// 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 models.VerifyUserResetPwdCode(&user, code) { this.Data["Success"] = true form := models.ResetPwdForm{} if this.ValidFormSets(&form) == false { return } user.IsActive = true user.Rands = models.GetUserSalt() if err := models.SaveNewPassword(&user, form.Password); err != nil { beego.Error("ResetPost Save New Password: "******"/login", 302, "ResetSuccess") } else { this.Data["Success"] = false } }
// Register implemented Post method for RegisterRouter. func (this *RegisterRouter) Register() { this.Data["IsRegister"] = true this.TplNames = "auth/register.html" // no need login if this.CheckLoginRedirect(false) { return } form := models.RegisterForm{Locale: this.Locale} // valid form and put errors to template context if this.ValidFormSets(&form) == false { return } // Create new user. user := new(models.User) // set default Lang user.Lang = this.Locale.Index() if err := models.RegisterUser(user, form); err == nil { models.SendRegisterMail(this.Locale, user) // login user models.LoginUser(user, &this.Controller, false) this.FlashRedirect("/settings/profile", 302, "RegSuccess") return } else { beego.Error("Register: Failed ", err) } }
// 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 models.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 } }
// view for new object save func (this *UserAdminRouter) Save() { form := models.UserAdminForm{Create: true} if this.ValidFormSets(&form) == false { return } var user models.User form.SetToUser(&user) if err := user.Insert(); err == nil { this.FlashRedirect(fmt.Sprintf("/admin/user/%d", user.Id), 302, "CreateSuccess") return } else { beego.Error(err) this.Data["Error"] = err } }