From 724610a45d16941fa74f6a2d6bc3f343b9a574bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=80=97=E5=AD=90?= Date: Sat, 13 Jul 2024 04:17:45 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=8F=91=E5=B8=83v2.2.25?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/http/controllers/user_controller.go | 20 +++++++++++++++++++- config/panel.go | 2 +- routes/api.go | 1 + 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/app/http/controllers/user_controller.go b/app/http/controllers/user_controller.go index 881583a9f3..6e3865470e 100644 --- a/app/http/controllers/user_controller.go +++ b/app/http/controllers/user_controller.go @@ -73,10 +73,28 @@ func (r *UserController) Login(ctx http.Context) http.Response { // @Success 200 {object} SuccessResponse // @Router /panel/user/logout [post] func (r *UserController) Logout(ctx http.Context) http.Response { - ctx.Request().Session().Forget("user_id") + if ctx.Request().HasSession() { + ctx.Request().Session().Forget("user_id") + } + return Success(ctx, nil) } +// IsLogin +// +// @Summary 是否登录 +// @Tags 用户鉴权 +// @Produce json +// @Success 200 {object} SuccessResponse +// @Router /panel/user/isLogin [get] +func (r *UserController) IsLogin(ctx http.Context) http.Response { + if !ctx.Request().HasSession() { + return Success(ctx, false) + } + + return Success(ctx, ctx.Request().Session().Has("user_id")) +} + // Info // // @Summary 用户信息 diff --git a/config/panel.go b/config/panel.go index 4e703002be..582ce52624 100644 --- a/config/panel.go +++ b/config/panel.go @@ -8,7 +8,7 @@ func init() { config := facades.Config() config.Add("panel", map[string]any{ "name": "耗子面板", - "version": "v2.2.24", + "version": "v2.2.25", "ssl": config.Env("APP_SSL", false), // 安全入口 "entrance": config.Env("APP_ENTRANCE", "/"), diff --git a/routes/api.go b/routes/api.go index ca77ebc022..88722b8de4 100644 --- a/routes/api.go +++ b/routes/api.go @@ -32,6 +32,7 @@ func Api() { userController := controllers.NewUserController() r.Middleware(frameworkmiddleware.Throttle("login")).Post("login", userController.Login) r.Post("logout", userController.Logout) + r.Get("isLogin", userController.IsLogin) r.Middleware(middleware.Session()).Get("info", userController.Info) }) r.Prefix("task").Middleware(middleware.Session()).Group(func(r route.Router) {