本文整理匯總了Golang中gorevel/app/models.User.ValidateCode方法的典型用法代碼示例。如果您正苦於以下問題:Golang User.ValidateCode方法的具體用法?Golang User.ValidateCode怎麽用?Golang User.ValidateCode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類gorevel/app/models.User
的用法示例。
在下文中一共展示了User.ValidateCode方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: SignupPost
func (c User) SignupPost(user models.User) revel.Result {
user.Validate(c.Validation)
if c.Validation.HasErrors() {
c.Validation.Keep()
c.FlashParams()
return c.Redirect(routes.User.Signup())
}
salt := uuidName()
user.Type = MEMBER_GROUP
user.Avatar = models.DefaultAvatar
user.ValidateCode = uuidName()
user.Salt = salt
user.HashedPassword = models.EncryptPassword(user.Password, salt)
aff, _ := engine.Insert(&user)
if aff == 0 {
c.Flash.Error("注冊用戶失敗")
return c.Redirect(routes.User.Signup())
}
subject := "激活賬號 —— Revel中文社區"
content := `<h2><a href="http://gorevel.cn/user/validate/` + user.ValidateCode + `">激活賬號</a></h2>`
go sendMail(subject, content, []string{user.Email})
c.Flash.Success(fmt.Sprintf("%s 注冊成功,請到您的郵箱 %s 激活賬號!", user.Name, user.Email))
engine.Insert(&models.Permissions{
UserId: user.Id,
Perm: MEMBER_GROUP,
})
return c.Redirect(routes.User.Signin())
}
示例2: ForgotPasswordPost
func (c User) ForgotPasswordPost(email string) revel.Result {
c.Validation.Required(email).Message("請填寫Email")
c.Validation.Email(email).Message("Email格式不正確")
if c.Validation.HasErrors() {
c.Validation.Keep()
c.FlashParams()
return c.Redirect(routes.User.ForgotPassword())
}
var user models.User
has, _ := engine.Where("email = ?", email).Get(&user)
if !has {
return c.NotFound("用戶不存在")
}
user.ValidateCode = uuidName()
engine.Where("email = ?", email).Cols("validate_code").Update(&user)
subject := "重設密碼 —— Revel社區"
content := `<h2><a href="http://gorevel.cn/reset_password/` + user.ValidateCode + `">重設密碼</a></h2>`
go sendMail(subject, content, []string{user.Email})
c.Flash.Success(fmt.Sprintf("你好,重設密碼的鏈接已經發送到您的郵箱,請到您的郵箱 %s 重設密碼!", user.Email))
return c.Redirect(routes.User.Signin())
}
示例3: Validate
func (c User) Validate(code string) revel.Result {
var user models.User
has, _ := engine.Where("validate_code = ?", code).Get(&user)
if !has {
return c.NotFound("用戶不存在或校驗碼錯誤")
}
user.Status = models.USER_STATUS_ACTIVATED
user.ValidateCode = ""
aff, _ := engine.Cols("status", "validate_code").Update(&user)
if aff > 0 {
c.Flash.Success("您的賬號成功激活,請登錄!")
} else {
c.Flash.Error("抱歉,您的賬號未能激活,請與管理員聯係!")
}
return c.Redirect(routes.User.Signin())
}