func HandleAccess(ctx *context.Context) { token := ctx.GetCookie("epic_user_token") ok, _ := tools.VerifyToken(token) if len(token) != 0 && ok { ctx.Redirect(302, "/succeed") } }
func (this *VerifyToken) Get() { token := this.GetString("token") result := VerifyTokenResult{} if len(token) == 0 { result.Succeed = false this.Data["json"] = &result this.ServeJson() return } ok, userid := tools.VerifyToken(token) if !ok { result.Succeed = false this.Data["json"] = &result this.ServeJson() return } ok, user := auth.GetUserInfo(userid) if ok { result.Username = user.UserName result.Email = user.Email } result.Succeed = true result.Userid = userid this.Data["json"] = &result this.ServeJson() return }
func (this *SettingController) ChangePasswordSave() { redirectURL := this.GetString("epic_sub_site") if "" == redirectURL { redirectURL = config.GetRedirectURL() } this.Data["epic_sub_site"] = redirectURL this.Data["redirectURL"] = redirectURL this.Data["succ"] = false passwordOld := this.GetString("PasswordOld") password := this.GetString("Password") passwordRe := this.GetString("PasswordRe") if len(passwordOld) == 0 || len(password) == 0 || len(passwordRe) == 0 { this.Data["msg"] = "修改密码失败,缺少参数" this.TplNames = "change_password_succeed.html" return } if password != passwordRe { this.Data["msg"] = "修改密码失败,两次密码输入不一致" this.TplNames = "change_password_succeed.html" return } token := this.Ctx.GetCookie("epic_user_token") ok, userId := tools.VerifyToken(token) if len(token) == 0 || !ok { this.Data["msg"] = "修改密码失败,请重新登录" this.TplNames = "change_password_succeed.html" return } ok, user := auth.GetUserInfoFrmDB(userId) if !ok { this.Data["msg"] = "修改密码失败,用户不存在" this.TplNames = "change_password_succeed.html" return } ok = auth.VerifyPassword(passwordOld, user.Password) if !ok { this.Data["msg"] = "修改密码失败,当前密码验证错误" this.TplNames = "change_password_succeed.html" return } err := auth.SaveNewPassword(&user, password) if err != nil { beego.Error("密码修改失败:", err) this.Data["msg"] = "修改密码失败,请联系管理员" this.TplNames = "change_password_succeed.html" return } this.Data["msg"] = "修改密码成功,稍后将进行自动跳转" this.Data["succ"] = true this.TplNames = "change_password_succeed.html" }
func (this *SocialAuthController) ConnectPost() { token := this.Ctx.GetCookie("epic_user_token") ok, userId := tools.VerifyToken(token) if !ok || len(userId) == 0 { this.Redirect("/", 302) return } password := this.GetString("Password") userName := this.GetString("UserName") if len(userId) == 0 || len(password) == 0 || len(userName) == 0 { this.Data["userId"] = userId this.TplNames = "connect.html" this.Data["error"] = "[用户名]或者[密码]为空" this.Data["state"] = "注册失败" this.Data["msg"] = "[用户名]或者[邮箱]已被注册" return } isExist := auth.UserIsExists(userName, userName) if isExist { this.Data["userId"] = userId this.TplNames = "connect.html" this.Data["error"] = "[用户名]或者[邮箱]已被注册" this.Data["state"] = "注册失败" this.Data["msg"] = "[用户名]或者[邮箱]已被注册" return } user := models.User{} user.Password = password user.UserName = userName user.Id, _ = strconv.Atoi(userId) err := auth.ConnectUpdateUser(&user, password) if err != nil { this.Data["userId"] = userId this.TplNames = "connect.html" this.Data["error"] = err.Error() this.Data["state"] = "注册失败" beego.Error("注册失败-插入数据库出错", err) this.Data["msg"] = err.Error() return } subSitesConf := config.GetSubSites() this.Data["srcs"] = strings.Split(subSitesConf, ",") this.Data["token"] = token this.Data["state"] = "注册成功" this.Data["msg"] = "3秒后自动跳转!!" this.Data["succ"] = true this.Data["redirectURL"] = config.GetRedirectURL() this.TplNames = "succeed.html" }
func (this *SettingController) ChangePassword() { this.Data["AppUrl"] = beego.AppConfig.String("appUrl") this.TplNames = "change_password.html" redirectURL := this.GetString("redirectURL") if "" == redirectURL { redirectURL = this.GetString("epic_sub_site") if "" == redirectURL { redirectURL = config.GetRedirectURL() } } this.Data["redirectURL"] = redirectURL this.Data["epic_sub_site"] = redirectURL ctx := this.Ctx token := ctx.GetCookie("epic_user_token") ok, _ := tools.VerifyToken(token) if len(token) == 0 || !ok { ctx.Redirect(302, "/") return } }