func (this *LoginControllers) Post() { userName := this.Input().Get("log") password := this.Input().Get("pwd") rememberme := this.Input().Get("rem") //判断是否选择了自动登录 var status int if strings.EqualFold(rememberme, "forever") { status = 1 } else { status = 0 } num, err := models.QueryUser(userName, utils.GetMD5Str(password)) beego.Error(err) //判断是否查询到用户 if err == nil && num > 0 { //如果选择自动登录更新数据库登录状态 err := models.UpdateUserStatus(userName, password, 1) if err == nil { beego.Debug("update user raw count", num) } else { beego.Error(err) } // this.SetSession("log", userName) // this.SetSession("pwd", utils.GetMD5Str(password)) // this.SetSession("rem", utils.GetIntToStr(status)) // this.SetSession("loginstate", "yes") this.Ctx.SetCookie("log", userName) this.Ctx.SetCookie("pwd", utils.GetMD5Str(password)) this.Ctx.SetCookie("rem", utils.GetIntToStr(status)) this.Ctx.SetCookie("loginstate", "yes") this.Redirect("/", 302) } else { this.Data["isUser"] = true this.TplName = "login_page.html" } }
func (this *RegistControllers) Post() { beego.Debug(fmt.Sprintln(this.Input())) userName := this.Input().Get("user_login") userPassword := this.Input().Get("user_password") userEmail := this.Input().Get("user_email") if !strings.EqualFold(userName, "") && !strings.EqualFold(userPassword, "") && !strings.EqualFold(userEmail, "") { num, err := models.QueryUserName(userName) beego.Error(err) beego.Debug(num) //判断是否查询到用户 if err == nil && num == 0 { num, err := models.QueryUserEmail(userEmail) beego.Error(err) beego.Debug(num) if err == nil && num == 0 { num, err := models.QueryAllUser() beego.Error(err) beego.Debug(num) err = models.InsertUser((num + 1), userName, utils.GetMD5Str(userPassword), userName, userEmail, "", utils.GetModifyTime(), "", 0, userName) beego.Error(err) if err != nil { this.Data["registState"] = true this.Data["registValue"] = "注册失败" this.TplName = "regist_page.html" } else { this.Redirect("/api/user/login", 302) } } else { this.Data["registState"] = true this.Data["registValue"] = "邮箱已经存在" this.TplName = "regist_page.html" } } else { this.Data["registState"] = true this.Data["registValue"] = "账号已经存在" this.TplName = "regist_page.html" } } else { this.Data["isLogin"] = true this.Data["registValue"] = "注册信息不能空着" this.TplName = "regist_page.html" } }