|
|
@@ -14,11 +14,13 @@ import cn.iocoder.byzs.module.system.controller.admin.auth.vo.AuthSmsLoginReqVO;
|
|
|
import cn.iocoder.byzs.module.system.controller.admin.auth.vo.AuthSmsSendReqVO;
|
|
|
import cn.iocoder.byzs.module.system.dal.dataobject.permission.RoleDO;
|
|
|
import cn.iocoder.byzs.module.system.dal.dataobject.tenant.TenantDO;
|
|
|
+import cn.iocoder.byzs.module.system.dal.dataobject.user.AdminUserDO;
|
|
|
import cn.iocoder.byzs.module.system.enums.logger.LoginLogTypeEnum;
|
|
|
import cn.iocoder.byzs.module.system.service.auth.AdminAuthService;
|
|
|
import cn.iocoder.byzs.module.system.service.permission.PermissionService;
|
|
|
import cn.iocoder.byzs.module.system.service.permission.RoleService;
|
|
|
import cn.iocoder.byzs.module.system.service.tenant.TenantService;
|
|
|
+import cn.iocoder.byzs.module.system.service.user.AdminUserService;
|
|
|
import cn.iocoder.byzs.module.web.controller.admin.login.vo.WebLoginVO;
|
|
|
import cn.iocoder.byzs.module.web.controller.admin.login.vo.WebRegisterVO;
|
|
|
import cn.iocoder.byzs.module.web.service.login.WebLoginServiceImpl;
|
|
|
@@ -53,6 +55,8 @@ public class WebLoginController {
|
|
|
@Resource
|
|
|
private RoleService roleService;
|
|
|
@Resource
|
|
|
+ private AdminUserService adminUserService;
|
|
|
+ @Resource
|
|
|
private WebLoginServiceImpl webLoginServiceImpl;
|
|
|
|
|
|
|
|
|
@@ -76,20 +80,23 @@ public class WebLoginController {
|
|
|
|
|
|
@PostMapping("/login")
|
|
|
@PermitAll
|
|
|
+ @TenantIgnore
|
|
|
@Operation(summary = "使用账号密码登录")
|
|
|
public CommonResult<WebLoginVO> login(@RequestBody @Valid AuthLoginReqVO reqVO) {
|
|
|
- return success(setAuthRoleVO(authService.login(reqVO)));
|
|
|
+ return success(buildWebLoginVO(authService.login(reqVO)));
|
|
|
}
|
|
|
|
|
|
@PostMapping("/sms-login")
|
|
|
@PermitAll
|
|
|
+ @TenantIgnore
|
|
|
@Operation(summary = "使用短信验证码登录")
|
|
|
public CommonResult<WebLoginVO> smsLogin(@RequestBody @Valid AuthSmsLoginReqVO reqVO) {
|
|
|
- return success(setAuthRoleVO(authService.smsLogin(reqVO)));
|
|
|
+ return success(buildWebLoginVO(authService.smsLogin(reqVO)));
|
|
|
}
|
|
|
|
|
|
@PostMapping("/send-sms-code")
|
|
|
@PermitAll
|
|
|
+ @TenantIgnore
|
|
|
@Operation(summary = "发送手机验证码")
|
|
|
public CommonResult<Boolean> sendLoginSmsCode(@RequestBody @Valid AuthSmsSendReqVO reqVO) {
|
|
|
authService.sendSmsCode(reqVO);
|
|
|
@@ -115,43 +122,25 @@ public class WebLoginController {
|
|
|
return success(roleRouteSet);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 填充课程数据权限
|
|
|
- * @param login
|
|
|
- * @return
|
|
|
- */
|
|
|
- private WebLoginVO setAuthRoleVO(AuthLoginRespVO login) {
|
|
|
+ // 填充租户
|
|
|
+ private WebLoginVO buildWebLoginVO(AuthLoginRespVO login) {
|
|
|
+ // 转换为 WebLoginVO
|
|
|
WebLoginVO webLoginVO = BeanUtils.toBean(login, WebLoginVO.class);
|
|
|
|
|
|
- // 已经在后台读取,这里无需重复读取
|
|
|
- if (true) {
|
|
|
- return webLoginVO;
|
|
|
+ // 确保租户ID存在
|
|
|
+ if (webLoginVO.getTenantId() == null) {
|
|
|
+ AdminUserDO user = adminUserService.getUser(webLoginVO.getUserId());
|
|
|
+ if (user != null) {
|
|
|
+ webLoginVO.setTenantId(user.getTenantId());
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- // 获得角色列表
|
|
|
- Set<Long> roleIds = permissionService.getUserRoleIdListByUserId(login.getUserId());
|
|
|
- List<RoleDO> roles = roleService.getRoleList(roleIds);
|
|
|
- roles.removeIf(role -> !CommonStatusEnum.ENABLE.getStatus().equals(role.getStatus())); // 移除禁用的角色
|
|
|
-
|
|
|
- // 将所有角色的dataScopeCourseIds拼接成一个Set集合
|
|
|
- Set<Long> allDataScopeCourseIds = new HashSet<>();
|
|
|
- Set<Long> allDataScopeBlocklyIds = new HashSet<>();
|
|
|
- for (RoleDO role : roles) {
|
|
|
- // 填充课程数据权限
|
|
|
- Set<Long> dataScopeCourseIds = role.getDataScopeCourseIds();
|
|
|
- if (dataScopeCourseIds != null && !dataScopeCourseIds.isEmpty()) {
|
|
|
- allDataScopeCourseIds.addAll(dataScopeCourseIds);
|
|
|
- }
|
|
|
- //blocklu课程数据权限
|
|
|
- Set<Long> dataScopeBlocklyIds = role.getDataScopeBlocklyIds();
|
|
|
- if (dataScopeBlocklyIds != null && !dataScopeBlocklyIds.isEmpty()) {
|
|
|
- allDataScopeBlocklyIds.addAll(dataScopeBlocklyIds);
|
|
|
- }
|
|
|
+ // 填充租户名称
|
|
|
+ TenantDO tenant = tenantService.getTenant(webLoginVO.getTenantId());
|
|
|
+ if (tenant != null) {
|
|
|
+ webLoginVO.setTenantName(tenant.getName());
|
|
|
}
|
|
|
|
|
|
- //填充课程数据权限
|
|
|
- webLoginVO.setCourseDataScope(allDataScopeCourseIds);
|
|
|
- webLoginVO.setBlocklyDataScope(allDataScopeBlocklyIds);
|
|
|
return webLoginVO;
|
|
|
}
|
|
|
-}
|
|
|
+}
|