本文整理汇总了Golang中github.com/astaxie/beego/validation.Validation.Email方法的典型用法代码示例。如果您正苦于以下问题:Golang Validation.Email方法的具体用法?Golang Validation.Email怎么用?Golang Validation.Email使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/astaxie/beego/validation.Validation
的用法示例。
在下文中一共展示了Validation.Email方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Login
func (this *UserController) Login() {
if this.Ctx.Input.Method() == "GET" {
if this.GetSession("user") != nil {
this.Redirect("/", 302)
}
this.TplNames = "console/login.html"
return
}
json := this.ReqJson()
email := json.Get("email").MustString()
password := json.Get("password").MustString()
valid := validation.Validation{}
valid.Email(email, "email")
valid.MinSize(password, 6, "passwordMin")
valid.MaxSize(password, 12, "passwordMax")
if valid.HasErrors() {
this.CustomAbort(enum.RespCode.BadRequest.Code(), enum.RespCode.BadRequest.Str())
}
user := user.GetUserByEmail(email)
if user == nil {
//用户不存在
this.RespJson(enum.RespCode.UserNotExist, nil)
} else if util.Md5(user.Salt+password) != user.Password {
//密码错误
this.RespJson(enum.RespCode.PasswordIncorrect, nil)
} else {
this.SetSession("user", user)
this.RespJson(enum.RespCode.OK, map[string]interface{}{"url": "/"})
}
}
示例2: Login
//用户登录
func (this *User) Login() {
json := this.ReqJson()
if json != nil {
email := json.Get("email").MustString()
password := json.Get("password").MustString()
valid := validation.Validation{}
valid.Email(email, "email")
valid.MinSize(password, 6, "passwordMin")
valid.MaxSize(password, 12, "passwordMax")
if valid.HasErrors() {
this.CustomAbort(enum.BadRequest.Code(), enum.BadRequest.Str())
}
u := user.GetUserByEmail(email)
if u == nil {
//用户不存在
this.RespJson(enum.UserNotExist, nil)
} else if util.Md5(u.Salt+password) != u.Password {
//密码错误
this.RespJson(enum.PasswordIncorrect, nil)
} else {
this.SetSession("uId", u.Id.Hex())
user.SetToken(u.Id, this.StartSession().SessionID()) //using cookie as token
this.RespJson(enum.OK, map[string]interface{}{"url": "/"})
}
}
}
示例3: Register
//注册 todo 错误处理的优雅封装
func (this *User) Register() {
reqBody := this.Ctx.Input.RequestBody
reqJson, err := simplejson.NewJson(reqBody)
//非法请求
if err != nil {
this.Abort("400")
}
email := reqJson.Get("email").MustString()
nickname := reqJson.Get("nickname").MustString()
password := reqJson.Get("password").MustString()
valid := validation.Validation{}
valid.Email(email, "email") //邮箱
valid.MinSize(nickname, 5, "nickname") //昵称至少5位
valid.MinSize(password, 6, "password") //密码至少6位
//非法请求
if valid.HasErrors() {
this.Abort("400")
}
enumResult := user.AddUser(email, nickname, password)
fmt.Println(enumResult)
this.Data["json"] = map[string]interface{}{"code": enumResult, "msg": enumResult.String()}
this.ServeJson()
}
示例4: Recovery
func (l *LoginController) Recovery() {
email := l.GetString("email")
valid := validation.Validation{}
valid.Email(email, "email")
if valid.HasErrors() {
var msg string
for _, err := range valid.Errors {
msg += fmt.Sprintf("%s: %s\r", err.Key, err.Message)
}
l.Ctx.ResponseWriter.WriteHeader(400)
l.Data["json"] = &map[string]interface{}{"status": "error", "message": msg}
l.ServeJson()
return
}
user, _ := rbacModels.UserGetByEmail(email)
if user.Id == 0 {
l.Data["json"] = &map[string]interface{}{"status": "error", "message": "Пользователь не найден"}
} else {
site_url := beego.AppConfig.String("site_url")
reset_token, _ := user.GenResetPassToken()
params := map[string]interface{}{}
params["user:one-time-login-url"] = fmt.Sprintf("%s/admin/reset?token=%s", site_url, reset_token)
msg := emailSystem.New()
msg.Template = "email_password_reset"
msg.Params = ¶ms
msg.User = user
if err := msg.SendMail(); err == nil {
l.Data["json"] = &map[string]interface{}{"status": "info", "message": "Дальнейшие инструкции высланы на указанный почтовый ящик"}
}
}
l.ServeJson()
}
示例5: Register
//用户注册
func (this *User) Register() {
req := this.ReqJson()
if req != nil {
email := req.Get("email").MustString()
nickName := req.Get("nickName").MustString()
password := req.Get("password").MustString()
valid := validation.Validation{}
valid.Email(email, "email")
valid.MinSize(nickName, 6, "nickNameMin")
valid.MaxSize(nickName, 12, "nickNameMax")
valid.MinSize(password, 6, "passwordMin")
valid.MaxSize(password, 12, "passwordMax")
if valid.HasErrors() {
this.CustomAbort(enum.BadRequest.Code(), enum.BadRequest.Str())
}
err := user.AddUser(email, nickName, password)
if err == nil {
this.RespJson(enum.OK, nil)
} else {
if strings.Contains(err.Error(), "email") {
this.RespJson(enum.EmailAlreadyExist, nil)
} else if strings.Contains(err.Error(), "nickname") {
this.RespJson(enum.NickNameAlreadyExist, nil)
} else {
beego.Error(err)
}
}
}
}
示例6: Valid
func (form *LoginForm) Valid(v *validation.Validation) {
valid := validation.Validation{}
valid.Email(form.Email, "email")
if valid.HasErrors() {
v.SetError("Email", form.Locale.Tr("valid.invalid_email"))
}
}
示例7: TestEmailValidate
func TestEmailValidate(t *testing.T) {
mail := "406504302qq.com"
valid := validation.Validation{}
if !valid.Email(mail, "email").Ok {
fmt.Println("mail 格式错误")
}
}
示例8: ValidUser
//表单验证
func ValidUser(m *BUser) string {
v := validation.Validation{}
v.Required(m.Username, "username").Message("邮箱不能为空")
v.Required(m.Password, "password").Message("密码不能为空")
v.Email(m.Username, "username").Message("邮箱格式不正确")
if v.HasErrors() {
// 如果有错误信息,证明验证没通过
return utils.WrapErrors(v.Errors)
}
return ""
}
示例9: Edit
//编辑用户
func (this *UserController) Edit() {
id, _ := this.GetInt("id")
user := models.User{Id: id}
if err := user.Read(); err != nil {
this.showmsg("用户不存在")
}
errmsg := make(map[string]string)
if this.Ctx.Request.Method == "POST" {
password := strings.TrimSpace(this.GetString("password"))
password2 := strings.TrimSpace(this.GetString("password2"))
email := strings.TrimSpace(this.GetString("email"))
active, _ := this.GetInt("active")
valid := validation.Validation{}
if password != "" {
if v := valid.Required(password2, "password2"); !v.Ok {
errmsg["password2"] = "请再次输入密码"
} else if password != password2 {
errmsg["password2"] = "两次输入的密码不一致"
} else {
user.Password = models.Md5([]byte(password))
}
}
if v := valid.Required(email, "email"); !v.Ok {
errmsg["email"] = "请输入email地址"
} else if v := valid.Email(email, "email"); !v.Ok {
errmsg["email"] = "Email无效"
} else {
user.Email = email
}
if active > 0 {
user.Active = 1
} else {
user.Active = 0
}
if len(errmsg) == 0 {
user.Update()
this.Redirect("/admin/user/list", 302)
}
}
this.Data["errmsg"] = errmsg
this.Data["user"] = user
this.display()
}
示例10: Valid
// We will check if the user data are valid
func (u User) Valid() bool {
v := validation.Validation{}
v.Required(u.Name, "name")
v.MaxSize(u.Name, 20, "nameMax")
v.Required(u.Pass, "pass")
v.MaxSize(u.Pass, 30, "passMax")
v.Email(u.Email, "email")
if v.HasErrors() {
for _, e := range v.Errors {
log.Println("Check valid user data:", e)
}
return false
}
return true
}
示例11: ValidEmail
func (c *TUserController) ValidEmail() {
email := c.GetString("email")
valid := validation.Validation{}
valid.Email(email, "Email")
valid.MaxSize(email, 50, "Email")
if valid.HasErrors() {
c.Data["json"] = map[string]string{"error": "邮箱不正确"}
} else {
err := models.ValidEmail(email)
if err == nil {
c.Data["json"] = map[string]string{"error": "邮箱已经存在"}
} else {
c.Data["json"] = map[string]string{"message": "这个邮箱未被注册"}
}
}
c.ServeJson()
}
示例12: CheckUserMail
func CheckUserMail(mail string) error {
valid := validation.Validation{}
if !valid.Email(mail, "email").Ok {
return errors.New("邮箱格式错误")
}
orm := orm.NewOrm()
count, err := orm.QueryTable("user").Filter("mail", mail).Count()
if nil != err || count > 0 {
return exception.USER_MAIL_EXISTENT
}
return nil
}
示例13: Forgot
func (this *MainController) Forgot() {
this.activeContent("user/forgot")
if this.Ctx.Input.Method() == "POST" {
email := this.GetString("email")
valid := validation.Validation{}
valid.Email(email, "email")
if valid.HasErrors() {
errormap := make(map[string]string)
for _, err := range valid.Errors {
errormap[err.Key] = err.Message
}
this.Data["Errors"] = errormap
return
}
flash := beego.NewFlash()
o := orm.NewOrm()
o.Using("default")
user := models.AuthUser{Email: email}
err := o.Read(&user, "Email")
if err != nil {
flash.Error("No such user/email in our records")
flash.Store(&this.Controller)
return
}
u := uuid.NewV4()
user.Reset_key = u.String()
_, err = o.Update(&user)
if err != nil {
flash.Error("Internal error")
flash.Store(&this.Controller)
return
}
domainname := this.Data["domainname"]
this.sendRequestReset(email, u.String(), domainname.(string))
flash.Notice("You've been sent a reset password link. You must check your email.")
flash.Store(&this.Controller)
this.Redirect("/notice", 302)
}
}
示例14: FundUser
func FundUser(name string, password string) (entities.User, error) {
var err error
var user entities.User
orm := orm.NewOrm()
querySetter := orm.QueryTable("user").Filter("password", password)
valid := validation.Validation{}
if valid.Email(name, "email").Ok {
querySetter = querySetter.Filter("mail", name)
} else {
querySetter = querySetter.Filter("name", name)
}
err = querySetter.One(&user, "id", "name", "nick", "password", "age", "cell", "mail", "sex", "CreatedAt", "UpdatedAt")
return user, err
}
示例15: Login
//登录
func (this *User) Login() {
fmt.Println(this)
reqBody := this.Ctx.Input.RequestBody
fmt.Println(string(reqBody))
reqJson, err := simplejson.NewJson(reqBody)
//非法请求
if err != nil {
this.Abort("400")
}
fmt.Println(reqJson)
email := reqJson.Get("email").MustString()
password := reqJson.Get("password").MustString()
valid := validation.Validation{}
valid.Email(email, "email")
valid.MinSize(password, 6, "password") //密码至少6位
//非法请求
if valid.HasErrors() {
this.Abort("400")
}
fmt.Println(reqJson)
if currentUser := user.FindUser(email); currentUser == nil {
this.Data["json"] = map[string]interface{}{"code": enum.UserNotExist, "msg": enum.UserNotExist.String()}
} else {
if currentUser.Password != common.Md5(password+currentUser.Salt) {
this.Data["json"] = map[string]interface{}{"code": enum.PasswordError, "msg": enum.PasswordError.String()}
} else {
this.Data["json"] = map[string]interface{}{"code": enum.OK, "msg": enum.OK.String()}
//讲token写入cookie
token := user.UpdateCookieToken(*currentUser)
this.SetSession(this.Ctx.GetCookie("token"), token)
}
}
this.ServeJson()
}