Ejemplo n.º 1
0
func (this *LoginController) CheckPwd() {
	username := this.Input().Get("username")
	password := this.Input().Get("password")
	var result []*models.User
	o := orm.NewOrm()
	o.QueryTable("user").Filter("Name", username).Filter("Password", models.HashPassword(password)).One(&result)
	if len(result) == 1 {
		this.Data["json"] = true
	} else {
		this.Data["json"] = false
	}
	this.ServeJson()
}
Ejemplo n.º 2
0
func GetUserByCookie(ctx *context.Context) ([]*models.User, bool) {
	uk, unameErr := ctx.Request.Cookie("uname")
	pk, pwdErr := ctx.Request.Cookie("pwd")
	var result []*models.User
	if unameErr != nil || pwdErr != nil {
		return result, false
	}
	o := orm.NewOrm()
	o.QueryTable("user").Filter("Name", uk.Value).Filter("Password", models.HashPassword(pk.Value)).One(&result)
	fmt.Println(result)
	if len(result) > 0 {
		return result, true
	} else {
		return result, false
	}
}
Ejemplo n.º 3
0
func (this *LoginController) Post() {
	username := this.Input().Get("username")
	password := this.Input().Get("password")
	remenber := this.Input().Get("remenber")
	if username == "" || password == "" {
		this.Redirect("/", 302)
		return
	}
	var user []*models.User
	o := orm.NewOrm()
	o.QueryTable("user").Filter("Name", username).Filter("Password", models.HashPassword(password)).One(&user)

	if len(user) == 0 {
		this.Redirect("/login", 302)
		return
	}
	fmt.Println(user)
	if remenber == "true" {
		lib.SetCookie(this.Ctx, username, password, contains.MiddleCookieTime)
	} else {
		lib.SetCookie(this.Ctx, username, password, contains.SmallCookieTime)
	}
	this.Redirect("/", 301)
}