This commit is contained in:
2026-07-18 10:52:32 +08:00
parent 2dcafae465
commit b5ef58f434
61 changed files with 1274 additions and 2142 deletions

View File

@@ -116,3 +116,32 @@ func (c *AuthController) ChangePassword(ctx *gin.Context) {
utils.SuccessWithMessage(ctx, "密码修改成功", nil)
}
// Logout 退出登录
// POST /api/auth/logout
func (c *AuthController) Logout(ctx *gin.Context) {
userID := middleware.GetCurrentUserID(ctx)
token := ctx.GetHeader("token")
if token == "" {
authHeader := ctx.GetHeader("Authorization")
if len(authHeader) > 7 && authHeader[:7] == "Bearer " {
token = authHeader[7:]
}
}
if userID > 0 && token != "" {
c.authService.Logout(userID, token)
}
utils.SuccessWithMessage(ctx, "已退出登录", nil)
}
// GetSessions 获取当前用户的登录会话列表
// GET /api/auth/sessions
func (c *AuthController) GetSessions(ctx *gin.Context) {
userID := middleware.GetCurrentUserID(ctx)
if userID == 0 {
utils.Unauthorized(ctx, "未登录")
return
}
sessions := c.authService.GetSessions(userID)
utils.Success(ctx, sessions)
}