From d3ecaeed46fa9c4a663fc6fa34b8faf6899a9e6c Mon Sep 17 00:00:00 2001 From: yokowu <18836617@qq.com> Date: Tue, 22 Jul 2025 11:48:52 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=99=BB=E5=87=BA=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/docs/swagger.json | 48 ++++++++++++++++++++++++ backend/internal/user/handler/v1/user.go | 40 +++++++++++++++++++- 2 files changed, 86 insertions(+), 2 deletions(-) diff --git a/backend/docs/swagger.json b/backend/docs/swagger.json index 00fe6b2..2c0f20e 100644 --- a/backend/docs/swagger.json +++ b/backend/docs/swagger.json @@ -258,6 +258,30 @@ } } }, + "/api/v1/admin/logout": { + "post": { + "description": "管理员登出", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Admin" + ], + "summary": "管理员登出", + "operationId": "admin-logout", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/web.Resp" + } + } + } + } + }, "/api/v1/admin/setting": { "get": { "description": "获取系统设置", @@ -2147,6 +2171,30 @@ } } }, + "/api/v1/user/logout": { + "post": { + "description": "用户登出", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "User" + ], + "summary": "用户登出", + "operationId": "logout", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/web.Resp" + } + } + } + } + }, "/api/v1/user/oauth/callback": { "get": { "description": "用户 OAuth 回调", diff --git a/backend/internal/user/handler/v1/user.go b/backend/internal/user/handler/v1/user.go index 7b5efd0..a3d98ca 100644 --- a/backend/internal/user/handler/v1/user.go +++ b/backend/internal/user/handler/v1/user.go @@ -76,10 +76,11 @@ func NewUserHandler( admin.GET("/setting", web.BaseHandler(u.GetSetting)) admin.Use(auth.Auth(), active.Active("admin")) - admin.PUT("/setting", web.BindHandler(u.UpdateSetting)) - admin.POST("/create", web.BindHandler(u.CreateAdmin)) admin.GET("/list", web.BaseHandler(u.AdminList, web.WithPage())) admin.GET("/login-history", web.BaseHandler(u.AdminLoginHistory, web.WithPage())) + admin.PUT("/setting", web.BindHandler(u.UpdateSetting)) + admin.POST("/create", web.BindHandler(u.CreateAdmin)) + admin.POST("/logout", web.BaseHandler(u.AdminLogout)) admin.DELETE("/delete", web.BaseHandler(u.DeleteAdmin)) // user @@ -91,6 +92,7 @@ func NewUserHandler( g.GET("/profile", web.BaseHandler(u.Profile), auth.UserAuth()) g.PUT("/profile", web.BindHandler(u.UpdateProfile), auth.UserAuth()) + g.POST("/logout", web.BaseHandler(u.Logout), auth.UserAuth()) g.Use(auth.Auth(), active.Active("admin")) @@ -236,6 +238,23 @@ func (h *UserHandler) Login(c *web.Context, req domain.LoginReq) error { return c.Success(resp) } +// Logout 用户登出 +// +// @Tags User +// @Summary 用户登出 +// @Description 用户登出 +// @ID logout +// @Accept json +// @Produce json +// @Success 200 {object} web.Resp{} +// @Router /api/v1/user/logout [post] +func (h *UserHandler) Logout(c *web.Context) error { + if err := h.session.Del(c, consts.UserSessionName); err != nil { + return err + } + return c.Success(nil) +} + // Update 更新用户 // // @Tags User @@ -318,6 +337,23 @@ func (h *UserHandler) AdminLogin(c *web.Context, req domain.LoginReq) error { return c.Success(resp) } +// AdminLogout 管理员登出 +// +// @Tags Admin +// @Summary 管理员登出 +// @Description 管理员登出 +// @ID admin-logout +// @Accept json +// @Produce json +// @Success 200 {object} web.Resp{} +// @Router /api/v1/admin/logout [post] +func (h *UserHandler) AdminLogout(c *web.Context) error { + if err := h.session.Del(c, consts.SessionName); err != nil { + return err + } + return c.Success(nil) +} + // List 获取用户列表 // // @Tags User