|
@@ -1,13 +1,13 @@
|
|
|
-package cn.iocoder.yudao.module.system.controller.auth;
|
|
|
+package cn.iocoder.yudao.module.system.controller.admin.auth;
|
|
|
|
|
|
-import cn.iocoder.yudao.module.system.controller.auth.vo.auth.*;
|
|
|
-import cn.iocoder.yudao.module.system.convert.auth.SysAuthConvert;
|
|
|
-import cn.iocoder.yudao.module.system.dal.dataobject.permission.SysMenuDO;
|
|
|
+import cn.iocoder.yudao.module.system.controller.admin.auth.vo.auth.*;
|
|
|
+import cn.iocoder.yudao.module.system.convert.auth.AuthConvert;
|
|
|
+import cn.iocoder.yudao.module.system.dal.dataobject.permission.MenuDO;
|
|
|
import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.permission.SysRoleDO;
|
|
|
import cn.iocoder.yudao.module.system.enums.permission.MenuTypeEnum;
|
|
|
-import cn.iocoder.yudao.module.system.service.auth.SysAuthService;
|
|
|
-import cn.iocoder.yudao.module.system.service.permission.SysPermissionService;
|
|
|
-import cn.iocoder.yudao.module.system.service.permission.SysRoleService;
|
|
|
+import cn.iocoder.yudao.module.system.service.auth.AuthService;
|
|
|
+import cn.iocoder.yudao.module.system.service.permission.PermissionService;
|
|
|
+import cn.iocoder.yudao.module.system.service.permission.RoleService;
|
|
|
import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.user.SysUserDO;
|
|
|
import cn.iocoder.yudao.coreservice.modules.system.service.social.SysSocialCoreService;
|
|
|
import cn.iocoder.yudao.coreservice.modules.system.service.user.SysUserCoreService;
|
|
@@ -21,6 +21,7 @@ import io.swagger.annotations.ApiImplicitParam;
|
|
|
import io.swagger.annotations.ApiImplicitParams;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
@@ -34,36 +35,37 @@ import static cn.iocoder.yudao.framework.common.util.servlet.ServletUtils.getUse
|
|
|
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
|
|
|
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserRoleIds;
|
|
|
|
|
|
-@Api(tags = "认证")
|
|
|
+@Api(tags = "管理后台 - 认证")
|
|
|
@RestController
|
|
|
-@RequestMapping("/")
|
|
|
+@RequestMapping("/system") // 暂时不跟 /auth 结尾
|
|
|
@Validated
|
|
|
@Slf4j
|
|
|
-public class SysAuthController {
|
|
|
+public class AuthController {
|
|
|
|
|
|
- @Resource
|
|
|
- private SysAuthService authService;
|
|
|
+ @Autowired
|
|
|
+ @SuppressWarnings("SpringJavaAutowiredFieldsWarningInspection") // AuthService 存在重名
|
|
|
+ private AuthService authService;
|
|
|
@Resource
|
|
|
private SysUserCoreService userCoreService;
|
|
|
@Resource
|
|
|
- private SysRoleService roleService;
|
|
|
+ private RoleService roleService;
|
|
|
@Resource
|
|
|
- private SysPermissionService permissionService;
|
|
|
+ private PermissionService permissionService;
|
|
|
@Resource
|
|
|
private SysSocialCoreService socialCoreService;
|
|
|
|
|
|
@PostMapping("/login")
|
|
|
@ApiOperation("使用账号密码登录")
|
|
|
@OperateLog(enable = false) // 避免 Post 请求被记录操作日志
|
|
|
- public CommonResult<SysAuthLoginRespVO> login(@RequestBody @Valid SysAuthLoginReqVO reqVO) {
|
|
|
+ public CommonResult<AuthLoginRespVO> login(@RequestBody @Valid AuthLoginReqVO reqVO) {
|
|
|
String token = authService.login(reqVO, getClientIP(), getUserAgent());
|
|
|
// 返回结果
|
|
|
- return success(SysAuthLoginRespVO.builder().token(token).build());
|
|
|
+ return success(AuthLoginRespVO.builder().token(token).build());
|
|
|
}
|
|
|
|
|
|
@GetMapping("/get-permission-info")
|
|
|
@ApiOperation("获取登录用户的权限信息")
|
|
|
- public CommonResult<SysAuthPermissionInfoRespVO> getPermissionInfo() {
|
|
|
+ public CommonResult<AuthPermissionInfoRespVO> getPermissionInfo() {
|
|
|
// 获得用户信息
|
|
|
SysUserDO user = userCoreService.getUser(getLoginUserId());
|
|
|
if (user == null) {
|
|
@@ -72,24 +74,24 @@ public class SysAuthController {
|
|
|
// 获得角色列表
|
|
|
List<SysRoleDO> roleList = roleService.getRolesFromCache(getLoginUserRoleIds());
|
|
|
// 获得菜单列表
|
|
|
- List<SysMenuDO> menuList = permissionService.getRoleMenusFromCache(
|
|
|
+ List<MenuDO> menuList = permissionService.getRoleMenusFromCache(
|
|
|
getLoginUserRoleIds(), // 注意,基于登录的角色,因为后续的权限判断也是基于它
|
|
|
SetUtils.asSet(MenuTypeEnum.DIR.getType(), MenuTypeEnum.MENU.getType(), MenuTypeEnum.BUTTON.getType()),
|
|
|
SetUtils.asSet(CommonStatusEnum.ENABLE.getStatus()));
|
|
|
// 拼接结果返回
|
|
|
- return success(SysAuthConvert.INSTANCE.convert(user, roleList, menuList));
|
|
|
+ return success(AuthConvert.INSTANCE.convert(user, roleList, menuList));
|
|
|
}
|
|
|
|
|
|
@GetMapping("list-menus")
|
|
|
@ApiOperation("获得登录用户的菜单列表")
|
|
|
- public CommonResult<List<SysAuthMenuRespVO>> getMenus() {
|
|
|
+ public CommonResult<List<AuthMenuRespVO>> getMenus() {
|
|
|
// 获得用户拥有的菜单列表
|
|
|
- List<SysMenuDO> menuList = permissionService.getRoleMenusFromCache(
|
|
|
+ List<MenuDO> menuList = permissionService.getRoleMenusFromCache(
|
|
|
getLoginUserRoleIds(), // 注意,基于登录的角色,因为后续的权限判断也是基于它
|
|
|
SetUtils.asSet(MenuTypeEnum.DIR.getType(), MenuTypeEnum.MENU.getType()), // 只要目录和菜单类型
|
|
|
SetUtils.asSet(CommonStatusEnum.ENABLE.getStatus())); // 只要开启的
|
|
|
// 转换成 Tree 结构返回
|
|
|
- return success(SysAuthConvert.INSTANCE.buildMenuTree(menuList));
|
|
|
+ return success(AuthConvert.INSTANCE.buildMenuTree(menuList));
|
|
|
}
|
|
|
|
|
|
// ========== 社交登录相关 ==========
|
|
@@ -108,31 +110,31 @@ public class SysAuthController {
|
|
|
@PostMapping("/social-login")
|
|
|
@ApiOperation("社交登录,使用 code 授权码")
|
|
|
@OperateLog(enable = false) // 避免 Post 请求被记录操作日志
|
|
|
- public CommonResult<SysAuthLoginRespVO> socialLogin(@RequestBody @Valid SysAuthSocialLoginReqVO reqVO) {
|
|
|
+ public CommonResult<AuthLoginRespVO> socialLogin(@RequestBody @Valid AuthSocialLoginReqVO reqVO) {
|
|
|
String token = authService.socialLogin(reqVO, getClientIP(), getUserAgent());
|
|
|
// 返回结果
|
|
|
- return success(SysAuthLoginRespVO.builder().token(token).build());
|
|
|
+ return success(AuthLoginRespVO.builder().token(token).build());
|
|
|
}
|
|
|
|
|
|
@PostMapping("/social-login2")
|
|
|
@ApiOperation("社交登录,使用 code 授权码 + 账号密码")
|
|
|
@OperateLog(enable = false) // 避免 Post 请求被记录操作日志
|
|
|
- public CommonResult<SysAuthLoginRespVO> socialLogin2(@RequestBody @Valid SysAuthSocialLogin2ReqVO reqVO) {
|
|
|
+ public CommonResult<AuthLoginRespVO> socialLogin2(@RequestBody @Valid AuthSocialLogin2ReqVO reqVO) {
|
|
|
String token = authService.socialLogin2(reqVO, getClientIP(), getUserAgent());
|
|
|
// 返回结果
|
|
|
- return success(SysAuthLoginRespVO.builder().token(token).build());
|
|
|
+ return success(AuthLoginRespVO.builder().token(token).build());
|
|
|
}
|
|
|
|
|
|
@PostMapping("/social-bind")
|
|
|
@ApiOperation("社交绑定,使用 code 授权码")
|
|
|
- public CommonResult<Boolean> socialBind(@RequestBody @Valid SysAuthSocialBindReqVO reqVO) {
|
|
|
+ public CommonResult<Boolean> socialBind(@RequestBody @Valid AuthSocialBindReqVO reqVO) {
|
|
|
authService.socialBind(getLoginUserId(), reqVO);
|
|
|
return CommonResult.success(true);
|
|
|
}
|
|
|
|
|
|
@DeleteMapping("/social-unbind")
|
|
|
@ApiOperation("取消社交绑定")
|
|
|
- public CommonResult<Boolean> socialUnbind(@RequestBody SysAuthSocialUnbindReqVO reqVO) {
|
|
|
+ public CommonResult<Boolean> socialUnbind(@RequestBody AuthSocialUnbindReqVO reqVO) {
|
|
|
socialCoreService.unbindSocialUser(getLoginUserId(), reqVO.getType(), reqVO.getUnionId(), UserTypeEnum.ADMIN);
|
|
|
return CommonResult.success(true);
|
|
|
}
|