From bee2504a7a6c2504567af11ac1ea239db6d2a77c Mon Sep 17 00:00:00 2001 From: PBK-B Date: Sun, 5 Sep 2021 15:03:16 +0800 Subject: [PATCH] fix: repair multiple redirection problems when landing --- controllers/admin.go | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/controllers/admin.go b/controllers/admin.go index 7b1a3b5..029a6f0 100644 --- a/controllers/admin.go +++ b/controllers/admin.go @@ -13,22 +13,38 @@ type AdminController struct { func (c *AdminController) Get() { _, _, is := isLogin(c) + flash := beego.NewFlash() + if _, ok := flash.Data["notice"]; ok { + c.TplName = "admin.tpl" + return + } + if !is { // token 获取失败或失效,或用户被禁用将跳转登陆 c.Redirect("/login", 301) c.Finish() + return } c.TplName = "admin.tpl" } func (c *AdminController) LoginPage() { - _, _, is := isLogin(c) + token, _, is := isLogin(c) + if is { + + flash := beego.NewFlash() + flash.Notice(token) + flash.Store(&c.Controller) + c.Redirect("/admin", 301) - } else { - c.TplName = "login.tpl" + c.Finish() + return } + + c.TplName = "login.tpl" + } func isLogin(c *AdminController) (token string, user models.Users, isLogin bool) {