Esempio n. 1
0
File: user.go Progetto: jango2015/OJ
func (user *User) Validate(v *revel.Validation) {
	v.Required(user.Name)
	v.Required(user.Email)
	valid := v.Email(user.Email)
	if user.Password != user.ConfirmPassword {
		v.Errors = append(v.Errors, &revel.ValidationError{Message: "两次密码不一致", Key: "user.Password"})
	}

	if user.HasName() {
		fmt.Println("has name")
		err := &revel.ValidationError{
			Message: "该用户名已经被注册",
			Key:     "user.Name",
		}
		v.Errors = append(v.Errors, err)
	}

	if valid.Ok {
		if user.HasEmail() {
			fmt.Println("has email")
			err := &revel.ValidationError{
				Message: "该邮箱已经被用于注册",
				Key:     "user.Email",
			}
			v.Errors = append(v.Errors, err)
		}
	}
}
Esempio n. 2
0
func (requests Requests) Validate(v *revel.Validation) {
	v.Required(requests.User)
	v.Required(requests.RequestType)
	v.Required(requests.RequestCount)
	v.Required(requests.RequestTime)
	v.Required(requests.RequestPlace)
}
Esempio n. 3
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.")
}
Esempio n. 4
0
func (u *UserMaillist) Validate(v *revel.Validation) {
	v.Required(u.Email).
		Message("Email required").
		Key("usermaillist.Email")
	v.Email(u.Email).
		Message("Valid email required").
		Key("usermaillist.Email")
}
Esempio n. 5
0
func (user *User) ValidatePassword(v *revel.Validation, password Password) {
	v.Check(password.Pass,
		revel.MinSize{8},
	)
	v.Check(password.PassConfirm,
		revel.MinSize{8},
	)
	v.Required(password.Pass == password.PassConfirm).Message("The passwords do not match.")
}
Esempio n. 6
0
func (u *UserLogin) Validate(v *revel.Validation) {
	v.Required(u.Email).
		Message("Email required").
		Key("userlogin.Email")
	v.Email(u.Email).
		Message("Valid email address required").
		Key("userlogin.Email")
	v.Required(u.Password).
		Message("Password required").
		Key("userlogin.Password")
}
Esempio n. 7
0
func (category Category) Validate(v *revel.Validation) {
	v.Required(category.Name).Message("请输入名称")

	if category.HasName() {
		err := &revel.ValidationError{
			Message: "名称已存在",
			Key:     "category.Name",
		}
		v.Errors = append(v.Errors, err)
	}
}
Esempio n. 8
0
func (user User) Validate(v *revel.Validation) {
	v.Required(user.Name).Message("请输入用户名")
	v.Match(user.Name, nameRegex).Message("只能使用字母、数字和下划线")

	if user.HasName() {
		err := &revel.ValidationError{
			Message: "用户名已经注册过",
			Key:     "user.Name",
		}
		v.Errors = append(v.Errors, err)
	}

	v.Required(user.Email).Message("请输入Email")
	v.Email(user.Email).Message("无效的电子邮件")

	if user.HasEmail() {
		err := &revel.ValidationError{
			Message: "邮件已经注册过",
			Key:     "user.Email",
		}
		v.Errors = append(v.Errors, err)
	}

	v.Required(user.Password).Message("请输入密码")
	v.MinSize(user.Password, 3).Message("密码最少三位")
	v.Required(user.ConfirmPassword == user.Password).Message("密码不一致")
}
Esempio n. 9
0
func ValidatePostTitle(v *revel.Validation, title string) *revel.ValidationResult {
	result := v.Required(title).Message("A post must have a title")
	if !result.Ok {
		return result
	}

	result = v.MinSize(title, 3).Message("Post title must exceed 2 characters")
	if !result.Ok {
		return result
	}

	result = v.MaxSize(title, 200).Message("Post title cannot exceed 200 characters")

	return result
}
Esempio n. 10
0
func ValidateUserPassword(v *revel.Validation, password string) *revel.ValidationResult {
	result := v.Required(password).Message("Password required")
	if !result.Ok {
		return result
	}

	result = v.MinSize(password, 6).Message("Password must be at least 6 characters")
	if !result.Ok {
		return result
	}

	result = v.MaxSize(password, 200).Message("Password must be at most 200 characters")

	return result
}
Esempio n. 11
0
func (si SiteInfo) Validate(v *revel.Validation) {
	v.MaxSize(si.AboutUsTitle, 1024)

	v.Required(si.AboutUsTitle)
	v.Required(si.AboutUsContent)
	v.Required(si.TwitterURL)
	v.Required(si.FacebookURL)
}
Esempio n. 12
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"
}
Esempio n. 13
0
func ValidateUserEmail(v *revel.Validation, email string) *revel.ValidationResult {
	result := v.Required(email).Message("Email address required")
	if !result.Ok {
		return result
	}

	result = v.MinSize(email, 6).Message("Email address can not be less than 6 characters")
	if !result.Ok {
		return result
	}

	result = v.MaxSize(email, 200).Message("Email address can not exceed 200 characters")
	if !result.Ok {
		return result
	}

	result = v.Match(email, EmailRegex).Message("You must provide a valid email address")

	return result
}
Esempio n. 14
0
func (menu *Menu) Validate(v *revel.Validation) {
	v.Required(menu.Name).Message("请输入菜单名称!")
	v.MaxSize(menu.Name, 105).Message("最多35个字")
	v.Required(menu.Pid).Message("请选择父菜单!")
	v.Required(menu.Url).Message("请输入菜单地址!")
	v.Required(menu.Order).Message("请输入排序!")
}
Esempio n. 15
0
func (d *DataStream) Validate(v *revel.Validation) {
	v.Required(d.Name).Key("name").Message("Data stream name required")
	v.MinSize(d.Name, 3).Key("name").Message("Minimum length is 3 characters")
	v.Required(d.AccountId).Key("accountId").Message("Account ID required")
	v.Required(d.ProjectId).Key("projectId").Message("Project ID required")
	v.Required(d.DataStreamGroupId).Key("dataStreamGroupId").Message("Data Stream Group ID required")
}
Esempio n. 16
0
func (a *Admin) Validate(v *revel.Validation) {
	v.Required(a.Username).Message("请输入用户名!")
	valid := v.Match(a.Username, regexp.MustCompile("^\\w*$")).Message("只能使用字母、数字和下划线!")
	if valid.Ok {
		if a.HasName() {
			err := &revel.ValidationError{
				Message: "该用户名已经注册过!",
				Key:     "a.Username",
			}
			valid.Error = err
			valid.Ok = false

			v.Errors = append(v.Errors, err)
		}
	}

	v.Required(a.Email).Message("请输入Email")
	valid = v.Email(a.Email).Message("无效的电子邮件!")
	if valid.Ok {
		if a.HasEmail() {
			err := &revel.ValidationError{
				Message: "该邮件已经注册过!",
				Key:     "a.Email",
			}
			valid.Error = err
			valid.Ok = false

			v.Errors = append(v.Errors, err)
		}
	}

	v.Required(a.Password).Message("请输入密码!")
	v.MinSize(a.Password, 3).Message("密码最少三位!")
}
Esempio n. 17
0
//验证密码
func (P *Password) ValidatePassword(v *revel.Validation) {
	v.Required(P.Password).Message("请输入密码!")
	v.Required(P.PasswordConfirm).Message("请输入确认密码!")

	v.MinSize(P.Password, 6).Message("密码最少六位!")
	v.Required(P.Password == P.PasswordConfirm).Message("两次密码不相同!")
}
Esempio n. 18
0
// TODO: Make an interface for Validate() and then validation can pass in the
// key prefix ("booking.")
func (booking Booking) Validate(v *revel.Validation) {
	v.Required(booking.User)
	v.Required(booking.Hotel)
	v.Required(booking.CheckInDate)
	v.Required(booking.CheckOutDate)

	v.Match(booking.CardNumber, regexp.MustCompile(`\d{16}`)).
		Message("Credit card number must be numeric and 16 digits")

	v.Check(booking.NameOnCard,
		revel.Required{},
		revel.MinSize{3},
		revel.MaxSize{70},
	)
}
Esempio n. 19
0
func ValidateProfileName(v *revel.Validation, name string) *revel.ValidationResult {
	result := v.Required(name).Message("Name required")
	if !result.Ok {
		return result
	}

	result = v.MinSize(name, 2).Message("Name must be at least 2 characters")
	if !result.Ok {
		return result
	}

	result = v.MaxSize(name, 100).Message("Name must be at most 100 characters")
	if !result.Ok {
		return result
	}

	// Inverse regexp matcher (name cannot contain reserved # or @ symbols)
	if invalidNameMatcher := NameRegex.FindString(name); invalidNameMatcher == "" {
		result = v.Error("Invalid Name. Reserved characters ('#' and '@') are not allowed")
	}

	return result
}
Esempio n. 20
0
func ValidateProfileUserName(v *revel.Validation, username string) *revel.ValidationResult {
	result := v.Required(username).Message("User name required")
	if !result.Ok {
		return result
	}

	result = v.MaxSize(username, 64).Message("User name can not exceed 64 characters")
	if !result.Ok {
		return result
	}

	result = v.Match(username, UserNameRegex).Message("Invalid User name. Alphanumerics allowed only")
	if !result.Ok {
		return result
	}

	// Inverse regexp matcher (username cannot be the same as any blacklisted usernames)
	if blacklistMatcher := UserNameBlacklistRegex.FindString(username); blacklistMatcher != "" {
		result = v.Error("Invalid User name. Reserved keywords not allowed")
	}

	return result
}
Esempio n. 21
0
func (topic Topic) Validate(v *revel.Validation) {
	v.Required(topic.Title).Message("请输入标题")
	if utf8.RuneCountInString(topic.Title) > 35 {
		err := &revel.ValidationError{
			Message: "最多35个字",
			Key:     "topic.Title",
		}
		v.Errors = append(v.Errors, err)
	}
	v.Required(topic.Category).Message("请选择分类")
	v.Required(topic.Content).Message("帖子内容不能为空")
}
Esempio n. 22
0
// Interface for Validate() and
// validation can pass in the key prefix ("message.")
func (message Message) Validate(v *revel.Validation) {

	v.Check(message.Name,
		revel.Required{},
		revel.MinSize{3},
	).Message("Name is required and more than 3 characters!")

	v.Required(message.Email).Message("Email is required!")

	v.Required(message.Title).Message("Title is required!")

	v.Required(message.Message).Message("Message is required!")
}
Esempio n. 23
0
func (product Product) Validate(v *revel.Validation) {
	v.Required(product.Name).Message("不能为空")
	v.Required(product.Author).Message("不能为空")
	v.Required(product.Description).Message("不能为空")

	if utf8.RuneCountInString(product.Name) > 20 {
		err := &revel.ValidationError{
			Message: "最多20个字",
			Key:     "product.Name",
		}
		v.Errors = append(v.Errors, err)
	}
}
Esempio n. 24
0
func (u *UserSignup) Validate(v *revel.Validation) {
	v.Required(u.Email).
		Message("Email required").
		Key("usersignup.Email")
	v.Email(u.Email).
		Message("Valid email required").
		Key("usersignup.Email")
	v.Required(u.Password).
		Message("Password required").
		Key("usersignup.Password")
	v.MinSize(u.Password, 8).
		Message("Password length must be at least 8").
		Key("usersignup.Password")
	v.Required(u.PasswordConfirm == u.Password).
		Message("The passwords do not match.").
		Key("usersignup.PasswordConfirm")
}
Esempio n. 25
0
func (post *Post) Validate(v *revel.Validation) {
	v.Required(post.Slug).Message("请填写访问Slug")
	v.Required(post.Title).Message("标题不能为空")
	v.Required(post.Content).Message("文章内容不能为空")
}
Esempio n. 26
0
func (c Category) Validate(v *revel.Validation) {
	v.Required(c.Heading)
}
Esempio n. 27
0
func (user *User) Validate(v *revel.Validation) {
	v.Check(user.UserName,
		revel.Required{},
		revel.MaxSize{36},
		revel.MinSize{4},
		revel.Match{userRegex},
	).Message("User name must be between 4 and 36 alphanumeric characters")
	v.Required(user.FirstName).
		Message("First name is required")
	v.Required(user.LastName).
		Message("Last name is required")
	v.Required(user.Password).
		Message("Password is required")
	v.Required(user.PasswordConfirm == user.Password).
		Message("The passwords do not match.")
	validatePassword(v, user.Password).Key("user.Password").
		Message("Password must be between 5 and 65 characters long")

	v.Required(user.Email).
		Message("Email is required")
	v.Email(user.Email).
		Message("Email must be valid")
	v.Required(user.TermsOfUse).
		Message("Must agree to honor code.")
}
func (ct ContributorType) Validate(v *revel.Validation) {
	v.Required(ct.Type)
}
Esempio n. 29
0
func (c Contributor) Validate(v *revel.Validation) {
	v.Required(c.Name)
	v.Required(c.Handle)
	v.Required(c.Email)
	v.Required(c.Password)
}
Esempio n. 30
0
func (post Post) Validate(v *revel.Validation) {
	v.Required(post.User)
}