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 @@