feat:优化登录跳转

pull/425/head
lifei6671 2018-11-27 18:00:16 +08:00
parent cbe03642b4
commit f9a214199d
1 changed files with 11 additions and 21 deletions

View File

@ -20,6 +20,14 @@ type AccountController struct {
BaseController
}
func (c *AccountController) referer() string {
u, _ := url.PathUnescape(c.GetString("url"))
if u == "" {
u = conf.URLFor("HomeController.Index")
}
return u
}
func (c *AccountController) Prepare() {
c.BaseController.Prepare()
c.EnableXSRF = true
@ -111,41 +119,23 @@ func (c *AccountController) Login() {
c.SetSecureCookie(conf.GetAppKey(), "login", v, time.Now().Add(time.Hour * 24 * 30).Unix())
}
}
u, _ := url.PathUnescape(c.GetString("url"))
if u == "" {
u = c.Ctx.Request.Header.Get("Referer")
}
if u == "" {
u = conf.URLFor("HomeController.Index")
}
c.JsonResult(0, "ok", u)
c.JsonResult(0, "ok", c.referer())
} else {
beego.Error("用户登录 ->", err)
c.JsonResult(500, "账号或密码错误", nil)
}
} else {
u, _ := url.PathUnescape(c.GetString("url"))
if u == "" {
u = c.Ctx.Request.Header.Get("Referer")
}
if u == "" {
u = conf.URLFor("HomeController.Index")
}
c.Data["url"] = url.PathEscape(u)
c.Data["url"] = c.referer()
}
}
// 登录成功后的操作,如重定向到原始请求页面
func (c *AccountController) LoggedIn(isPost bool) interface{} {
turl := c.GetString("url")
turl := c.referer()
if !isPost {
// 检查是否存在 turl 参数,如果有则重定向至 turl 处,否则进入 Home 页面
if turl == "" {
turl = conf.URLFor("HomeController.Index")
}
c.Redirect(turl, 302)
return nil
} else {