func (this *MainController) UserUpdate() { var userFront models.User err := json.Unmarshal(this.Ctx.Input.RequestBody, &userFront) if err != nil { beego.Error("invalid user," + err.Error()) } qsUser := new(models.User) userDb := models.User{Id: int64(userFront.Id)} qsUser.Query().Filter("id", int64(userFront.Id)).One(&userDb) userFront.Password = userDb.Password userFront.Update() res := &ResEntity{true, "修改成功", nil} this.Data["json"] = res this.ServeJson() return }
func (this *UserControlelr) Author() { qsUser := new(models.User) user := models.User{Id: int64(1)} qsUser.Query().Filter("id", 1).One(&user) this.Data["json"] = user this.ServeJson() }
func (this *MainController) ResetPwd() { h := md5.New() h.Write([]byte(string(this.Ctx.Input.RequestBody))) newPwd := hex.EncodeToString(h.Sum(nil)) qsUser := new(models.User) userDb := models.User{Id: 1} qsUser.Query().Filter("id", int64(1)).One(&userDb) userDb.Password = newPwd userDb.Update() res := &ResEntity{true, "修改成功", nil} this.Data["json"] = res this.ServeJson() return }
func (this *MainController) ValidUser() { res := &ResEntity{} if time.Now().Unix()-LAST_LOGIN_TIME < RELOGIN_PERIOD { LOGIN_COUNT++ } else { LOGIN_COUNT = 0 } if LOGIN_COUNT >= LOGIN_LOCK_TIMES { res.Success = false if LOGIN_COUNT > LOGIN_LOCK_TIMES+3 { res.Msg = "悟空,不要调皮了" } else { res.Msg = "连续尝试" + strconv.Itoa(LOGIN_COUNT) + "次登录失败, 请隔" + strconv.Itoa(int(RELOGIN_PERIOD)) + "秒后再登录" } this.Data["json"] = res this.ServeJson() return } h := md5.New() h.Write([]byte(string(this.Ctx.Input.RequestBody))) inputPwd := hex.EncodeToString(h.Sum(nil)) qsUser := new(models.User) userDb := models.User{Id: 1} qsUser.Query().Filter("id", int64(1)).One(&userDb) if userDb.Password != inputPwd { LAST_LOGIN_TIME = time.Now().Unix() res.Success = false res.Msg = "登录失败" this.Data["json"] = res this.ServeJson() return } /*maxAge := 0 maxAge = 1 << 31 -1 this.Ctx.SetCookie("username", "inote", maxAge, "/")*/ LOGIN_COUNT = 0 LAST_LOGIN_TIME = time.Now().Unix() this.SetSession("inote", 1) res.Success = true res.Msg = "登录成功" this.Data["json"] = res this.ServeJson() return }