Exemplo n.º 1
0
/**
 * 登录
 */
func (this *LoginController) Login() {
	val := validation.Validation{}
	username := this.GetString("username")
	password := this.GetString("password")

	val.Required(username, "username")
	val.Required(password, "password")

	if val.HasErrors() {
		for _, v := range val.Errors {
			this.Ctx.WriteString("<script>alert('" + v.Key + " " + v.Message + "');</script>") //遇到一个错误就可以StopRun了其实,这里只是练习验证模块
		}
		this.StopRun()
	}
	toolbox.Display("u", username)
	toolbox.Display("pa", password)

	password = utils.LoginPassword(password)
	toolbox.Display("paaa", password)

	if user.CheckLogin(username, password) == true {
		this.SetSession("username", username)
		this.Ctx.SetCookie("username", username)
		this.Redirect("/admin", 302)
	} else {
		this.Redirect("/login", 302)
	}
}
Exemplo n.º 2
0
/**
 * 更改密码
 */
func (this *Users) ChangePassword(username, oldPassword, password string) error {
	if !this.CheckLogin(username, utils.LoginPassword(oldPassword)) {
		return errors.New("check old password fail")
	}
	password = utils.LoginPassword(password)
	toolbox.Display("u", username)
	toolbox.Display("n", password)
	num, err := o.QueryTable(this).Filter("username", username).Update(orm.Params{"password": password})
	toolbox.Display("err", err)
	toolbox.Display("num", num)
	return err
}