Ejemplo n.º 1
0
// ValidateCard validates whether the card's values are appropriate
// when creating a new card.
func ValidateCard(validator *revel.Validation, params url.Values) {
	validator.Clear()

	id, err := strconv.ParseInt(params.Get("CreatorID"), 0, 0)
	if err != nil {
		validator.Error("The ID of the creator should be a number").Key("creatorID")
	}
	creatorID := int(id)

	cardBody := params.Get("CardBody")
	t, err := strconv.ParseInt(params.Get("CardType"), 0, 0)
	if err != nil {
		validator.Error("Card Type should be a number").Key("cardType")
	}
	cardType := int(t)

	b, err := strconv.ParseInt(params.Get("CardBlanks"), 0, 0)
	if err != nil {
		validator.Error("Card Blanks should be a number").Key("cardBlanks")
	}
	cardBlanks := int(b)

	validator.Required(cardBody)
	validator.Range(int(cardType), 0, 1).Message("The card type can only be 0 for a white card, or 1 for a black card.")
	validator.Range(int(cardBlanks), 0, 3).Message("Card blanks must be in the range of 0 - 3.")
	if cardType == 0 {
		validator.Max(int(cardBlanks), 0).Message("You cannot have blank spaces in a card unless it is a black card.)")
	}
	validator.Min(creatorID, 0).Message("The creator ID must be greater than 0.")
}
Ejemplo n.º 2
0
func (p *Problem) Validate(v *revel.Validation, in, out []byte) {
	v.Required(p.Title).Message("Title Required")
	v.Min(int(p.MemoryLimit), 1).Message("TimeLimit Required")
	v.Min(int(p.TimeLimit), 1).Message("MemoryLimit Required")
	v.Required(p.Description).Message("Description Required")
	v.Required(in).Message("input file needed")
	v.Required(out).Message("output file needed")
	v.MaxSize(p.InputSample, 512).Message("input sample too long")
	v.MaxSize(p.OutputSample, 512).Message("output sample too long")
	path := p.TestPath()
	p.InputTestPath = path + "/inputTest"
	p.OutputTestPath = path + "/outputTest"
}