新版仿ok交易所-后端
zyy
2025-10-13 9b818aedae8481c21a0f45cca55f212eb551cd5b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*
 * Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved.
 *
 * https://www.mall4j.com/
 *
 * 未经允许,不可做商业用途!
 *
 * 版权所有,侵权必究!
 */
package com.yami.trading.security.common.controller;
 
import cn.hutool.core.util.StrUtil;
import com.yami.trading.security.common.enums.SysTypeEnum;
import com.yami.trading.security.common.manager.TokenStore;
import com.yami.trading.security.common.util.SecurityUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
 
import javax.servlet.http.HttpServletRequest;
 
/**
 * @author 菠萝凤梨
 * @date 2022/3/25 17:33
 */
@RestController
@Api(tags = "注销")
public class LogoutController {
 
    @Autowired
    private TokenStore tokenStore;
 
    @PostMapping("/logOut")
    @ApiOperation(value = "退出登陆", notes = "点击退出登陆,清除token,清除菜单缓存")
    public ResponseEntity<Void> logOut(HttpServletRequest request) {
        String accessToken = request.getHeader("Authorization");
        String token = request.getHeader("token");
        if (StrUtil.isBlank(token)) {
            accessToken=token;
        }
        if (StrUtil.isBlank(accessToken)) {
            return ResponseEntity.ok().build();
        }
        // 删除该用户在该系统当前的token
        tokenStore.deleteAllToken(String.valueOf(SysTypeEnum.ORDINARY.value()), String.valueOf(SecurityUtils.getSysUser().getUserId()));
        return ResponseEntity.ok().build();
    }
}