From 6fb4f1e6b50e7f279d38005752f8993176e3b811 Mon Sep 17 00:00:00 2001 From: ZJY <764763903@qq.com> Date: Thu, 2 Sep 2021 08:28:50 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E3=80=82=E3=80=82=E3=80=82?= =?UTF-8?q?=E3=80=82=E8=AF=B7=E5=8B=BF=E6=8B=89=E5=8F=96=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controllers/account.go | 4 ++++ controllers/base.go | 3 +++ main.go | 2 +- theme/admin.html | 30 ++++++++++++++++++++++++++++++ 4 files changed, 38 insertions(+), 1 deletion(-) diff --git a/controllers/account.go b/controllers/account.go index c37c4fe..888f0aa 100644 --- a/controllers/account.go +++ b/controllers/account.go @@ -75,3 +75,7 @@ func (c *AccountController) CreateOrUpdate() { func (c *AccountController) Admin() { c.Ctx.WriteString(models.Admin) } + +func (c *AccountController) IsAdmin() { + c.SetSession("pin", "test") +} diff --git a/controllers/base.go b/controllers/base.go index 3dfae5a..9a26d43 100644 --- a/controllers/base.go +++ b/controllers/base.go @@ -2,6 +2,7 @@ package controllers import ( "encoding/json" + "github.com/beego/beego/v2/core/logs" beego "github.com/beego/beego/v2/server/web" "github.com/cdle/xdd/models" "github.com/go-playground/locales/zh" @@ -112,10 +113,12 @@ func (c *BaseController) Logined() *BaseController { return c } if v := c.GetSession("pin"); v == nil { + logs.Warn("test") c.Ctx.Redirect(302, "/") c.StopRun() } else { c.PtPin = v.(string) + logs.Warn(v.(string)) if strings.Contains(models.Config.Master, v.(string)) { c.Master = true } diff --git a/main.go b/main.go index c28b4c8..9ec9065 100644 --- a/main.go +++ b/main.go @@ -58,7 +58,7 @@ func main() { web.Router("/api/account", &controllers.AccountController{}, "get:List") web.Router("/api/account", &controllers.AccountController{}, "post:CreateOrUpdate") web.Router("/admin", &controllers.AccountController{}, "get:Admin") - web.Router("/admin", &controllers.AccountController{}, "get:Admin") + web.Router("/admin", &controllers.AccountController{}, "post:IsAdmin") if models.Config.Static == "" { models.Config.Static = "./static" } diff --git a/theme/admin.html b/theme/admin.html index 2180772..e30393e 100644 --- a/theme/admin.html +++ b/theme/admin.html @@ -76,8 +76,38 @@