Esempio n. 1
0
File: reg_user.go Progetto: jsli/cms
func (regUser *RegUser) Validate(v *revel.Validation, session *mgo.Session) {
	//Check workflow:
	//see @validation.go Check(obj interface{}, checks ...Validator)
	//Validator is an interface, v.Check invoke v.Apply for each validator.
	//Further, v.Apply invoke validator.IsSatisfied with passing obj.
	//Checking result is an object of ValidationResult. The field Ok of ValidationResult
	//would be true if checking success. Otherwise, Ok would be false, and another filed
	//Error of ValidationResult would be non-nil, an ValidationError filled with error message
	//should be assigned to Error.
	v.Check(regUser.UserName,
		revel.Required{},
		revel.Match{USERNAME_REX},
		DuplicatedUserValidator{session},
	)

	//validation provide an convenient method for checking Email.
	//revel has a const for email rexgep, Email will use the rex to check email string.
	v.Email(regUser.Email)
	v.Check(regUser.Email,
		DuplicatedEmailValidator{session},
	)

	v.Check(regUser.PasswordStr,
		revel.Required{},
		revel.Match{PWD_REX},
	)
	v.Check(regUser.ConfirmPwdStr,
		revel.Required{},
		revel.Match{PWD_REX},
	)
	//pwd and comfirm_pwd should be equal
	v.Required(regUser.PasswordStr == regUser.ConfirmPwdStr).Message("The passwords do not match.")
}
Esempio n. 2
0
func (this *Project) Validate(v *r.Validation) {
	v.Check(this.Name, r.Required{}, r.MinSize{2}, r.MaxSize{64}, r.Match{projRegex})
	if this.DisplayName == "" {
		this.DisplayName = this.Name
	}
	v.Required(this.OwnerId)
}
Esempio n. 3
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. 4
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. 5
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)

}
Esempio n. 6
0
File: user.go Progetto: puspesh/cdfs
func (user *User) Validate(v *revel.Validation) {
	v.Required(user.Password)
	//v.MinSize(user.Password, 6)
	v.Required(user.Email)
	v.Email(user.Email)

	if user.Email == "*****@*****.**" && user.Password == "test" {
		user.Id = "6964943e-535a-4736-85ad-4baaa9656709"
	} else {
		v.Error("Sorry! invalid account ...")
	}
}
Esempio n. 7
0
File: user.go Progetto: jsli/gorevel
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("密码不一致")
}
Esempio n. 8
0
func (category *Category) Validate(v *revel.Validation) {
	valid := v.Required(category.Name).Message("请输入名称")

	if valid.Ok {
		if category.HasName() {
			err := &revel.ValidationError{
				Message: "该名称已存在",
				Key:     "category.Name",
			}
			valid.Error = err
			valid.Ok = false

			v.Errors = append(v.Errors, err)
		}
	}
}
Esempio n. 9
0
func (loginUser *LoginUser) Validate(v *revel.Validation) {
	v.Check(loginUser.UserName,
		revel.Required{},
		revel.Match{USERNAME_REX},
	).Message("UserName or password is wrong")

	v.Check(loginUser.PasswordStr,
		revel.Required{},
		revel.Match{PWD_REX},
	).Message("UserName or password is wrong")

	//0: generate passing str
	//1: get pwd bytes from database
	//2: compare them
	//test here
	pwd := "testtest"
	//rPwd := "testtest"
	rPwd := "testtest"
	v.Required(pwd == rPwd).Message("user name or password is wrong!!!")
}
Esempio n. 10
0
File: menu.go Progetto: qmdx/GoCMS
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. 11
0
File: admin.go Progetto: qmdx/GoCMS
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. 12
0
File: admin.go Progetto: qmdx/GoCMS
//验证密码
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. 13
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. 14
0
func (user *User) ValidateCreate(v *revel.Validation) {
	validators.UniqueUsername(v, user.Username).Key("user.Username")
	validators.UniqueEmail(v, user.Email).Key("user.Email")

	v.Required(user.Password)
	v.Required(user.PasswordConfirm)

	v.Required(user.PasswordConfirm == user.Password).Message("Passwords must match")
}
Esempio n. 15
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. 16
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. 17
0
//校验
func (user *User) Validation(q *qbs.Qbs, v *revel.Validation) {

	v.Required(user.UserName).Message("请输入用户名")
	v.Required(user.Email).Message("请输入邮箱")
	v.Required(user.Password).Message("请输入密码")
	valid := v.Email(user.Email).Message("邮箱格式错误")

	if valid.Ok {
		if user.HasEmail(q) {
			err := &revel.ValidationError{
				Message: "该邮件已经注册过",
				Key:     "user.Email",
			}
			valid.Error = err
			valid.Ok = false

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

	v.Required(user.Password == user.AffirmPassword).Message("两次密码输入不一致")

}
Esempio n. 18
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")
	*/

}
Esempio n. 19
0
func (this *User) Validate(v *r.Validation, password string) {
	const (
		EMAIL         = "电子邮件地址"
		USERNAME      = "******"
		PASSWORD      = "******"
		INVALID       = "不符合要求"
		NOEMPTY       = "不能为空"
		ALREADYEXISTS = "已存在"
	)
	v.Required(this.Email).Message(EMAIL + NOEMPTY)
	v.Check(this.Email, r.MinSize{6}, r.MaxSize{100}, r.Match{emailRegex}).
		Message(EMAIL + INVALID)
	v.Required(this.Username).Message(USERNAME + NOEMPTY)
	v.Check(this.Username, r.MinSize{2}, r.MaxSize{32}, r.Match{userRegex}).
		Message(USERNAME + INVALID)
	v.Required(password).Message(PASSWORD + NOEMPTY)
	v.Check(password, r.MaxSize{32}, r.MinSize{6}).
		Message(PASSWORD + INVALID)

}
Esempio n. 20
0
func (upf *UpdateRoom) Validate(v *revel.Validation) {
	v.Required(upf.Title)
	v.Required(upf.Desc)
}
Esempio n. 21
0
func (rf *RoomForm) Validate(v *revel.Validation) {
	v.Required(rf.UserId)
	v.Required(rf.RoomKey)
	v.Required(rf.Title)
	v.Required(rf.Desc)
}
Esempio n. 22
0
func (user *User) ValidateLogin(v *revel.Validation) {
	v.Required(user.Email)
	v.Required(user.Password)
	v.Email(user.Email)
}
Esempio n. 23
0
File: post.go Progetto: robfig/acvte
func (p *Post) Validate(v *revel.Validation) {
	v.Required(p.Title)
}
Esempio n. 24
0
func (topic *Topic) Validate(v *revel.Validation) {
	v.Required(topic.Title).Message("请输入标题")
	v.MaxSize(topic.Title, 105).Message("最多35个字")
	v.Required(topic.Category).Message("请选择分类")
	v.Required(topic.Content).Message("帖子内容不能为空")
}
Esempio n. 25
0
func (sf *ServerSettings) Validate(v *revel.Validation) {
	v.Required(sf.Name)
}
Esempio n. 26
0
func (quote *QdbView) Validate(v *revel.Validation) {
	v.Required(quote.Author)
	v.Required(quote.Quote)
}
Esempio n. 27
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)
}
Esempio n. 28
0
File: menu.go Progetto: jsli/GoCMS
func (m *Menu) Validate(v *revel.Validation) {
	v.Required(m.Name).Message("请输入菜单名称")
	v.Required(m.Pid).Message("请选择父菜单")
	v.Required(m.Controller).Message("请输入菜单地址")

}