// Reset implemented user password reset. func (this *ForgotRouter) ResetPost() { this.TplNames = "auth/reset.html" code := this.GetString(":code") this.Data["Code"] = code var user models.User if auth.VerifyUserResetPwdCode(&user, code) { this.Data["Success"] = true form := auth.ResetPwdForm{} if this.ValidFormSets(&form) == false { return } user.IsActive = true user.Rands = models.GetUserSalt() if err := auth.SaveNewPassword(&user, form.Password); err != nil { beego.Error("ResetPost Save New Password: "******"/login", 302, "ResetSuccess") } else { this.Data["Success"] = false } }
// Active implemented check Email actice code. func (this *RegisterRouter) Active() { this.TplNames = "auth/active.html" // no need active if this.CheckActiveRedirect(false) { return } code := this.GetString(":code") var user models.User if auth.VerifyUserActiveCode(&user, code) { user.IsActive = true user.Rands = models.GetUserSalt() if err := user.Update("IsActive", "Rands", "Updated"); err != nil { beego.Error("Active: user Update ", err) } if this.IsLogin { this.User = user } this.Redirect("/active/success", 302) } else { this.Data["Success"] = false } }
// register create user func RegisterUser(user *models.User, username, email, password string, locale i18n.Locale) error { // use random salt encode password salt := models.GetUserSalt() pwd := utils.EncodePassword(password, salt) user.UserName = strings.ToLower(username) user.Email = strings.ToLower(email) // save salt and encode password, use $ as split char user.Password = fmt.Sprintf("%s$%s", salt, pwd) // save md5 email value for gravatar user.GrEmail = utils.EncodeMd5(user.Email) // Use username as default nickname. user.NickName = user.UserName //set default language if locale.Lang == "en-US" { user.Lang = setting.LangEnUS } else { user.Lang = setting.LangZhCN } //set default avatar user.AvatarType = setting.AvatarTypeGravatar return user.Insert() }
// register create user func RegisterUser(user *models.User, username, email, password string) error { // use random salt encode password salt := models.GetUserSalt() pwd := utils.EncodePassword(password, salt) user.UserName = strings.ToLower(username) user.Email = strings.ToLower(email) // save salt and encode password, use $ as split char user.Password = fmt.Sprintf("%s$%s", salt, pwd) // save md5 email value for gravatar user.GrEmail = utils.EncodeMd5(user.Email) // Use username as default nickname. user.NickName = user.UserName return user.Insert() }
// set a new password to user func SaveNewPassword(user *models.User, password string) error { salt := models.GetUserSalt() user.Password = fmt.Sprintf("%s$%s", salt, utils.EncodePassword(password, salt)) return user.Update("Password", "Rands", "Updated") }