예제 #1
0
파일: Project.go 프로젝트: pa001024/MoeFeed
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)
}
예제 #2
0
파일: user.go 프로젝트: huaguzi/revel
func ValidatePassword(v *revel.Validation, password string) *revel.ValidationResult {
	return v.Check(password,
		revel.Required{},
		revel.MaxSize{15},
		revel.MinSize{5},
	)
}
예제 #3
0
파일: hotel.go 프로젝트: huaguzi/revel
func (hotel *Hotel) Validate(v *revel.Validation) {
	v.Check(hotel.Name,
		revel.Required{},
		revel.MaxSize{50},
	)

	v.MaxSize(hotel.Address, 100)

	v.Check(hotel.City,
		revel.Required{},
		revel.MaxSize{40},
	)

	v.Check(hotel.State,
		revel.Required{},
		revel.MaxSize{6},
		revel.MinSize{2},
	)

	v.Check(hotel.Zip,
		revel.Required{},
		revel.MaxSize{6},
		revel.MinSize{5},
	)

	v.Check(hotel.Country,
		revel.Required{},
		revel.MaxSize{40},
		revel.MinSize{2},
	)
}
예제 #4
0
func Validate(validation *revel.Validation, obj interface{}) {
	// Get reflection data to parse validation tag data
	var v reflect.Value = reflect.Indirect(reflect.ValueOf(obj))

	// We only want to validate structs and their tagged fields
	if v.Kind() != reflect.Struct {
		panic(fmt.Sprintf("Object is not a struct. Actual kind is: %s", v.Kind()))
	}

	// Go through each field in the struct and check for the
	// validation tag.  Apply appropriate revel check as needed.
	t := v.Type()
	for i := 0; i < t.NumField(); i++ {
		field := t.Field(i)
		fieldId := fmt.Sprintf("%s.%s", t.Name(), field.Name)
		var fieldValidators []revel.Validator
		fieldValidators, ok := validationCache[fieldId]
		if tag := field.Tag.Get(TagName); !ok && len(tag) > 0 {
			fieldValidators = parseTag(tag)
			validationCache[fieldId] = fieldValidators
		} else if !ok {
			fieldValidators = nil
			validationCache[fieldId] = nil
		}
		if len(fieldValidators) > 0 {
			validation.Check(v.FieldByName(field.Name).Interface(), fieldValidators...).Key(fieldId)
		}
	}
}
예제 #5
0
파일: article.go 프로젝트: stunti/bloggo
func (article *Article) Validate(v *revel.Validation) {
	v.Check(article.Title,
		revel.Required{},
		revel.MinSize{1},
		revel.MaxSize{256},
	)
}
예제 #6
0
func (r *Restaurant) Validate(v *revel.Validation) {
	v.Check(r.Name,
		revel.Required{},
		revel.MaxSize{150},
		revel.MinSize{1},
	)
}
예제 #7
0
파일: user.go 프로젝트: stunti/bloggo
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.")
}
예제 #8
0
파일: login_user.go 프로젝트: jsli/cms
func (loginUser *LoginUser) Validate(v *revel.Validation, session *mgo.Session) {
	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},
		LegalUserValidator{session, loginUser.UserName},
	).Message("UserName or password is wrong")
}
예제 #9
0
파일: user.go 프로젝트: BYVoid/byvnotes
func (user *User) Validate(v *revel.Validation) {
	v.Check(user.Username,
		revel.Required{},
		revel.MaxSize{15},
		revel.MinSize{3},
		revel.Match{userRegex},
	).Key("username")
	v.Check(user.Password,
		revel.Required{},
		revel.MaxSize{15},
		revel.MinSize{3},
	).Key("password")
}
예제 #10
0
파일: user.go 프로젝트: netsharec/ironzebra
func (user *User) Validate(v *revel.Validation) {
	v.Check(user.Username,
		revel.Required{},
		revel.MaxSize{15},
		revel.MinSize{4},
		revel.Match{userRegex},
	)

	v.Check(user.Name,
		revel.Required{},
		revel.MaxSize{100},
	)
}
예제 #11
0
파일: reg_user.go 프로젝트: 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.")
}
예제 #12
0
파일: post.go 프로젝트: puredevotion/jobs
func (post *Post) Validate(v *revel.Validation) {
	v.Check(
		post.Title,
		revel.Required{},
		revel.MinSize{3},
		revel.MaxSize{256},
	)

	v.Check(
		post.Body,
		revel.Required{},
		revel.MinSize{10},
		revel.MaxSize{2048},
	)
}
예제 #13
0
파일: booking.go 프로젝트: huaguzi/revel
// 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},
	)
}
예제 #14
0
파일: user.go 프로젝트: huaguzi/revel
func (user *User) Validate(v *revel.Validation) {
	v.Check(user.Username,
		revel.Required{},
		revel.MaxSize{15},
		revel.MinSize{4},
		revel.Match{userRegex},
	)

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

	v.Check(user.Name,
		revel.Required{},
		revel.MaxSize{100},
	)
}
예제 #15
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!!!")
}
예제 #16
0
파일: user.go 프로젝트: stunti/bloggo
func (user *User) Validate(v *revel.Validation) {
	v.Check(user.Firstname,
		revel.Required{},
		revel.MinSize{1},
		revel.MaxSize{64},
	)

	v.Check(user.Lastname,
		revel.Required{},
		revel.MinSize{1},
		revel.MaxSize{64},
	)

	v.Check(user.Email,
		revel.Required{},
	)

	v.Email(user.Email)
}
예제 #17
0
파일: User.go 프로젝트: pa001024/MoeFeed
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)

}
예제 #18
0
파일: default.go 프로젝트: Qwait/revauth
func UniqueEmail(v *revel.Validation, email string) *revel.ValidationResult {
	return v.Check(email, revel.Required{}, revel.Email{})
}
예제 #19
0
파일: default.go 프로젝트: Qwait/revauth
func UniqueUsername(v *revel.Validation, username string) *revel.ValidationResult {
	return v.Check(username, revel.Required{})
}