Beispiel #1
0
func chackDqsjAccount(ctx *context.Context) (bool, string) {
	ck, err := ctx.Request.Cookie(DQSJ_USERNAME)
	if err != nil {
		return false, ""
	}

	username := ck.Value

	ck, err = ctx.Request.Cookie(DQSJ_PASSWORD)
	if err != nil {
		return false, ""
	}

	password := ck.Value

	admin, err := models.GetOneDqsjAdmin(username)
	beego.Debug("GetOneDqsjAdmin admin:", admin)
	if err != nil {
		return false, ""
	}
	if admin != nil && strings.EqualFold(username, admin.Username) && strings.EqualFold(password, admin.Password) {
		beego.Debug(" cookie username ", username)
		return true, username
	} else {
		return false, username
	}

}
Beispiel #2
0
//后台登录
func (c *DqsjController) AdminLogin() {
	if c.Ctx.Input.IsGet() {
		beego.Debug("AdminLogin Get")
	}
	if c.Ctx.Input.IsPost() {
		beego.Debug("AdminLogin Post")
		username := c.Input().Get("user")
		password := c.Input().Get("password")
		autologin := c.Input().Get("autologin") == "on"
		beego.Debug("AdminLogin Post user:"******"password:"******"/dqsj/adminlogin", 302)
				return
			}
			if admin != nil && strings.EqualFold(username, admin.Username) && strings.EqualFold(password, admin.Password) {
				maxAge := 0
				if autologin {
					maxAge = 1<<31 - 1
				}
				c.Ctx.SetCookie(DQSJ_USERNAME, username, maxAge, "/")
				c.Ctx.SetCookie(DQSJ_PASSWORD, password, maxAge, "/")
				beego.Debug("login ok------")
				c.Redirect("/dqsj/admin", 302)
				return
			} else {
				c.Redirect("/dqsj/adminlogin", 302)
				return
			}
		} else {
			c.Redirect("/dqsj/adminlogin", 302)
			return
		}
	}
	c.TplName = "dqsjadminlogin.html"
}