예제 #1
0
func (this *BaseController) AssignIsAdmin() {
	admin_name := this.Ctx.GetCookie("admin_name")
	admin_password := this.Ctx.GetCookie("admin_password")
	name := this.Ctx.GetCookie("name")
	password := this.Ctx.GetCookie("password")

	if admin_name == g.RootName && admin_password == g.RootPass && admin_name != "" && admin_password != "" {
		this.IsAdmin = true
		this.IsLogin = true
		this.UserName = "******"
		// fmt.Println("*******************登录成功,username="******"IsAdmin"] = this.IsAdmin
	this.Data["IsLogin"] = this.IsLogin
	this.Data["UserName"] = this.UserName
}
예제 #2
0
func (this *LoginController) DoLogin() {
	name := this.GetString("name")
	if name == "" {
		this.Ctx.WriteString("name is blank")
		return
	}
	password := this.GetString("password")
	if password == "" {
		this.Ctx.WriteString("password is blank")
		return
	}

	if g.RootName == name && g.RootPass == password {
		this.Ctx.SetCookie("admin_name", name, 2592000, "/")
		this.Ctx.ResponseWriter.Header().Add("Set-Cookie", "admin_password="******"; Max-Age=2592000; Path=/; httponly")
		this.Ctx.WriteString("admin login success")
		return
	}
	result := models.CheckPassword(name, password)
	if result {
		this.Ctx.SetCookie("name", name, 2592000, "/")
		this.Ctx.ResponseWriter.Header().Add("Set-Cookie", "password="******"; Max-Age=2592000; Path=/; httponly")
		this.Ctx.WriteString("login success")
		return
	}

	return
}
예제 #3
0
func CheckAccount(t *context.Context) bool {
	n, err := t.Request.Cookie("name")
	if err != nil {
		return false
	}
	name := n.Value

	p, err := t.Request.Cookie("password")
	if err != nil {
		return false
	}
	password := p.Value
	isright := models.CheckPassword(name, password)
	return isright
}