// Active implemented check Email actice code. func (this *RegisterController) Active() { this.TplName = "auth/active.html" // no need active if this.CheckActiveRedirect(false) { return } code := this.GetString(":code") var user user.User if this.UserService.VerifyUserActiveCode(&user, code) { user.Active = true user.PasswordSalt = userServ.GetUserSalt() if err := this.UserService.Update(&user, "Active", "PasswordSalt", "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 } }
// Reset implemented user password reset. func (this *ForgotController) ResetPost() { this.TplName = "auth/reset.html" code := this.GetString(":code") this.Data["Code"] = code var user user.User if this.UserService.VerifyUserResetPwdCode(&user, code) { this.Data["Success"] = true form := ResetPwdModel{} if this.ValidFormSets(&form) == false { return } user.Active = true user.PasswordSalt = userServ.GetUserSalt() if err := this.UserService.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 RegisterController. func (this *RegisterController) Register() { this.Data["IsRegister"] = true this.TplName = "auth/register.html" // no need login if this.CheckLoginRedirect(false) { return } form := RegisterForm{Locale: this.Locale} // valid form and put errors to template context if this.ValidFormSets(&form) == false { return } // Create new user. u := new(user.User) //set to default usertype ut := new(user.UserType) ut.Id = 1 role := new(user.Role) role.Id = 1 if !setting.IsActivationRequired { u.Active = true } if err := this.UserService.RegisterUser(u, form.Username, form.Email, form.Password, ut, role); err == nil { if setting.IsActivationRequired { email.SendRegisterMail(this.Locale, u) } loginRedirect := this.LoginUser(u, false) if loginRedirect == "/" { //this.FlashRedirect("/settings/profile", 302, "RegSuccess") this.FlashRedirect("/", 302, "RegSuccess") } else { this.Redirect(loginRedirect, 302) } return } else { beego.Error("Register: Failed ", err) } }
func (form *ProfileForm) SaveUserProfile(u *user.User) error { // set md5 value if the value is an email if strings.IndexRune(form.GrEmail, '@') != -1 { form.GrEmail = utils.EncodeMd5(form.GrEmail) } changes := utils.FormChanges(u, form) if len(changes) > 0 { // if email changed then need re-active if u.Email != form.Email { u.Active = false changes = append(changes, "Active") } serv := &userServ.UserService{} utils.SetFormValues(form, u) return serv.Update(u, changes...) } return nil }