Example #1
0
//登录状态验证
func (this *baseController) auth() {
	arr := strings.Split(this.Ctx.GetCookie("auth"), "|")
	if len(arr) == 2 {
		idstr, password := arr[0], arr[1]
		userid, _ := strconv.Atoi(idstr)
		if userid > 0 {
			var user models.User
			user.Id = userid
			if user.Read() == nil && password == util.Md5([]byte(this.getClientIp()+"|"+user.Password)) {
				this.userid = user.Id
				this.username = user.UserName
			}
		}
	}

	if this.userid == 0 && (this.controllerName != "account" ||
		(this.controllerName == "account" && this.actionName != "logout" && this.actionName != "login")) {
		this.Redirect("/admin/login", 302)
	}
}