提交
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user