Exemplo n.º 1
0
// Reset implemented user password reset.
func (this *ForgotRouter) ResetPost() {
	this.TplNames = "auth/reset.html"

	code := this.GetString(":code")
	this.Data["Code"] = code

	var user models.User

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

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

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

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

	} else {
		this.Data["Success"] = false
	}
}
Exemplo n.º 2
0
// Logout implemented user logout page.
func (this *LoginRouter) Logout() {
	models.LogoutUser(&this.Controller)

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

	this.Redirect("/login", 302)
}
Exemplo n.º 3
0
func (this *BaseAdminRouter) NestPrepare() {
	if this.CheckActiveRedirect() {
		return
	}

	// if user isn't admin, then logout user
	if !this.user.IsAdmin {
		models.LogoutUser(&this.Controller)

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

		this.Redirect("/login", 302)
		return
	}

	// current in admin page
	this.Data["IsAdmin"] = true

	if app, ok := this.AppController.(ModelPreparer); ok {
		app.ModelPrepare()
		return
	}
}
Exemplo n.º 4
0
// Prepare implemented Prepare method for baseRouter.
func (this *baseRouter) Prepare() {
	if utils.EnforceRedirect {
		// if the host not matching app settings then redirect to AppUrl
		if this.Ctx.Request.Host != utils.AppHost {
			this.Redirect(utils.AppUrl, 302)
			return
		}
	}

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

	// start session
	this.StartSession()

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

	// save logined user if exist in session
	if models.GetUserFromSession(&this.user, this.CruSession) {
		this.isLogin = true
		this.Data["User"] = &this.user
		this.Data["IsLogin"] = this.isLogin

		// if user forbided then do logout
		if this.user.IsForbid {
			models.LogoutUser(&this.Controller)
			this.FlashRedirect("/login", 302, "UserForbid")
			return
		}

	} else {
		this.isLogin = false
	}

	// Setting properties.
	this.Data["AppName"] = utils.AppName
	this.Data["AppVer"] = utils.AppVer
	this.Data["AppUrl"] = utils.AppUrl
	this.Data["AppLogo"] = utils.AppLogo
	this.Data["AvatarURL"] = utils.AvatarURL
	this.Data["IsProMode"] = utils.IsProMode

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

	// read flash message
	beego.ReadFromRequest(&this.Controller)

	// pass xsrf helper to template context
	xsrfToken := this.XsrfToken()
	this.Data["xsrf_token"] = xsrfToken
	this.Data["xsrf_html"] = template.HTML(this.XsrfFormHtml())

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

	if app, ok := this.AppController.(NestPreparer); ok {
		app.NestPrepare()
	}
}