Exemple #1
1
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
}
Exemple #2
0
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
}