func (doc *Document) saveChain(v *revel.Validation) bool { if v != nil { doc.callCB("BeforeValidation") doc.Validate(v) if v.HasErrors() { return false } doc.callCB("AfterValidation") } doc.callCB("BeforeSave") if doc.IsNew() { doc.callCB("BeforeCreate") } else { doc.callCB("BeforeUpdate") } saved := doc.save() if doc.IsNew() { doc.callCB("AfterCreate") } else { doc.callCB("AfterUpdate") } doc.callCB("AfterSave") return saved }
func (serviceissuedata *ServiceIssueData) Validate() error { var v revel.Validation if serviceissuedata.ServiceID < 1 { return errors.New("required service id") } if serviceissuedata.IssueID < 1 { return errors.New("required issue id") } if serviceissuedata.ReflectdateStr != "" { v.Match(serviceissuedata.ReflectdateStr, regexp.MustCompile(`\d{8}`)) if v.HasErrors() { return errors.New("Reflectdate is validate error") } } return nil }
// Validate for userData of struct func (userdata *UserData) Validate() error { var v revel.Validation v.Match(userdata.MailAddr, regexp.MustCompile(`([a-zA-Z0-9])[email protected]`)) if v.HasErrors() { return errors.New("mail address is validate error") } v.Check( userdata.Password, revel.Required{}, revel.MinSize{4}, ) if v.HasErrors() { return errors.New("password is validate error") } return nil }
func (c Accounts) LoginCreate() revel.Result { u := User{} newUser := User{} v := revel.Validation{} if !c.validateCaptcha(c.Params.Get("captcha")) { v.Error("验证码不正确") return c.renderValidation("accounts/login.html", v) } newUser, v = u.Signin(c.Params.Get("login"), c.Params.Get("password")) if v.HasErrors() { return c.renderValidation("accounts/login.html", v) } c.storeUser(&newUser) c.Flash.Success("登录成功,欢迎再次回来。") return c.Redirect(Home.Index) }
func (servicedata *ServiceData) Validate() error { var v revel.Validation v.Check( servicedata.Name, revel.Required{}, revel.MaxSize{1024}, revel.MinSize{1}, ) if v.HasErrors() { return errors.New("name is validate error") } if servicedata.StartStr != "" { v.Match(servicedata.StartStr, regexp.MustCompile(`\d{8}`)) if v.HasErrors() { return errors.New("start is validate error") } } if servicedata.EndStr != "" { v.Match(servicedata.EndStr, regexp.MustCompile(`\d{8}`)) if v.HasErrors() { return errors.New("end is validate error") } } return nil }
func (issuedata *IssueData) Validate() error { var v revel.Validation v.Check( issuedata.Title, revel.Required{}, revel.MaxSize{1024}, revel.MinSize{1}, ) if v.HasErrors() { return errors.New("titel is validate error") } v.Check( issuedata.Source, revel.Required{}, revel.MaxSize{1024}, revel.MinSize{1}, ) if v.HasErrors() { return errors.New("source is validate error") } v.Check( issuedata.Detail, revel.Required{}, revel.MaxSize{5120}, revel.MinSize{1}, ) if v.HasErrors() { return errors.New("detail is validate error") } v.Match(strconv.Itoa(issuedata.Priority), regexp.MustCompile(`\d{1}`)) if v.HasErrors() { return errors.New("priority is validate error") } v.Match(strconv.Itoa(issuedata.Status), regexp.MustCompile(`\d{1}`)) if v.HasErrors() { return errors.New("status is validate error") } v.Match(issuedata.LimitStr, regexp.MustCompile(`\d{8}`)) if v.HasErrors() { return errors.New("limit is validate error") } return nil }