本文整理汇总了Golang中github.com/silvasur/mailremind/model.User.SetActivationCode方法的典型用法代码示例。如果您正苦于以下问题:Golang User.SetActivationCode方法的具体用法?Golang User.SetActivationCode怎么用?Golang User.SetActivationCode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/silvasur/mailremind/model.User
的用法示例。
在下文中一共展示了User.SetActivationCode方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: forgotpw
func forgotpw(user model.User, sess *sessions.Session, req *http.Request) (interface{}, model.User) {
if req.Method != "POST" {
return &forgotpwTpldata{}, user
}
if err := req.ParseForm(); err != nil {
return &forgotpwTpldata{Error: "Form data corrupted."}, user
}
email := req.FormValue("Mail")
if email == "" {
return &forgotpwTpldata{Error: "E-Mail must not be empty."}, user
}
user, err := dbcon.UserByMail(email)
if err != nil {
return &forgotpwTpldata{Error: "E-Mail not found."}, user
}
key := genAcCode()
if err := user.SetActivationCode(key); err != nil {
log.Printf("Could not store pwreset key: %s", err)
return &forgotpwTpldata{Error: "Could not generate a keyword reset code."}, user
}
if !SendPwresetLink(user.Email(), key, user.ID()) {
return &forgotpwTpldata{Error: "Could not send reset E-Mail."}, user
}
return &forgotpwTpldata{Success: "We sent you an E-Mail with further instructions."}, user
}
示例2: activate
func activate(user model.User, sess *sessions.Session, req *http.Request) (interface{}, model.User) {
outdata := &msgTpldata{Title: "Activate Account", Class: "error"}
req.ParseForm()
_userid := req.FormValue("U")
code := req.FormValue("Code")
if (_userid == "") || (code == "") {
outdata.Msg = "User or code invalid. Check, if the activation link was correctly copied from the mail."
return outdata, nil
}
userid, err := db.ParseDBID(_userid)
if err != nil {
outdata.Msg = "User or code invalid. Check, if the activation link was correctly copied from the mail."
return outdata, nil
}
switch user, err = dbcon.UserByID(userid); err {
case nil:
case model.NotFound:
outdata.Msg = "User not found."
return outdata, nil
default:
log.Printf("Error while getting user by ID <%s>: %s", userid, err)
outdata.Msg = "An unknown error occurred while loading user data."
return outdata, nil
}
if user.ActivationCode() != code {
outdata.Msg = "Wrong activation code."
return outdata, nil
}
if err := user.SetActivationCode(""); err != nil {
log.Printf("Error while resetting activation code: %s", err)
outdata.Msg = "An unknown error occurred while activating the user."
return outdata, nil
}
if err := user.SetActive(true); err != nil {
log.Printf("Error while resetting activation code: %s", err)
outdata.Msg = "An unknown error occurred while activating the user."
return outdata, nil
}
outdata.Class = "success"
outdata.Msg = "Account activated!"
return outdata, nil
}
示例3: pwreset
func pwreset(user model.User, sess *sessions.Session, req *http.Request) (interface{}, model.User) {
if err := req.ParseForm(); err != nil {
return &pwresetTpldata{Error: "Form data corrupted."}, user
}
code := req.FormValue("Code")
_uid := req.FormValue("U")
pw1 := req.FormValue("Password")
pw2 := req.FormValue("PasswordAgain")
if code == "" {
return &pwresetTpldata{Error: "Wrong password reset code"}, user
}
uid, err := db.ParseDBID(_uid)
if err != nil {
return &pwresetTpldata{Error: "Invalid user ID"}, user
}
if user, err = dbcon.UserByID(uid); err != nil {
return &pwresetTpldata{Error: "User not found"}, user
}
if user.ActivationCode() != code {
return &pwresetTpldata{Error: "Wrong activation code"}, user
}
outdata := &pwresetTpldata{UID: _uid, Code: code}
if req.Method != "POST" {
return outdata, user
}
if pw1 == "" {
outdata.Error = "Password must not be empty."
return outdata, user
}
if pw1 != pw2 {
outdata.Error = "Passwords are not identical."
return outdata, user
}
hash, err := bcrypt.GenerateFromPassword([]byte(pw1), bcrypt.DefaultCost)
if err != nil {
log.Printf("Could not has password: %s", err)
outdata.Error = "Could not save password."
return outdata, user
}
if err := user.SetPWHash(hash); err != nil {
log.Printf("Error while hashing password: %s", err)
outdata.Error = "Could not save password."
return outdata, user
}
if err := user.SetActivationCode(""); err != nil {
log.Printf("Error resetting acCode: %s", err)
}
outdata.Success = "Password was changed"
return outdata, user
}