Esempio n. 1
0
File: auth.go Progetto: zeuson/wego
// Get implemented login page.
func (this *Login) Get() error {
	this.Data["IsLoginPage"] = true

	loginRedirect := strings.TrimSpace(this.GetString("to"))
	if loginRedirect == "" {
		loginRedirect = this.Ctx.Req().Header.Get("Referer")
	}
	if utils.IsMatchHost(loginRedirect) == false {
		loginRedirect = "/"
	}

	// no need login
	if this.CheckLoginRedirect(false, loginRedirect) {
		return nil
	}

	if len(loginRedirect) > 0 {
		auth.SetCookie(this, "login_to", loginRedirect, 0, "/")
	}

	form := auth.LoginForm{}
	this.SetFormSets(&form)

	return this.Render("auth/login.html", this.Data)
}
Esempio n. 2
0
// get login redirect url from cookie
func GetLoginRedirect(ctx *tango.Context) string {
	loginRedirect := strings.TrimSpace(GetCookie(ctx.Req(), "login_to"))
	if utils.IsMatchHost(loginRedirect) == false {
		loginRedirect = "/"
	} else {
		SetCookie(ctx, "login_to", "", -1, "/")
	}
	return loginRedirect
}
Esempio n. 3
0
func (this *BaseRouter) LoginUser(user *models.User, remember bool) string {
	ck := this.Cookies().Get("login_to")
	var loginRedirect string
	if ck != nil {
		loginRedirect = strings.TrimSpace(ck.Value)
	}
	if !utils.IsMatchHost(loginRedirect) {
		loginRedirect = "/"
	} else {
		auth.SetCookie(this, "login_to", "", -1, "/")
	}

	// login user
	auth.LoginUser(user, this.Context, &this.Session, remember)

	this.setLangCookie(i18n.GetLangByIndex(user.Lang))

	return loginRedirect
}