Beispiel #1
0
func (user *User) Validate(v *revel.Validation) {
	v.Required(user.Name).Message("请输入用户名")
	valid := v.Match(user.Name, nameRegex).Message("只能使用字母、数字和下划线")
	if valid.Ok {
		if user.HasName() {
			err := &revel.ValidationError{
				Message: "该用户名已经注册过",
				Key:     "user.Name",
			}
			valid.Error = err
			valid.Ok = false

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

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

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

	v.Required(user.Password).Message("请输入密码")
	v.MinSize(user.Password, 3).Message("密码最少三位")
	v.Required(user.ConfirmPassword == user.Password).Message("密码不一致")
}
Beispiel #2
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("两次密码不相同!")
}
Beispiel #3
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("密码最少三位!")
}
Beispiel #4
0
func (c *Credentials) Validate(v *revel.Validation) {

	v.Required(c.Email)
	v.Email(c.Email)
	v.MaxSize(c.Email, 32)
	v.MinSize(c.Email, 5)

	v.Required(c.Password)
	v.MaxSize(c.Password, 128)
	v.MinSize(c.Password, 6)

}
Beispiel #5
0
func (user *User) Validate(v *revel.Validation) {
	v.Required(user.Username)
	v.MinSize(user.Username, 6)
	v.Required(user.FirstName)
	v.Required(user.LastName)
	v.Required(user.Age)
	v.Range(user.Age, 16, 120)
	v.Required(user.Password)
	v.MinSize(user.Password, 6)
	v.Required(user.PasswordConfirm)
	v.Required(user.PasswordConfirm == user.Password).
		Message("The passwords do not match.")
	v.Required(user.Email)
	v.Email(user.Email)
	v.Required(user.EmailConfirm)
	v.Required(user.EmailConfirm == user.Email).
		Message("The email addresses do not match")
	v.Required(user.TermsOfUse)
}
Beispiel #6
0
func (user *User) Validate(v *revel.Validation) {

	/*
		v.Check(user.Username,
			revel.Required{},
			revel.Range{revel.Min{4},revel.Max{15}},
			revel.Match{userRegex},
		)

		v.Check(user.Email,
			revel.Required{},
			revel.MaxSize{50},
			revel.MinSize{4},

			//revel.Match{revel.emailPattern},
		).Message("Email")

		ValidatePassword(v, user.Password).
			Key("user.Password")

		v.Check(user.Name,
			revel.Required{},
			revel.MaxSize{100},
		)
	*/

	v.Required(user.Username)
	v.MinSize(user.Username, 6).Message("Username must be at least 6 characters")

	v.Required(user.Name)
	v.MinSize(user.Name, 2).Message("Name must be at least 2 characters")

	v.Required(user.Email)
	v.Email(user.Email)
	v.MinSize(user.Email, 5)

	/*
		v.Required(user.Password)
		v.MinSize(user.Password, 8).Message("Password must be at least 8 characters")
	*/

}