Commit abfbe1ea83570a00106dedebb283dc8b065ac929
1 parent
4a9e9961
feat:【SYSTEM】通过系统配置管理来设置系统是否可注册用户
Showing
2 changed files
with
10 additions
and
2 deletions
yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java
| ... | ... | @@ -45,6 +45,7 @@ public interface ErrorCodeConstants { |
| 45 | 45 | ErrorCode USER_COUNT_MAX = new ErrorCode(1_002_003_008, "创建用户失败,原因:超过租户最大租户配额({})!"); |
| 46 | 46 | ErrorCode USER_IMPORT_INIT_PASSWORD = new ErrorCode(1_002_003_009, "初始密码不能为空"); |
| 47 | 47 | ErrorCode USER_MOBILE_NOT_EXISTS = new ErrorCode(1_002_003_010, "该手机号尚未注册"); |
| 48 | + ErrorCode USER_REGISTER_DISABLED = new ErrorCode(1_002_003_011, "注册功能已关闭"); | |
| 48 | 49 | |
| 49 | 50 | // ========== 部门模块 1-002-004-000 ========== |
| 50 | 51 | ErrorCode DEPT_NAME_DUPLICATE = new ErrorCode(1_002_004_000, "已经存在该名字的部门"); | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/user/AdminUserServiceImpl.java
| ... | ... | @@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.system.service.user; |
| 3 | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | 4 | import cn.hutool.core.collection.CollectionUtil; |
| 5 | 5 | import cn.hutool.core.io.IoUtil; |
| 6 | +import cn.hutool.core.util.ObjUtil; | |
| 6 | 7 | import cn.hutool.core.util.StrUtil; |
| 7 | 8 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 8 | 9 | import cn.iocoder.yudao.framework.common.exception.ServiceException; |
| ... | ... | @@ -61,6 +62,8 @@ public class AdminUserServiceImpl implements AdminUserService { |
| 61 | 62 | |
| 62 | 63 | static final String USER_INIT_PASSWORD_KEY = "system.user.init-password"; |
| 63 | 64 | |
| 65 | + static final String USER_REGISTER_ENABLED_KEY = "system.user.register-enabled"; | |
| 66 | + | |
| 64 | 67 | @Resource |
| 65 | 68 | private AdminUserMapper userMapper; |
| 66 | 69 | |
| ... | ... | @@ -117,14 +120,18 @@ public class AdminUserServiceImpl implements AdminUserService { |
| 117 | 120 | |
| 118 | 121 | @Override |
| 119 | 122 | public Long registerUser(AuthRegisterReqVO registerReqVO) { |
| 120 | - // 1.1 校验账户配合 | |
| 123 | + // 1.1 校验是否开启注册 | |
| 124 | + if (ObjUtil.notEqual(configApi.getConfigValueByKey(USER_REGISTER_ENABLED_KEY), "true")) { | |
| 125 | + throw exception(USER_REGISTER_DISABLED); | |
| 126 | + } | |
| 127 | + // 1.2 校验账户配合 | |
| 121 | 128 | tenantService.handleTenantInfo(tenant -> { |
| 122 | 129 | long count = userMapper.selectCount(); |
| 123 | 130 | if (count >= tenant.getAccountCount()) { |
| 124 | 131 | throw exception(USER_COUNT_MAX, tenant.getAccountCount()); |
| 125 | 132 | } |
| 126 | 133 | }); |
| 127 | - // 1.2 校验正确性 | |
| 134 | + // 1.3 校验正确性 | |
| 128 | 135 | validateUserForCreateOrUpdate(null, registerReqVO.getUsername(), null, null, null, null); |
| 129 | 136 | |
| 130 | 137 | // 2. 插入用户 | ... | ... |