Exemplo n.º 1
0
func (this *HomeController) SavePassword() {
	var ajaxResult models.AjaxResult
	var data map[string]interface{}
	err := json.Unmarshal(this.Ctx.Input.RequestBody, &data)
	if err != nil {
		fmt.Println(err)
	}

	oldpwd := data["oldpwd"].(string)
	newpwd := data["newpwd"].(string)

	if utils.ToMD5([]byte(oldpwd)) != this.User.Password {
		ajaxResult.Success = false
		ajaxResult.Error = "原密码输入错误!"
	} else {
		user := new(models.User)
		user.Id = this.User.Id
		user.Username = this.UserName
		user.Password = utils.ToMD5([]byte(newpwd))
		ajaxResult = user.SaveUserInfo()
	}

	this.Data["json"] = ajaxResult
	this.ServeJson()
}
Exemplo n.º 2
0
func (this *LoginController) Post() {
	username := this.GetString("username")
	password := this.GetString("password")

	ajaxResult := new(models.AjaxResult)

	user := new(models.User)
	err := user.GetUserName(username)
	fmt.Println(user)
	if err != nil {
		ajaxResult.Error = "帐号不存在!"
	} else {
		if user.Password != utils.ToMD5([]byte(password)) {
			ajaxResult.Error = "密码输入错误!"
		} else {
			ajaxResult.Success = true
			this.SetSession("adminAuthen", utils.ToJson(user))
		}
	}

	this.Ctx.WriteString(ajaxResult.ToString())
}