示例#1
0
文件: account.go 项目: jango2015/OJ
//POST /account/reset
func (c Account) PostReset(user models.User) revel.Result {
	username := c.Session[USERNAME]
	if user.Password == user.ConfirmPassword {
		user.HashedPassword, user.Salt = models.GenHashPasswordAndSalt(user.Password)
		user.ResetCode = ""
		_, err := engine.Where("name = ?", username).
			Cols("hashed_password", "salt", "reset_code").
			Update(&user)
		if err != nil {
			fmt.Println(err)
		}
		c.Session[USERNAME] = username
		c.Flash.Success("reset success!")
		return c.Redirect(routes.Problem.Index(0))
	} else {
		resetcode := c.Flash.Data[RESETCODE]
		c.Flash.Error("两次密码输入不一致")
		return c.Redirect(routes.Account.Reset(resetcode))
	}
}
示例#2
0
文件: account.go 项目: jango2015/OJ
//POST /account/edit
func (c Account) PostEdit(user models.User) revel.Result {
	c.Validation.Required(user.Name).Message("用户名不能为空")
	if c.Validation.HasErrors() {
		c.Validation.Keep()
		c.FlashParams()
		return c.Redirect(routes.Account.Edit())
	}
	if user.HasName() {
		return c.Redirect(routes.User.Profile())
	}
	if user.Password != "" {
		if user.Password == user.ConfirmPassword {
			user.HashedPassword, user.Salt = models.GenHashPasswordAndSalt(user.Password)
			username := c.Session[USERNAME]
			u := models.GetCurrentUser(username)
			_, err := engine.Id(u.Id).Update(user)
			if err != nil {
				fmt.Println(err)
			}
			c.Session[USERNAME] = user.Name
			return c.Redirect(routes.User.Profile())
		} else {
			c.Flash.Error("passwords not match")
			return c.Redirect(routes.Account.Notice())
		}
	} else {
		username := c.Session[USERNAME]
		u := models.GetCurrentUser(username)
		_, err := engine.Id(u.Id).Cols("name").Update(user)
		if err != nil {
			fmt.Println(err)
			c.Flash.Error(err.Error())
		} else {
			c.Session[USERNAME] = user.Name
			c.Flash.Success("modify sucess")
		}
		return c.Redirect(routes.User.Profile())
	}

}