Exemple #1
0
// Reset implemented user password reset.
func (this *ResetRouter) Post() {
	code := this.GetString(":code")
	this.Data["Code"] = code

	var user models.User

	if auth.VerifyUserResetPwdCode(&user, code) {
		this.Data["Success"] = true

		form := auth.ResetPwdForm{}
		if this.ValidFormSets(&form) == false {
			return
		}

		user.IsActive = true
		user.Rands = models.GetUserSalt()

		if err := auth.SaveNewPassword(&user, form.Password); err != nil {
			log.Error("ResetPost Save New Password: "******"/login", 302, "ResetSuccess")

	} else {
		this.Data["Success"] = false
	}

	this.Render("auth/reset.html", this.Data)
}
Exemple #2
0
// Logout implemented user logout page.
func (this *Logout) Get() {
	auth.LogoutUser(this.Context, &this.Session)

	// write flash message
	this.FlashWrite("HasLogout", "true")

	this.Redirect("/login")
}
Exemple #3
0
func (this *BaseAdminRouter) Before() {
	this.BaseRouter.Before()

	if this.CheckActiveRedirect() {
		return
	}

	// if user isn't admin, then logout user
	if !this.User.IsAdmin {
		auth.LogoutUser(this.Context, &this.Session)
		// write flash message, use .flash.NotPermit
		this.FlashWrite("NotPermit", "true")
		this.Redirect("/login", 302)
		return
	}

	// it's admin and current in admin page
	this.Data["IsAdminPage"] = true
}
Exemple #4
0
// Before implemented Before method for baseRouter.
func (this *BaseRouter) Before() {
	this.Data = make(renders.T)

	if setting.EnforceRedirect {
		// if the host not matching app settings then redirect to AppUrl
		if this.Ctx.Req().Host != setting.AppHost {
			this.Redirect(setting.AppUrl)
			return
		}
	}

	// page start time
	this.Data["PageStartTime"] = time.Now()

	// check flash redirect, if match url then end, else for redirect return
	if match, redir := this.CheckFlashRedirect(this.Ctx.Req().RequestURI); redir {
		return
	} else if match {
		this.EndFlashRedirect()
	}

	switch {
	// save logined user if exist in session
	case auth.GetUserFromSession(&this.User, &this.Session):
		this.IsLogin = true
	// save logined user if exist in remember cookie
	case auth.LoginUserFromRememberCookie(&this.User, this.Ctx.Context, &this.Session):
		this.IsLogin = true
	}

	if this.IsLogin {
		this.IsLogin = true
		this.Data["User"] = &this.User
		this.Data["IsLogin"] = this.IsLogin

		// if user forbided then do logout
		if this.User.IsForbid {
			auth.LogoutUser(this.Context, &this.Session)
			this.FlashRedirect("/login", 302, "UserForbid")
			return
		}
	}

	// Setting properties.
	this.Data["Flush"] = this.Flash.Data()

	// Redirect to make URL clean.
	if this.setLang() {
		i := strings.Index(this.Ctx.Req().RequestURI, "?")
		this.Redirect(this.Ctx.Req().RequestURI[:i])
		return
	}

	// pass xsrf helper to template context
	this.Data["xsrf_token"] = this.XsrfValue
	this.Data["xsrf_html"] = this.XsrfFormHtml()

	// read unread notifications
	if this.IsLogin {
		this.Data["UnreadNotificationCount"] = models.GetUnreadNotificationCount(this.User.Id)
	}

	// if method is GET then auto create a form once token
	if this.Req().Method == "GET" {
		this.FormOnceCreate()
	}
}