Эх сурвалжийг харах

退出登录
获取登录用户信息

Gaokun Wang 1 сар өмнө
parent
commit
f67dc525e8

+ 13 - 24
eco-nexus-core/auth-biz/src/main/java/org/eco/vip/auth/controller/auth/AuthController.java

@@ -6,27 +6,27 @@
 package org.eco.vip.auth.controller.auth;
 
 
+import cn.dev33.satoken.stp.StpUtil;
 import jakarta.annotation.Resource;
 import lombok.extern.slf4j.Slf4j;
 import org.eco.vip.auth.domain.auth.pojo.AuthQuery;
 import org.eco.vip.auth.domain.auth.pojo.AuthVO;
-import org.eco.vip.auth.domain.auth.pojo.LoginUserVO;
 import org.eco.vip.auth.domain.client.pojo.ClientVO;
-import org.eco.vip.auth.domain.user.pojo.UserVO;
 import org.eco.vip.auth.service.auth.IAuthService;
 import org.eco.vip.auth.service.client.IClientService;
-import org.eco.vip.auth.service.user.IUserService;
 import org.eco.vip.orm.constant.Constants;
 import org.eco.vip.orm.exception.BusinessException;
 import org.eco.vip.orm.pojo.CommonResult;
-import org.eco.vip.orm.pojo.LoginUser;
 import org.eco.vip.orm.utils.JsonUtils;
 import org.eco.vip.orm.utils.ObjUtils;
 import org.eco.vip.orm.utils.StrUtils;
 import org.eco.vip.orm.utils.ValidatorUtils;
-import org.eco.vip.security.utils.LoginHelper;
 import org.springframework.validation.annotation.Validated;
-import org.springframework.web.bind.annotation.*;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
 
 import static org.eco.vip.orm.pojo.CommonResult.fail;
 import static org.eco.vip.orm.pojo.CommonResult.success;
@@ -49,9 +49,6 @@ public class AuthController {
     @Resource
     private IClientService clientService;
 
-    @Resource
-    private IUserService userService;
-
     @PostMapping("/login")
     public CommonResult<AuthVO> login(@RequestBody String body) {
         AuthQuery authQueryBody = JsonUtils.parseObject(body, AuthQuery.class);
@@ -72,20 +69,12 @@ public class AuthController {
         return success(adminAuthService.login(authQueryBody, clientVO, grantType));
     }
 
-    @GetMapping("/info")
-    public CommonResult<LoginUserVO> getInfo() {
-        LoginUserVO loginUserVO = new LoginUserVO();
-        LoginUser loginUser = LoginHelper.getLoginUser();
-        if (ObjUtils.isNull(loginUser)) {
-            return fail("用户无权限!");
-        }
-        UserVO userVO = userService.selectById(loginUser.getUserId());
-        if (ObjUtils.isNull(userVO)) {
-            return fail("用户无权限!");
-        }
-        loginUserVO.setUser(userVO);
-        loginUserVO.setPermissionCodes(loginUser.getPermissionCodes());
-        loginUserVO.setRoleCodes(loginUser.getRoleCodes());
-        return success(loginUserVO);
+    @GetMapping("/logout")
+    public CommonResult<Void> logout() {
+        // 清除缓存session
+        StpUtil.getTokenSession().logout();
+        // 退出登录
+        StpUtil.logout();
+        return success();
     }
 }

+ 21 - 3
eco-nexus-core/auth-biz/src/main/java/org/eco/vip/auth/controller/user/UserController.java

@@ -9,15 +9,22 @@ package org.eco.vip.auth.controller.user;
 import jakarta.annotation.Resource;
 import jakarta.validation.Valid;
 import jakarta.validation.constraints.NotEmpty;
+import org.eco.vip.auth.domain.auth.pojo.LoginUserVO;
 import org.eco.vip.auth.domain.user.pojo.UserBO;
 import org.eco.vip.auth.domain.user.pojo.UserVO;
 import org.eco.vip.auth.service.user.IUserService;
 import org.eco.vip.orm.pojo.CommonResult;
 import org.eco.vip.orm.pojo.LoginUser;
 import org.eco.vip.orm.pojo.PageResult;
+import org.eco.vip.orm.utils.ObjUtils;
 import org.eco.vip.security.utils.LoginHelper;
 import org.springframework.validation.annotation.Validated;
-import org.springframework.web.bind.annotation.*;
+import org.springframework.web.bind.annotation.DeleteMapping;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
 
 import java.util.List;
 
@@ -72,8 +79,19 @@ public class UserController {
     }
 
     @GetMapping("/info")
-    public CommonResult<LoginUser> getInfo() {
+    public CommonResult<LoginUserVO> getInfo() {
+        LoginUserVO loginUserVO = new LoginUserVO();
         LoginUser loginUser = LoginHelper.getLoginUser();
-        return success(loginUser);
+        if (ObjUtils.isNull(loginUser)) {
+            return fail("用户无权限!");
+        }
+        UserVO userVO = userService.selectById(loginUser.getUserId());
+        if (ObjUtils.isNull(userVO)) {
+            return fail("用户无权限!");
+        }
+        loginUserVO.setUser(userVO);
+        loginUserVO.setPermissionCodes(loginUser.getPermissionCodes());
+        loginUserVO.setRoleCodes(loginUser.getRoleCodes());
+        return success(loginUserVO);
     }
 }