Commit 928b7dbe23338127834ae6023d2a5ae32a16308e
1 parent
06fa85a3
多模块重构 2:在 yudao-admin-server 中,引入 yudao-module-member 模块
Showing
58 changed files
with
607 additions
and
445 deletions
yudao-admin-server/pom.xml
| @@ -17,6 +17,13 @@ | @@ -17,6 +17,13 @@ | ||
| 17 | <url>https://github.com/YunaiV/ruoyi-vue-pro</url> | 17 | <url>https://github.com/YunaiV/ruoyi-vue-pro</url> |
| 18 | 18 | ||
| 19 | <dependencies> | 19 | <dependencies> |
| 20 | + <!-- TODO 芋艿:多模块 --> | ||
| 21 | + <dependency> | ||
| 22 | + <groupId>cn.iocoder.boot</groupId> | ||
| 23 | + <artifactId>yudao-module-member-impl</artifactId> | ||
| 24 | + <version>${revision}</version> | ||
| 25 | + </dependency> | ||
| 26 | + | ||
| 20 | <!-- 业务组件 --> | 27 | <!-- 业务组件 --> |
| 21 | <dependency> | 28 | <dependency> |
| 22 | <groupId>cn.iocoder.boot</groupId> | 29 | <groupId>cn.iocoder.boot</groupId> |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/AdminServerApplication.java
| @@ -4,7 +4,8 @@ import org.springframework.boot.SpringApplication; | @@ -4,7 +4,8 @@ import org.springframework.boot.SpringApplication; | ||
| 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; | 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; |
| 5 | 5 | ||
| 6 | @SuppressWarnings("SpringComponentScan") // 忽略 IDEA 无法识别 ${yudao.info.base-package} 和 ${yudao.core-service.base-package} | 6 | @SuppressWarnings("SpringComponentScan") // 忽略 IDEA 无法识别 ${yudao.info.base-package} 和 ${yudao.core-service.base-package} |
| 7 | -@SpringBootApplication(scanBasePackages = {"${yudao.info.base-package}", "${yudao.core-service.base-package}"}) | 7 | +@SpringBootApplication(scanBasePackages = {"${yudao.info.base-package}", "${yudao.core-service.base-package}", |
| 8 | + "${yudao.info.member-package}"}) // TODO 芋艿:重构 | ||
| 8 | public class AdminServerApplication { | 9 | public class AdminServerApplication { |
| 9 | 10 | ||
| 10 | public static void main(String[] args) { | 11 | public static void main(String[] args) { |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/framework/security/SecurityConfiguration.java
| @@ -23,19 +23,28 @@ public class SecurityConfiguration { | @@ -23,19 +23,28 @@ public class SecurityConfiguration { | ||
| 23 | public Customizer<ExpressionUrlAuthorizationConfigurer<HttpSecurity>.ExpressionInterceptUrlRegistry> authorizeRequestsCustomizer() { | 23 | public Customizer<ExpressionUrlAuthorizationConfigurer<HttpSecurity>.ExpressionInterceptUrlRegistry> authorizeRequestsCustomizer() { |
| 24 | return registry -> { | 24 | return registry -> { |
| 25 | // 验证码的接口 | 25 | // 验证码的接口 |
| 26 | - registry.antMatchers(api("/system/captcha/**")).anonymous(); | 26 | + registry.antMatchers(buildAdminApi("/system/captcha/**")).anonymous(); |
| 27 | // 获得租户编号的接口 | 27 | // 获得租户编号的接口 |
| 28 | - registry.antMatchers(api("/system/tenant/get-id-by-name")).anonymous(); | 28 | + registry.antMatchers(buildAdminApi("/system/tenant/get-id-by-name")).anonymous(); |
| 29 | // Spring Boot Admin Server 的安全配置 | 29 | // Spring Boot Admin Server 的安全配置 |
| 30 | registry.antMatchers(adminSeverContextPath).anonymous() | 30 | registry.antMatchers(adminSeverContextPath).anonymous() |
| 31 | .antMatchers(adminSeverContextPath + "/**").anonymous(); | 31 | .antMatchers(adminSeverContextPath + "/**").anonymous(); |
| 32 | // 短信回调 API | 32 | // 短信回调 API |
| 33 | - registry.antMatchers(api("/system/sms/callback/**")).anonymous(); | 33 | + registry.antMatchers(buildAdminApi("/system/sms/callback/**")).anonymous(); |
| 34 | + | ||
| 35 | + // 设置 App API 无需认证 | ||
| 36 | + registry.antMatchers(buildAppApi("/**")); | ||
| 34 | }; | 37 | }; |
| 35 | } | 38 | } |
| 36 | 39 | ||
| 37 | - private String api(String url) { | ||
| 38 | - return webProperties.getApiPrefix() + url; | 40 | + private String buildAdminApi(String url) { |
| 41 | + // TODO 芋艿:多模块 | ||
| 42 | + return webProperties.getAdminApi().getPrefix() + url; | ||
| 43 | + } | ||
| 44 | + | ||
| 45 | + private String buildAppApi(String url) { | ||
| 46 | + // TODO 芋艿:多模块 | ||
| 47 | + return webProperties.getAppApi().getPrefix() + url; | ||
| 39 | } | 48 | } |
| 40 | 49 | ||
| 41 | } | 50 | } |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/framework/activiti/config/BpmActivitiConfiguration.java
| @@ -11,10 +11,12 @@ import cn.iocoder.yudao.adminserver.modules.system.service.dept.SysDeptService; | @@ -11,10 +11,12 @@ import cn.iocoder.yudao.adminserver.modules.system.service.dept.SysDeptService; | ||
| 11 | import cn.iocoder.yudao.adminserver.modules.system.service.permission.SysPermissionService; | 11 | import cn.iocoder.yudao.adminserver.modules.system.service.permission.SysPermissionService; |
| 12 | import cn.iocoder.yudao.adminserver.modules.system.service.user.SysUserService; | 12 | import cn.iocoder.yudao.adminserver.modules.system.service.user.SysUserService; |
| 13 | import org.activiti.api.runtime.shared.identity.UserGroupManager; | 13 | import org.activiti.api.runtime.shared.identity.UserGroupManager; |
| 14 | +import org.activiti.core.common.spring.identity.ActivitiUserGroupManagerImpl; | ||
| 14 | import org.activiti.spring.boot.ProcessEngineConfigurationConfigurer; | 15 | import org.activiti.spring.boot.ProcessEngineConfigurationConfigurer; |
| 15 | import org.springframework.context.ApplicationEventPublisher; | 16 | import org.springframework.context.ApplicationEventPublisher; |
| 16 | import org.springframework.context.annotation.Bean; | 17 | import org.springframework.context.annotation.Bean; |
| 17 | import org.springframework.context.annotation.Configuration; | 18 | import org.springframework.context.annotation.Configuration; |
| 19 | +import org.springframework.security.core.userdetails.UserDetailsService; | ||
| 18 | 20 | ||
| 19 | import java.util.Collections; | 21 | import java.util.Collections; |
| 20 | import java.util.List; | 22 | import java.util.List; |
| @@ -28,7 +30,15 @@ import static org.activiti.spring.boot.ProcessEngineAutoConfiguration.BEHAVIOR_F | @@ -28,7 +30,15 @@ import static org.activiti.spring.boot.ProcessEngineAutoConfiguration.BEHAVIOR_F | ||
| 28 | public class BpmActivitiConfiguration { | 30 | public class BpmActivitiConfiguration { |
| 29 | 31 | ||
| 30 | /** | 32 | /** |
| 31 | - * BPM 模块的 ProcessEngineConfigurationConfigurer 实现类,主要设置各种监听器、用户组管理 | 33 | + * 空用户组的 Bean |
| 34 | + */ | ||
| 35 | + @Bean | ||
| 36 | + public UserGroupManager userGroupManager() { | ||
| 37 | + return new EmptyUserGroupManager(); | ||
| 38 | + } | ||
| 39 | + | ||
| 40 | + /** | ||
| 41 | + * BPM 模块的 ProcessEngineConfigurationConfigurer 实现类,主要设置各种监听器 | ||
| 32 | */ | 42 | */ |
| 33 | @Bean | 43 | @Bean |
| 34 | public ProcessEngineConfigurationConfigurer bpmProcessEngineConfigurationConfigurer( | 44 | public ProcessEngineConfigurationConfigurer bpmProcessEngineConfigurationConfigurer( |
| @@ -36,8 +46,6 @@ public class BpmActivitiConfiguration { | @@ -36,8 +46,6 @@ public class BpmActivitiConfiguration { | ||
| 36 | return configuration -> { | 46 | return configuration -> { |
| 37 | // 注册监听器,例如说 BpmActivitiEventListener | 47 | // 注册监听器,例如说 BpmActivitiEventListener |
| 38 | configuration.setEventListeners(Collections.singletonList(taskActivitiEventListener)); | 48 | configuration.setEventListeners(Collections.singletonList(taskActivitiEventListener)); |
| 39 | - // 用户组 | ||
| 40 | - configuration.setUserGroupManager(new EmptyUserGroupManager()); | ||
| 41 | }; | 49 | }; |
| 42 | } | 50 | } |
| 43 | 51 |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/auth/impl/SysAuthServiceImpl.java
| @@ -60,8 +60,6 @@ import static java.util.Collections.singleton; | @@ -60,8 +60,6 @@ import static java.util.Collections.singleton; | ||
| 60 | @Slf4j | 60 | @Slf4j |
| 61 | public class SysAuthServiceImpl implements SysAuthService { | 61 | public class SysAuthServiceImpl implements SysAuthService { |
| 62 | 62 | ||
| 63 | - private static final UserTypeEnum USER_TYPE_ENUM = UserTypeEnum.ADMIN; | ||
| 64 | - | ||
| 65 | @Resource | 63 | @Resource |
| 66 | @Lazy // 延迟加载,因为存在相互依赖的问题 | 64 | @Lazy // 延迟加载,因为存在相互依赖的问题 |
| 67 | private AuthenticationManager authenticationManager; | 65 | private AuthenticationManager authenticationManager; |
| @@ -83,7 +81,6 @@ public class SysAuthServiceImpl implements SysAuthService { | @@ -83,7 +81,6 @@ public class SysAuthServiceImpl implements SysAuthService { | ||
| 83 | @Resource | 81 | @Resource |
| 84 | private SysSocialCoreService socialService; | 82 | private SysSocialCoreService socialService; |
| 85 | 83 | ||
| 86 | - | ||
| 87 | @Override | 84 | @Override |
| 88 | public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { | 85 | public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { |
| 89 | // 获取 username 对应的 SysUserDO | 86 | // 获取 username 对应的 SysUserDO |
| @@ -216,7 +213,7 @@ public class SysAuthServiceImpl implements SysAuthService { | @@ -216,7 +213,7 @@ public class SysAuthServiceImpl implements SysAuthService { | ||
| 216 | 213 | ||
| 217 | // 如果未绑定 SysSocialUserDO 用户,则无法自动登录,进行报错 | 214 | // 如果未绑定 SysSocialUserDO 用户,则无法自动登录,进行报错 |
| 218 | String unionId = socialService.getAuthUserUnionId(authUser); | 215 | String unionId = socialService.getAuthUserUnionId(authUser); |
| 219 | - List<SysSocialUserDO> socialUsers = socialService.getAllSocialUserList(reqVO.getType(), unionId, USER_TYPE_ENUM); | 216 | + List<SysSocialUserDO> socialUsers = socialService.getAllSocialUserList(reqVO.getType(), unionId, getUserType()); |
| 220 | if (CollUtil.isEmpty(socialUsers)) { | 217 | if (CollUtil.isEmpty(socialUsers)) { |
| 221 | throw exception(AUTH_THIRD_LOGIN_NOT_BIND); | 218 | throw exception(AUTH_THIRD_LOGIN_NOT_BIND); |
| 222 | } | 219 | } |
| @@ -232,7 +229,7 @@ public class SysAuthServiceImpl implements SysAuthService { | @@ -232,7 +229,7 @@ public class SysAuthServiceImpl implements SysAuthService { | ||
| 232 | LoginUser loginUser = this.buildLoginUser(user); | 229 | LoginUser loginUser = this.buildLoginUser(user); |
| 233 | 230 | ||
| 234 | // 绑定社交用户(更新) | 231 | // 绑定社交用户(更新) |
| 235 | - socialService.bindSocialUser(loginUser.getId(), reqVO.getType(), authUser, USER_TYPE_ENUM); | 232 | + socialService.bindSocialUser(loginUser.getId(), reqVO.getType(), authUser, getUserType()); |
| 236 | 233 | ||
| 237 | // 缓存登录用户到 Redis 中,返回 sessionId 编号 | 234 | // 缓存登录用户到 Redis 中,返回 sessionId 编号 |
| 238 | return userSessionCoreService.createUserSession(loginUser, userIp, userAgent); | 235 | return userSessionCoreService.createUserSession(loginUser, userIp, userAgent); |
| @@ -248,7 +245,7 @@ public class SysAuthServiceImpl implements SysAuthService { | @@ -248,7 +245,7 @@ public class SysAuthServiceImpl implements SysAuthService { | ||
| 248 | LoginUser loginUser = this.login0(reqVO.getUsername(), reqVO.getPassword()); | 245 | LoginUser loginUser = this.login0(reqVO.getUsername(), reqVO.getPassword()); |
| 249 | 246 | ||
| 250 | // 绑定社交用户(新增) | 247 | // 绑定社交用户(新增) |
| 251 | - socialService.bindSocialUser(loginUser.getId(), reqVO.getType(), authUser, USER_TYPE_ENUM); | 248 | + socialService.bindSocialUser(loginUser.getId(), reqVO.getType(), authUser, getUserType()); |
| 252 | 249 | ||
| 253 | // 缓存登录用户到 Redis 中,返回 sessionId 编号 | 250 | // 缓存登录用户到 Redis 中,返回 sessionId 编号 |
| 254 | return userSessionCoreService.createUserSession(loginUser, userIp, userAgent); | 251 | return userSessionCoreService.createUserSession(loginUser, userIp, userAgent); |
| @@ -261,7 +258,7 @@ public class SysAuthServiceImpl implements SysAuthService { | @@ -261,7 +258,7 @@ public class SysAuthServiceImpl implements SysAuthService { | ||
| 261 | Assert.notNull(authUser, "授权用户不为空"); | 258 | Assert.notNull(authUser, "授权用户不为空"); |
| 262 | 259 | ||
| 263 | // 绑定社交用户(新增) | 260 | // 绑定社交用户(新增) |
| 264 | - socialService.bindSocialUser(userId, reqVO.getType(), authUser, USER_TYPE_ENUM); | 261 | + socialService.bindSocialUser(userId, reqVO.getType(), authUser, getUserType()); |
| 265 | } | 262 | } |
| 266 | 263 | ||
| 267 | @Override | 264 | @Override |
| @@ -277,12 +274,17 @@ public class SysAuthServiceImpl implements SysAuthService { | @@ -277,12 +274,17 @@ public class SysAuthServiceImpl implements SysAuthService { | ||
| 277 | this.createLogoutLog(loginUser.getId(), loginUser.getUsername()); | 274 | this.createLogoutLog(loginUser.getId(), loginUser.getUsername()); |
| 278 | } | 275 | } |
| 279 | 276 | ||
| 277 | + @Override | ||
| 278 | + public UserTypeEnum getUserType() { | ||
| 279 | + return UserTypeEnum.ADMIN; | ||
| 280 | + } | ||
| 281 | + | ||
| 280 | private void createLogoutLog(Long userId, String username) { | 282 | private void createLogoutLog(Long userId, String username) { |
| 281 | SysLoginLogCreateReqDTO reqDTO = new SysLoginLogCreateReqDTO(); | 283 | SysLoginLogCreateReqDTO reqDTO = new SysLoginLogCreateReqDTO(); |
| 282 | reqDTO.setLogType(SysLoginLogTypeEnum.LOGOUT_SELF.getType()); | 284 | reqDTO.setLogType(SysLoginLogTypeEnum.LOGOUT_SELF.getType()); |
| 283 | reqDTO.setTraceId(TracerUtils.getTraceId()); | 285 | reqDTO.setTraceId(TracerUtils.getTraceId()); |
| 284 | reqDTO.setUserId(userId); | 286 | reqDTO.setUserId(userId); |
| 285 | - reqDTO.setUserType(USER_TYPE_ENUM.getValue()); | 287 | + reqDTO.setUserType(getUserType().getValue()); |
| 286 | reqDTO.setUsername(username); | 288 | reqDTO.setUsername(username); |
| 287 | reqDTO.setUserAgent(ServletUtils.getUserAgent()); | 289 | reqDTO.setUserAgent(ServletUtils.getUserAgent()); |
| 288 | reqDTO.setUserIp(ServletUtils.getClientIP()); | 290 | reqDTO.setUserIp(ServletUtils.getClientIP()); |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/user/impl/SysUserServiceImpl.java
| @@ -23,6 +23,7 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult; | @@ -23,6 +23,7 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 23 | import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; | 23 | import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; |
| 24 | import com.google.common.annotations.VisibleForTesting; | 24 | import com.google.common.annotations.VisibleForTesting; |
| 25 | import lombok.extern.slf4j.Slf4j; | 25 | import lombok.extern.slf4j.Slf4j; |
| 26 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 26 | import org.springframework.beans.factory.annotation.Value; | 27 | import org.springframework.beans.factory.annotation.Value; |
| 27 | import org.springframework.security.crypto.password.PasswordEncoder; | 28 | import org.springframework.security.crypto.password.PasswordEncoder; |
| 28 | import org.springframework.stereotype.Service; | 29 | import org.springframework.stereotype.Service; |
| @@ -47,7 +48,7 @@ public class SysUserServiceImpl implements SysUserService { | @@ -47,7 +48,7 @@ public class SysUserServiceImpl implements SysUserService { | ||
| 47 | @Value("${sys.user.init-password:yudaoyuanma}") | 48 | @Value("${sys.user.init-password:yudaoyuanma}") |
| 48 | private String userInitPassword; | 49 | private String userInitPassword; |
| 49 | 50 | ||
| 50 | - @Resource | 51 | + @Resource(name = "sysUserMapper") // userMapper 存在重名 |
| 51 | private SysUserMapper userMapper; | 52 | private SysUserMapper userMapper; |
| 52 | 53 | ||
| 53 | @Resource | 54 | @Resource |
yudao-admin-server/src/main/resources/application-local.yaml
| @@ -174,6 +174,18 @@ logging: | @@ -174,6 +174,18 @@ logging: | ||
| 174 | cn.iocoder.yudao.coreservice.modules.system.dal.mysql: debug | 174 | cn.iocoder.yudao.coreservice.modules.system.dal.mysql: debug |
| 175 | cn.iocoder.yudao.coreservice.modules.tool.dal.mysql: debug | 175 | cn.iocoder.yudao.coreservice.modules.tool.dal.mysql: debug |
| 176 | 176 | ||
| 177 | +--- #################### 微信公众号相关配置 #################### | ||
| 178 | +wx: # 参见 https://github.com/Wechat-Group/WxJava/blob/develop/spring-boot-starters/wx-java-mp-spring-boot-starter/README.md 文档 | ||
| 179 | + mp: | ||
| 180 | + # 公众号配置(必填) | ||
| 181 | + app-id: wx041349c6f39b268b | ||
| 182 | + secret: 5abee519483bc9f8cb37ce280e814bd0 | ||
| 183 | + # 存储配置,解决 AccessToken 的跨节点的共享 | ||
| 184 | + config-storage: | ||
| 185 | + type: RedisTemplate # 采用 RedisTemplate 操作 Redis,会自动从 Spring 中获取 | ||
| 186 | + key-prefix: wx # Redis Key 的前缀 TODO 芋艿:解决下 Redis key 管理的配置 | ||
| 187 | + http-client-type: HttpClient # 采用 HttpClient 请求微信公众号平台 | ||
| 188 | + | ||
| 177 | --- #################### 芋道相关配置 #################### | 189 | --- #################### 芋道相关配置 #################### |
| 178 | 190 | ||
| 179 | # 芋道配置项,设置当前项目所有自定义的配置 | 191 | # 芋道配置项,设置当前项目所有自定义的配置 |
yudao-admin-server/src/main/resources/application.yaml
| @@ -48,11 +48,17 @@ yudao: | @@ -48,11 +48,17 @@ yudao: | ||
| 48 | info: | 48 | info: |
| 49 | version: 1.0.0 | 49 | version: 1.0.0 |
| 50 | base-package: cn.iocoder.yudao.adminserver | 50 | base-package: cn.iocoder.yudao.adminserver |
| 51 | + member-package: cn.iocoder.yudao.module.member | ||
| 51 | core-service: | 52 | core-service: |
| 52 | base-package: cn.iocoder.yudao.coreservice | 53 | base-package: cn.iocoder.yudao.coreservice |
| 53 | web: | 54 | web: |
| 54 | - api-prefix: /api | ||
| 55 | - controller-package: ${yudao.info.base-package} | 55 | + admin-api: |
| 56 | + prefix: /api | ||
| 57 | + controller: ${yudao.info.base-package} | ||
| 58 | + app-api: | ||
| 59 | + prefix: /app-api | ||
| 60 | + controller: cn.iocoder.yudao.module.member.controller.app | ||
| 61 | + | ||
| 56 | swagger: | 62 | swagger: |
| 57 | title: 管理后台 | 63 | title: 管理后台 |
| 58 | description: 提供管理员管理的所有功能 | 64 | description: 提供管理员管理的所有功能 |
| @@ -72,7 +78,13 @@ yudao: | @@ -72,7 +78,13 @@ yudao: | ||
| 72 | - cn.iocoder.yudao.adminserver.modules.bpm.enums.BpmErrorCodeConstants | 78 | - cn.iocoder.yudao.adminserver.modules.bpm.enums.BpmErrorCodeConstants |
| 73 | tenant: # 多租户相关配置项 | 79 | tenant: # 多租户相关配置项 |
| 74 | tables: # 配置需要开启多租户的表;如果实体已经继承 TenantBaseDO 类,则无需重复配置 | 80 | tables: # 配置需要开启多租户的表;如果实体已经继承 TenantBaseDO 类,则无需重复配置 |
| 75 | - url: | 81 | + url: ## TODO 芋艿:迁移到 web 配置项下, |
| 76 | admin-ui: http://dashboard.yudao.iocoder.cn # Admin 管理后台 UI 的地址 | 82 | admin-ui: http://dashboard.yudao.iocoder.cn # Admin 管理后台 UI 的地址 |
| 83 | + sms-code: # 短信验证码相关的配置项 | ||
| 84 | + expire-times: 10m | ||
| 85 | + send-frequency: 1m | ||
| 86 | + send-maximum-quantity-per-day: 10 | ||
| 87 | + begin-code: 9999 # 这里配置 9999 的原因是,测试方便。 | ||
| 88 | + end-code: 9999 # 这里配置 9999 的原因是,测试方便。 | ||
| 77 | 89 | ||
| 78 | debug: false | 90 | debug: false |
yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/service/file/InfFileCoreService.java
| @@ -9,7 +9,6 @@ import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.file.InfFileDO; | @@ -9,7 +9,6 @@ import cn.iocoder.yudao.coreservice.modules.infra.dal.dataobject.file.InfFileDO; | ||
| 9 | */ | 9 | */ |
| 10 | public interface InfFileCoreService { | 10 | public interface InfFileCoreService { |
| 11 | 11 | ||
| 12 | - | ||
| 13 | /** | 12 | /** |
| 14 | * 保存文件,并返回文件的访问路径 | 13 | * 保存文件,并返回文件的访问路径 |
| 15 | * | 14 | * |
yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/service/sms/impl/SysSmsCoreServiceImpl.java
| @@ -2,8 +2,6 @@ package cn.iocoder.yudao.coreservice.modules.system.service.sms.impl; | @@ -2,8 +2,6 @@ package cn.iocoder.yudao.coreservice.modules.system.service.sms.impl; | ||
| 2 | 2 | ||
| 3 | import cn.hutool.core.collection.CollUtil; | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | import cn.hutool.core.util.StrUtil; | 4 | import cn.hutool.core.util.StrUtil; |
| 5 | -import cn.iocoder.yudao.coreservice.modules.member.dal.dataobject.user.MbrUserDO; | ||
| 6 | -import cn.iocoder.yudao.coreservice.modules.member.service.user.MbrUserCoreService; | ||
| 7 | import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.sms.SysSmsTemplateDO; | 5 | import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.sms.SysSmsTemplateDO; |
| 8 | import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.user.SysUserDO; | 6 | import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.user.SysUserDO; |
| 9 | import cn.iocoder.yudao.coreservice.modules.system.mq.message.sms.SysSmsSendMessage; | 7 | import cn.iocoder.yudao.coreservice.modules.system.mq.message.sms.SysSmsSendMessage; |
| @@ -43,8 +41,6 @@ public class SysSmsCoreServiceImpl implements SysSmsCoreService { | @@ -43,8 +41,6 @@ public class SysSmsCoreServiceImpl implements SysSmsCoreService { | ||
| 43 | @Resource | 41 | @Resource |
| 44 | private SysUserCoreService sysUserCoreService; | 42 | private SysUserCoreService sysUserCoreService; |
| 45 | @Resource | 43 | @Resource |
| 46 | - private MbrUserCoreService mbrUserCoreService; | ||
| 47 | - @Resource | ||
| 48 | private SysSmsTemplateCoreService smsTemplateCoreService; | 44 | private SysSmsTemplateCoreService smsTemplateCoreService; |
| 49 | @Resource | 45 | @Resource |
| 50 | private SysSmsLogCoreService smsLogCoreService; | 46 | private SysSmsLogCoreService smsLogCoreService; |
| @@ -72,10 +68,11 @@ public class SysSmsCoreServiceImpl implements SysSmsCoreService { | @@ -72,10 +68,11 @@ public class SysSmsCoreServiceImpl implements SysSmsCoreService { | ||
| 72 | public Long sendSingleSmsToMember(String mobile, Long userId, String templateCode, Map<String, Object> templateParams) { | 68 | public Long sendSingleSmsToMember(String mobile, Long userId, String templateCode, Map<String, Object> templateParams) { |
| 73 | // 如果 mobile 为空,则加载用户编号对应的手机号 | 69 | // 如果 mobile 为空,则加载用户编号对应的手机号 |
| 74 | if (StrUtil.isEmpty(mobile)) { | 70 | if (StrUtil.isEmpty(mobile)) { |
| 75 | - MbrUserDO user = mbrUserCoreService.getUser(userId); | ||
| 76 | - if (user != null) { | ||
| 77 | - mobile = user.getMobile(); | ||
| 78 | - } | 71 | +// MbrUserDO user = mbrUserCoreService.getUser(userId); |
| 72 | +// if (user != null) { | ||
| 73 | +// mobile = user.getMobile(); | ||
| 74 | +// } | ||
| 75 | + // TODO 芋艿:重构 | ||
| 79 | } | 76 | } |
| 80 | // 执行发送 | 77 | // 执行发送 |
| 81 | return this.sendSingleSms(mobile, userId, UserTypeEnum.MEMBER.getValue(), templateCode, templateParams); | 78 | return this.sendSingleSms(mobile, userId, UserTypeEnum.MEMBER.getValue(), templateCode, templateParams); |
yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/config/YudaoMybatisAutoConfiguration.java
| @@ -15,7 +15,8 @@ import org.springframework.context.annotation.Configuration; | @@ -15,7 +15,8 @@ import org.springframework.context.annotation.Configuration; | ||
| 15 | * @author 芋道源码 | 15 | * @author 芋道源码 |
| 16 | */ | 16 | */ |
| 17 | @Configuration | 17 | @Configuration |
| 18 | -@MapperScan(value = {"${yudao.info.base-package}", "${yudao.core-service.base-package}"}, annotationClass = Mapper.class, | 18 | +@MapperScan(value = {"${yudao.info.base-package}", "${yudao.core-service.base-package}", "${yudao.info.member-package}"}, |
| 19 | + annotationClass = Mapper.class, | ||
| 19 | lazyInitialization = "${mybatis.lazy-initialization:false}") // Mapper 懒加载,目前仅用于单元测试 | 20 | lazyInitialization = "${mybatis.lazy-initialization:false}") // Mapper 懒加载,目前仅用于单元测试 |
| 20 | public class YudaoMybatisAutoConfiguration { | 21 | public class YudaoMybatisAutoConfiguration { |
| 21 | 22 |
yudao-framework/yudao-spring-boot-starter-security/src/main/java/cn/iocoder/yudao/framework/security/config/YudaoSecurityAutoConfiguration.java
| @@ -7,6 +7,9 @@ import cn.iocoder.yudao.framework.security.core.handler.AccessDeniedHandlerImpl; | @@ -7,6 +7,9 @@ import cn.iocoder.yudao.framework.security.core.handler.AccessDeniedHandlerImpl; | ||
| 7 | import cn.iocoder.yudao.framework.security.core.handler.AuthenticationEntryPointImpl; | 7 | import cn.iocoder.yudao.framework.security.core.handler.AuthenticationEntryPointImpl; |
| 8 | import cn.iocoder.yudao.framework.security.core.handler.LogoutSuccessHandlerImpl; | 8 | import cn.iocoder.yudao.framework.security.core.handler.LogoutSuccessHandlerImpl; |
| 9 | import cn.iocoder.yudao.framework.security.core.service.SecurityAuthFrameworkService; | 9 | import cn.iocoder.yudao.framework.security.core.service.SecurityAuthFrameworkService; |
| 10 | +import cn.iocoder.yudao.framework.security.core.service.SecurityAuthService; | ||
| 11 | +import cn.iocoder.yudao.framework.security.core.service.SecurityAuthServiceImpl; | ||
| 12 | +import cn.iocoder.yudao.framework.web.config.WebProperties; | ||
| 10 | import cn.iocoder.yudao.framework.web.core.handler.GlobalExceptionHandler; | 13 | import cn.iocoder.yudao.framework.web.core.handler.GlobalExceptionHandler; |
| 11 | import org.springframework.beans.factory.config.MethodInvokingFactoryBean; | 14 | import org.springframework.beans.factory.config.MethodInvokingFactoryBean; |
| 12 | import org.springframework.boot.context.properties.EnableConfigurationProperties; | 15 | import org.springframework.boot.context.properties.EnableConfigurationProperties; |
| @@ -20,6 +23,7 @@ import org.springframework.security.web.access.AccessDeniedHandler; | @@ -20,6 +23,7 @@ import org.springframework.security.web.access.AccessDeniedHandler; | ||
| 20 | import org.springframework.security.web.authentication.logout.LogoutSuccessHandler; | 23 | import org.springframework.security.web.authentication.logout.LogoutSuccessHandler; |
| 21 | 24 | ||
| 22 | import javax.annotation.Resource; | 25 | import javax.annotation.Resource; |
| 26 | +import java.util.List; | ||
| 23 | 27 | ||
| 24 | /** | 28 | /** |
| 25 | * Spring Security 自动配置类,主要用于相关组件的配置 | 29 | * Spring Security 自动配置类,主要用于相关组件的配置 |
| @@ -29,7 +33,7 @@ import javax.annotation.Resource; | @@ -29,7 +33,7 @@ import javax.annotation.Resource; | ||
| 29 | * | 33 | * |
| 30 | * @author 芋道源码 | 34 | * @author 芋道源码 |
| 31 | */ | 35 | */ |
| 32 | -@Configuration | 36 | +@Configuration(proxyBeanMethods = false) |
| 33 | @EnableConfigurationProperties(SecurityProperties.class) | 37 | @EnableConfigurationProperties(SecurityProperties.class) |
| 34 | public class YudaoSecurityAutoConfiguration { | 38 | public class YudaoSecurityAutoConfiguration { |
| 35 | 39 | ||
| @@ -64,8 +68,8 @@ public class YudaoSecurityAutoConfiguration { | @@ -64,8 +68,8 @@ public class YudaoSecurityAutoConfiguration { | ||
| 64 | * 退出处理类 Bean | 68 | * 退出处理类 Bean |
| 65 | */ | 69 | */ |
| 66 | @Bean | 70 | @Bean |
| 67 | - public LogoutSuccessHandler logoutSuccessHandler(SecurityAuthFrameworkService securityFrameworkService) { | ||
| 68 | - return new LogoutSuccessHandlerImpl(securityProperties, securityFrameworkService); | 71 | + public LogoutSuccessHandler logoutSuccessHandler(SecurityAuthService securityAuthService) { |
| 72 | + return new LogoutSuccessHandlerImpl(securityProperties, securityAuthService); | ||
| 69 | } | 73 | } |
| 70 | 74 | ||
| 71 | /** | 75 | /** |
| @@ -83,9 +87,18 @@ public class YudaoSecurityAutoConfiguration { | @@ -83,9 +87,18 @@ public class YudaoSecurityAutoConfiguration { | ||
| 83 | * Token 认证过滤器 Bean | 87 | * Token 认证过滤器 Bean |
| 84 | */ | 88 | */ |
| 85 | @Bean | 89 | @Bean |
| 86 | - public JWTAuthenticationTokenFilter authenticationTokenFilter(SecurityAuthFrameworkService securityFrameworkService, | 90 | + public JWTAuthenticationTokenFilter authenticationTokenFilter(SecurityAuthService securityAuthService, |
| 87 | GlobalExceptionHandler globalExceptionHandler) { | 91 | GlobalExceptionHandler globalExceptionHandler) { |
| 88 | - return new JWTAuthenticationTokenFilter(securityProperties, securityFrameworkService, globalExceptionHandler); | 92 | + return new JWTAuthenticationTokenFilter(securityProperties, securityAuthService, globalExceptionHandler); |
| 93 | + } | ||
| 94 | + | ||
| 95 | + /** | ||
| 96 | + * 安全认证的 Service Bean | ||
| 97 | + */ | ||
| 98 | + @Bean | ||
| 99 | + public SecurityAuthService securityAuthService(List<SecurityAuthFrameworkService> securityFrameworkServices, | ||
| 100 | + WebProperties webProperties) { | ||
| 101 | + return new SecurityAuthServiceImpl(securityFrameworkServices, webProperties); | ||
| 89 | } | 102 | } |
| 90 | 103 | ||
| 91 | /** | 104 | /** |
yudao-framework/yudao-spring-boot-starter-security/src/main/java/cn/iocoder/yudao/framework/security/config/YudaoWebSecurityConfigurerAdapter.java
| @@ -65,13 +65,15 @@ public class YudaoWebSecurityConfigurerAdapter extends WebSecurityConfigurerAdap | @@ -65,13 +65,15 @@ public class YudaoWebSecurityConfigurerAdapter extends WebSecurityConfigurerAdap | ||
| 65 | */ | 65 | */ |
| 66 | @Resource | 66 | @Resource |
| 67 | private JWTAuthenticationTokenFilter authenticationTokenFilter; | 67 | private JWTAuthenticationTokenFilter authenticationTokenFilter; |
| 68 | + | ||
| 68 | /** | 69 | /** |
| 69 | * 自定义的权限映射 Bean | 70 | * 自定义的权限映射 Bean |
| 70 | * | 71 | * |
| 71 | * @see #configure(HttpSecurity) | 72 | * @see #configure(HttpSecurity) |
| 72 | */ | 73 | */ |
| 73 | @Resource | 74 | @Resource |
| 74 | - private Customizer<ExpressionUrlAuthorizationConfigurer<HttpSecurity>.ExpressionInterceptUrlRegistry> authorizeRequestsCustomizer; | 75 | + private Customizer<ExpressionUrlAuthorizationConfigurer<HttpSecurity>.ExpressionInterceptUrlRegistry> |
| 76 | + authorizeRequestsCustomizer; | ||
| 75 | 77 | ||
| 76 | /** | 78 | /** |
| 77 | * 由于 Spring Security 创建 AuthenticationManager 对象时,没声明 @Bean 注解,导致无法被注入 | 79 | * 由于 Spring Security 创建 AuthenticationManager 对象时,没声明 @Bean 注解,导致无法被注入 |
| @@ -89,8 +91,8 @@ public class YudaoWebSecurityConfigurerAdapter extends WebSecurityConfigurerAdap | @@ -89,8 +91,8 @@ public class YudaoWebSecurityConfigurerAdapter extends WebSecurityConfigurerAdap | ||
| 89 | */ | 91 | */ |
| 90 | @Override | 92 | @Override |
| 91 | protected void configure(AuthenticationManagerBuilder auth) throws Exception { | 93 | protected void configure(AuthenticationManagerBuilder auth) throws Exception { |
| 92 | - auth.userDetailsService(userDetailsService) | ||
| 93 | - .passwordEncoder(passwordEncoder); | 94 | + auth |
| 95 | + .userDetailsService(userDetailsService).passwordEncoder(passwordEncoder); | ||
| 94 | } | 96 | } |
| 95 | 97 | ||
| 96 | /** | 98 | /** |
| @@ -123,16 +125,16 @@ public class YudaoWebSecurityConfigurerAdapter extends WebSecurityConfigurerAdap | @@ -123,16 +125,16 @@ public class YudaoWebSecurityConfigurerAdapter extends WebSecurityConfigurerAdap | ||
| 123 | // 一堆自定义的 Spring Security 处理器 | 125 | // 一堆自定义的 Spring Security 处理器 |
| 124 | .exceptionHandling().authenticationEntryPoint(authenticationEntryPoint) | 126 | .exceptionHandling().authenticationEntryPoint(authenticationEntryPoint) |
| 125 | .accessDeniedHandler(accessDeniedHandler).and() | 127 | .accessDeniedHandler(accessDeniedHandler).and() |
| 126 | - .logout().logoutUrl(api("/logout")).logoutSuccessHandler(logoutSuccessHandler); // 登出 | 128 | + .logout().logoutUrl(buildAdminApi("/logout")).logoutSuccessHandler(logoutSuccessHandler); // 登出 |
| 127 | 129 | ||
| 128 | // 设置每个请求的权限 ①:全局共享规则 | 130 | // 设置每个请求的权限 ①:全局共享规则 |
| 129 | httpSecurity.authorizeRequests() | 131 | httpSecurity.authorizeRequests() |
| 130 | // 登录的接口,可匿名访问 | 132 | // 登录的接口,可匿名访问 |
| 131 | - .antMatchers(api("/login")).anonymous() | 133 | + .antMatchers(buildAdminApi("/login")).anonymous() |
| 132 | // 静态资源,可匿名访问 | 134 | // 静态资源,可匿名访问 |
| 133 | .antMatchers(HttpMethod.GET, "/*.html", "/**/*.html", "/**/*.css", "/**/*.js").permitAll() | 135 | .antMatchers(HttpMethod.GET, "/*.html", "/**/*.html", "/**/*.css", "/**/*.js").permitAll() |
| 134 | // 文件的获取接口,可匿名访问 | 136 | // 文件的获取接口,可匿名访问 |
| 135 | - .antMatchers(api("/infra/file/get/**")).anonymous() | 137 | + .antMatchers(buildAdminApi("/infra/file/get/**")).anonymous() |
| 136 | // Swagger 接口文档 | 138 | // Swagger 接口文档 |
| 137 | .antMatchers("/swagger-ui.html").anonymous() | 139 | .antMatchers("/swagger-ui.html").anonymous() |
| 138 | .antMatchers("/swagger-resources/**").anonymous() | 140 | .antMatchers("/swagger-resources/**").anonymous() |
| @@ -143,11 +145,11 @@ public class YudaoWebSecurityConfigurerAdapter extends WebSecurityConfigurerAdap | @@ -143,11 +145,11 @@ public class YudaoWebSecurityConfigurerAdapter extends WebSecurityConfigurerAdap | ||
| 143 | .antMatchers("/actuator/**").anonymous() | 145 | .antMatchers("/actuator/**").anonymous() |
| 144 | // Druid 监控 TODO 芋艿:等对接了 druid admin 后,在调整下。 | 146 | // Druid 监控 TODO 芋艿:等对接了 druid admin 后,在调整下。 |
| 145 | .antMatchers("/druid/**").anonymous() | 147 | .antMatchers("/druid/**").anonymous() |
| 146 | - // oAuth2 auth2/login/gitee | ||
| 147 | - .antMatchers(api("/auth2/login/**")).anonymous() | ||
| 148 | - .antMatchers(api("/auth2/authorization/**")).anonymous() | 148 | + // oAuth2 auth2/login/gitee TODO 芋艿:貌似可以删除 |
| 149 | + .antMatchers(buildAdminApi("/auth2/login/**")).anonymous() | ||
| 150 | + .antMatchers(buildAdminApi("/auth2/authorization/**")).anonymous() | ||
| 149 | .antMatchers("/api/callback/**").anonymous() | 151 | .antMatchers("/api/callback/**").anonymous() |
| 150 | - // 设置每个请求的权限 ②:每个项目的自定义规则 | 152 | + // 设置每个请求的权限 ②:每个项目的自定义规则 TODO 芋艿:改造成多个,方便每个模块自定义规则 |
| 151 | .and().authorizeRequests(authorizeRequestsCustomizer) | 153 | .and().authorizeRequests(authorizeRequestsCustomizer) |
| 152 | // 设置每个请求的权限 ③:兜底规则,必须认证 | 154 | // 设置每个请求的权限 ③:兜底规则,必须认证 |
| 153 | .authorizeRequests().anyRequest().authenticated() | 155 | .authorizeRequests().anyRequest().authenticated() |
| @@ -156,8 +158,14 @@ public class YudaoWebSecurityConfigurerAdapter extends WebSecurityConfigurerAdap | @@ -156,8 +158,14 @@ public class YudaoWebSecurityConfigurerAdapter extends WebSecurityConfigurerAdap | ||
| 156 | httpSecurity.addFilterBefore(authenticationTokenFilter, UsernamePasswordAuthenticationFilter.class); | 158 | httpSecurity.addFilterBefore(authenticationTokenFilter, UsernamePasswordAuthenticationFilter.class); |
| 157 | } | 159 | } |
| 158 | 160 | ||
| 159 | - private String api(String url) { | ||
| 160 | - return webProperties.getApiPrefix() + url; | 161 | + private String buildAdminApi(String url) { |
| 162 | + // TODO 芋艿:多模块 | ||
| 163 | + return webProperties.getAdminApi().getPrefix() + url; | ||
| 164 | + } | ||
| 165 | + | ||
| 166 | + private String buildAppApi(String url) { | ||
| 167 | + // TODO 芋艿:多模块 | ||
| 168 | + return webProperties.getAppApi().getPrefix() + url; | ||
| 161 | } | 169 | } |
| 162 | 170 | ||
| 163 | } | 171 | } |
yudao-framework/yudao-spring-boot-starter-security/src/main/java/cn/iocoder/yudao/framework/security/core/filter/JWTAuthenticationTokenFilter.java
| @@ -2,17 +2,15 @@ package cn.iocoder.yudao.framework.security.core.filter; | @@ -2,17 +2,15 @@ package cn.iocoder.yudao.framework.security.core.filter; | ||
| 2 | 2 | ||
| 3 | import cn.hutool.core.util.StrUtil; | 3 | import cn.hutool.core.util.StrUtil; |
| 4 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; | 4 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 5 | +import cn.iocoder.yudao.framework.common.util.servlet.ServletUtils; | ||
| 5 | import cn.iocoder.yudao.framework.security.config.SecurityProperties; | 6 | import cn.iocoder.yudao.framework.security.config.SecurityProperties; |
| 6 | import cn.iocoder.yudao.framework.security.core.LoginUser; | 7 | import cn.iocoder.yudao.framework.security.core.LoginUser; |
| 7 | -import cn.iocoder.yudao.framework.security.core.service.SecurityAuthFrameworkService; | 8 | +import cn.iocoder.yudao.framework.security.core.service.SecurityAuthService; |
| 8 | import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils; | 9 | import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils; |
| 9 | import cn.iocoder.yudao.framework.web.core.handler.GlobalExceptionHandler; | 10 | import cn.iocoder.yudao.framework.web.core.handler.GlobalExceptionHandler; |
| 10 | -import cn.iocoder.yudao.framework.common.util.servlet.ServletUtils; | ||
| 11 | import lombok.AllArgsConstructor; | 11 | import lombok.AllArgsConstructor; |
| 12 | -import org.springframework.stereotype.Component; | ||
| 13 | import org.springframework.web.filter.OncePerRequestFilter; | 12 | import org.springframework.web.filter.OncePerRequestFilter; |
| 14 | 13 | ||
| 15 | -import javax.annotation.Resource; | ||
| 16 | import javax.servlet.FilterChain; | 14 | import javax.servlet.FilterChain; |
| 17 | import javax.servlet.ServletException; | 15 | import javax.servlet.ServletException; |
| 18 | import javax.servlet.http.HttpServletRequest; | 16 | import javax.servlet.http.HttpServletRequest; |
| @@ -30,7 +28,7 @@ public class JWTAuthenticationTokenFilter extends OncePerRequestFilter { | @@ -30,7 +28,7 @@ public class JWTAuthenticationTokenFilter extends OncePerRequestFilter { | ||
| 30 | 28 | ||
| 31 | private final SecurityProperties securityProperties; | 29 | private final SecurityProperties securityProperties; |
| 32 | 30 | ||
| 33 | - private final SecurityAuthFrameworkService authService; | 31 | + private final SecurityAuthService authService; |
| 34 | 32 | ||
| 35 | private final GlobalExceptionHandler globalExceptionHandler; | 33 | private final GlobalExceptionHandler globalExceptionHandler; |
| 36 | 34 | ||
| @@ -42,10 +40,10 @@ public class JWTAuthenticationTokenFilter extends OncePerRequestFilter { | @@ -42,10 +40,10 @@ public class JWTAuthenticationTokenFilter extends OncePerRequestFilter { | ||
| 42 | if (StrUtil.isNotEmpty(token)) { | 40 | if (StrUtil.isNotEmpty(token)) { |
| 43 | try { | 41 | try { |
| 44 | // 验证 token 有效性 | 42 | // 验证 token 有效性 |
| 45 | - LoginUser loginUser = authService.verifyTokenAndRefresh(token); | 43 | + LoginUser loginUser = authService.verifyTokenAndRefresh(request, token); |
| 46 | // 模拟 Login 功能,方便日常开发调试 | 44 | // 模拟 Login 功能,方便日常开发调试 |
| 47 | if (loginUser == null) { | 45 | if (loginUser == null) { |
| 48 | - loginUser = this.mockLoginUser(token); | 46 | + loginUser = this.mockLoginUser(request, token); |
| 49 | } | 47 | } |
| 50 | // 设置当前用户 | 48 | // 设置当前用户 |
| 51 | if (loginUser != null) { | 49 | if (loginUser != null) { |
| @@ -67,10 +65,11 @@ public class JWTAuthenticationTokenFilter extends OncePerRequestFilter { | @@ -67,10 +65,11 @@ public class JWTAuthenticationTokenFilter extends OncePerRequestFilter { | ||
| 67 | * | 65 | * |
| 68 | * 注意,在线上环境下,一定要关闭该功能!!! | 66 | * 注意,在线上环境下,一定要关闭该功能!!! |
| 69 | * | 67 | * |
| 68 | + * @param request 请求 | ||
| 70 | * @param token 模拟的 token,格式为 {@link SecurityProperties#getTokenSecret()} + 用户编号 | 69 | * @param token 模拟的 token,格式为 {@link SecurityProperties#getTokenSecret()} + 用户编号 |
| 71 | * @return 模拟的 LoginUser | 70 | * @return 模拟的 LoginUser |
| 72 | */ | 71 | */ |
| 73 | - private LoginUser mockLoginUser(String token) { | 72 | + private LoginUser mockLoginUser(HttpServletRequest request, String token) { |
| 74 | if (!securityProperties.getMockEnable()) { | 73 | if (!securityProperties.getMockEnable()) { |
| 75 | return null; | 74 | return null; |
| 76 | } | 75 | } |
| @@ -79,7 +78,7 @@ public class JWTAuthenticationTokenFilter extends OncePerRequestFilter { | @@ -79,7 +78,7 @@ public class JWTAuthenticationTokenFilter extends OncePerRequestFilter { | ||
| 79 | return null; | 78 | return null; |
| 80 | } | 79 | } |
| 81 | Long userId = Long.valueOf(token.substring(securityProperties.getMockSecret().length())); | 80 | Long userId = Long.valueOf(token.substring(securityProperties.getMockSecret().length())); |
| 82 | - return authService.mockLogin(userId); | 81 | + return authService.mockLogin(request, userId); |
| 83 | } | 82 | } |
| 84 | 83 | ||
| 85 | } | 84 | } |
yudao-framework/yudao-spring-boot-starter-security/src/main/java/cn/iocoder/yudao/framework/security/core/handler/LogoutSuccessHandlerImpl.java
| @@ -2,16 +2,14 @@ package cn.iocoder.yudao.framework.security.core.handler; | @@ -2,16 +2,14 @@ package cn.iocoder.yudao.framework.security.core.handler; | ||
| 2 | 2 | ||
| 3 | import cn.hutool.core.util.StrUtil; | 3 | import cn.hutool.core.util.StrUtil; |
| 4 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; | 4 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 5 | +import cn.iocoder.yudao.framework.common.util.servlet.ServletUtils; | ||
| 5 | import cn.iocoder.yudao.framework.security.config.SecurityProperties; | 6 | import cn.iocoder.yudao.framework.security.config.SecurityProperties; |
| 6 | -import cn.iocoder.yudao.framework.security.core.service.SecurityAuthFrameworkService; | 7 | +import cn.iocoder.yudao.framework.security.core.service.SecurityAuthService; |
| 7 | import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils; | 8 | import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils; |
| 8 | -import cn.iocoder.yudao.framework.common.util.servlet.ServletUtils; | ||
| 9 | import lombok.AllArgsConstructor; | 9 | import lombok.AllArgsConstructor; |
| 10 | import org.springframework.security.core.Authentication; | 10 | import org.springframework.security.core.Authentication; |
| 11 | import org.springframework.security.web.authentication.logout.LogoutSuccessHandler; | 11 | import org.springframework.security.web.authentication.logout.LogoutSuccessHandler; |
| 12 | -import org.springframework.stereotype.Component; | ||
| 13 | 12 | ||
| 14 | -import javax.annotation.Resource; | ||
| 15 | import javax.servlet.http.HttpServletRequest; | 13 | import javax.servlet.http.HttpServletRequest; |
| 16 | import javax.servlet.http.HttpServletResponse; | 14 | import javax.servlet.http.HttpServletResponse; |
| 17 | 15 | ||
| @@ -26,14 +24,14 @@ public class LogoutSuccessHandlerImpl implements LogoutSuccessHandler { | @@ -26,14 +24,14 @@ public class LogoutSuccessHandlerImpl implements LogoutSuccessHandler { | ||
| 26 | 24 | ||
| 27 | private final SecurityProperties securityProperties; | 25 | private final SecurityProperties securityProperties; |
| 28 | 26 | ||
| 29 | - private final SecurityAuthFrameworkService securityFrameworkService; | 27 | + private final SecurityAuthService authService; |
| 30 | 28 | ||
| 31 | @Override | 29 | @Override |
| 32 | public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) { | 30 | public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) { |
| 33 | // 执行退出 | 31 | // 执行退出 |
| 34 | String token = SecurityFrameworkUtils.obtainAuthorization(request, securityProperties.getTokenHeader()); | 32 | String token = SecurityFrameworkUtils.obtainAuthorization(request, securityProperties.getTokenHeader()); |
| 35 | if (StrUtil.isNotBlank(token)) { | 33 | if (StrUtil.isNotBlank(token)) { |
| 36 | - securityFrameworkService.logout(token); | 34 | + authService.logout(request, token); |
| 37 | } | 35 | } |
| 38 | // 返回成功 | 36 | // 返回成功 |
| 39 | ServletUtils.writeJSON(response, CommonResult.success(null)); | 37 | ServletUtils.writeJSON(response, CommonResult.success(null)); |
yudao-framework/yudao-spring-boot-starter-security/src/main/java/cn/iocoder/yudao/framework/security/core/service/SecurityAuthFrameworkService.java
| 1 | package cn.iocoder.yudao.framework.security.core.service; | 1 | package cn.iocoder.yudao.framework.security.core.service; |
| 2 | 2 | ||
| 3 | +import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; | ||
| 3 | import cn.iocoder.yudao.framework.security.core.LoginUser; | 4 | import cn.iocoder.yudao.framework.security.core.LoginUser; |
| 4 | import org.springframework.security.core.userdetails.UserDetailsService; | 5 | import org.springframework.security.core.userdetails.UserDetailsService; |
| 5 | 6 | ||
| 6 | /** | 7 | /** |
| 7 | - * Security 框架 Auth Service 接口,定义 security 组件需要的功能 | 8 | + * Security 框架 Auth Service 接口,定义不同用户类型的 {@link UserTypeEnum} 需要实现的方法 |
| 8 | * | 9 | * |
| 9 | * @author 芋道源码 | 10 | * @author 芋道源码 |
| 10 | */ | 11 | */ |
| @@ -34,4 +35,11 @@ public interface SecurityAuthFrameworkService extends UserDetailsService { | @@ -34,4 +35,11 @@ public interface SecurityAuthFrameworkService extends UserDetailsService { | ||
| 34 | */ | 35 | */ |
| 35 | void logout(String token); | 36 | void logout(String token); |
| 36 | 37 | ||
| 38 | + /** | ||
| 39 | + * 获得用户类型。每个用户类型,对应一个 SecurityAuthFrameworkService 实现类。 | ||
| 40 | + * | ||
| 41 | + * @return 用户类型 | ||
| 42 | + */ | ||
| 43 | + UserTypeEnum getUserType(); | ||
| 44 | + | ||
| 37 | } | 45 | } |
yudao-framework/yudao-spring-boot-starter-security/src/main/java/cn/iocoder/yudao/framework/security/core/service/SecurityAuthService.java
0 → 100644
| 1 | +package cn.iocoder.yudao.framework.security.core.service; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.framework.security.core.LoginUser; | ||
| 4 | + | ||
| 5 | +import javax.servlet.http.HttpServletRequest; | ||
| 6 | + | ||
| 7 | +/** | ||
| 8 | + * 安全认证的 Service 接口,对 security 组件提供统一的 Auth 相关的方法。 | ||
| 9 | + * 主要是会基于 {@link HttpServletRequest} 参数,匹配对应的 {@link SecurityAuthFrameworkService} 实现,然后调用其方法。 | ||
| 10 | + * 因此,在方法的定义上,和 {@link SecurityAuthFrameworkService} 差不多。 | ||
| 11 | + * | ||
| 12 | + * @author 芋道源码 | ||
| 13 | + */ | ||
| 14 | +public interface SecurityAuthService { | ||
| 15 | + | ||
| 16 | + /** | ||
| 17 | + * 校验 token 的有效性,并获取用户信息 | ||
| 18 | + * 通过后,刷新 token 的过期时间 | ||
| 19 | + * | ||
| 20 | + * @param request 请求 | ||
| 21 | + * @param token token | ||
| 22 | + * @return 用户信息 | ||
| 23 | + */ | ||
| 24 | + LoginUser verifyTokenAndRefresh(HttpServletRequest request, String token); | ||
| 25 | + | ||
| 26 | + /** | ||
| 27 | + * 模拟指定用户编号的 LoginUser | ||
| 28 | + * | ||
| 29 | + * @param request 请求 | ||
| 30 | + * @param userId 用户编号 | ||
| 31 | + * @return 登录用户 | ||
| 32 | + */ | ||
| 33 | + LoginUser mockLogin(HttpServletRequest request, Long userId); | ||
| 34 | + | ||
| 35 | + /** | ||
| 36 | + * 基于 token 退出登录 | ||
| 37 | + * | ||
| 38 | + * @param request 请求 | ||
| 39 | + * @param token token | ||
| 40 | + */ | ||
| 41 | + void logout(HttpServletRequest request, String token); | ||
| 42 | + | ||
| 43 | +} |
yudao-framework/yudao-spring-boot-starter-security/src/main/java/cn/iocoder/yudao/framework/security/core/service/SecurityAuthServiceImpl.java
0 → 100644
| 1 | +package cn.iocoder.yudao.framework.security.core.service; | ||
| 2 | + | ||
| 3 | +import cn.hutool.core.lang.Assert; | ||
| 4 | +import cn.hutool.core.util.StrUtil; | ||
| 5 | +import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; | ||
| 6 | +import cn.iocoder.yudao.framework.security.core.LoginUser; | ||
| 7 | +import cn.iocoder.yudao.framework.web.config.WebProperties; | ||
| 8 | + | ||
| 9 | +import javax.servlet.http.HttpServletRequest; | ||
| 10 | +import java.util.HashMap; | ||
| 11 | +import java.util.List; | ||
| 12 | +import java.util.Map; | ||
| 13 | + | ||
| 14 | +/** | ||
| 15 | + * 安全认证的 Service 实现类,基于请求地址,计算到对应的 {@link UserTypeEnum} 枚举,从而拿到对应的 {@link SecurityAuthFrameworkService} 实现 | ||
| 16 | + * | ||
| 17 | + * @author 芋道源码 | ||
| 18 | + */ | ||
| 19 | +public class SecurityAuthServiceImpl implements SecurityAuthService { | ||
| 20 | + | ||
| 21 | + private final Map<UserTypeEnum, SecurityAuthFrameworkService> services = new HashMap<>(); | ||
| 22 | + private final WebProperties properties; | ||
| 23 | + | ||
| 24 | + public SecurityAuthServiceImpl(List<SecurityAuthFrameworkService> serviceList, WebProperties properties) { | ||
| 25 | + serviceList.forEach(service -> services.put(service.getUserType(), service)); | ||
| 26 | + this.properties = properties; | ||
| 27 | + } | ||
| 28 | + | ||
| 29 | + @Override | ||
| 30 | + public LoginUser verifyTokenAndRefresh(HttpServletRequest request, String token) { | ||
| 31 | + return selectService(request).verifyTokenAndRefresh(token); | ||
| 32 | + } | ||
| 33 | + | ||
| 34 | + @Override | ||
| 35 | + public LoginUser mockLogin(HttpServletRequest request, Long userId) { | ||
| 36 | + return selectService(request).mockLogin(userId); | ||
| 37 | + } | ||
| 38 | + | ||
| 39 | + @Override | ||
| 40 | + public void logout(HttpServletRequest request, String token) { | ||
| 41 | + selectService(request).logout(token); | ||
| 42 | + } | ||
| 43 | + | ||
| 44 | + private SecurityAuthFrameworkService selectService(HttpServletRequest request) { | ||
| 45 | + // 第一步,获得用户类型 | ||
| 46 | + UserTypeEnum userType = getUserType(request); | ||
| 47 | + // 第二步,获得 SecurityAuthFrameworkService | ||
| 48 | + SecurityAuthFrameworkService service = services.get(userType); | ||
| 49 | + Assert.notNull(service, "URI({}) 用户类型({}) 找不到 SecurityAuthFrameworkService 实现类", | ||
| 50 | + request.getRequestURI(), userType); | ||
| 51 | + return service; | ||
| 52 | + } | ||
| 53 | + | ||
| 54 | + private UserTypeEnum getUserType(HttpServletRequest request) { | ||
| 55 | + if (request.getRequestURI().startsWith(properties.getAdminApi().getPrefix())) { | ||
| 56 | + return UserTypeEnum.ADMIN; | ||
| 57 | + } | ||
| 58 | + if (request.getRequestURI().startsWith(properties.getAppApi().getPrefix())) { | ||
| 59 | + return UserTypeEnum.MEMBER; | ||
| 60 | + } | ||
| 61 | + throw new IllegalArgumentException(StrUtil.format("URI({}) 找不到匹配的用户类型", request.getRequestURI())); | ||
| 62 | + } | ||
| 63 | + | ||
| 64 | +} |
yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/apilog/core/filter/ApiAccessLogFilter.java
| @@ -2,6 +2,7 @@ package cn.iocoder.yudao.framework.apilog.core.filter; | @@ -2,6 +2,7 @@ package cn.iocoder.yudao.framework.apilog.core.filter; | ||
| 2 | 2 | ||
| 3 | import cn.hutool.core.exceptions.ExceptionUtil; | 3 | import cn.hutool.core.exceptions.ExceptionUtil; |
| 4 | import cn.hutool.core.map.MapUtil; | 4 | import cn.hutool.core.map.MapUtil; |
| 5 | +import cn.hutool.core.util.StrUtil; | ||
| 5 | import cn.hutool.extra.servlet.ServletUtil; | 6 | import cn.hutool.extra.servlet.ServletUtil; |
| 6 | import cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants; | 7 | import cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants; |
| 7 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; | 8 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| @@ -25,6 +26,8 @@ import java.io.IOException; | @@ -25,6 +26,8 @@ import java.io.IOException; | ||
| 25 | import java.util.Date; | 26 | import java.util.Date; |
| 26 | import java.util.Map; | 27 | import java.util.Map; |
| 27 | 28 | ||
| 29 | +import static cn.iocoder.yudao.framework.common.util.json.JsonUtils.*; | ||
| 30 | + | ||
| 28 | /** | 31 | /** |
| 29 | * API 访问日志 Filter | 32 | * API 访问日志 Filter |
| 30 | * | 33 | * |
| @@ -42,7 +45,8 @@ public class ApiAccessLogFilter extends OncePerRequestFilter { | @@ -42,7 +45,8 @@ public class ApiAccessLogFilter extends OncePerRequestFilter { | ||
| 42 | @Override | 45 | @Override |
| 43 | protected boolean shouldNotFilter(HttpServletRequest request) { | 46 | protected boolean shouldNotFilter(HttpServletRequest request) { |
| 44 | // 只过滤 API 请求的地址 | 47 | // 只过滤 API 请求的地址 |
| 45 | - return !request.getRequestURI().startsWith(webProperties.getApiPrefix()); | 48 | + return !StrUtil.startWithAny(request.getRequestURI(), webProperties.getAppApi().getPrefix(), |
| 49 | + webProperties.getAppApi().getPrefix()); | ||
| 46 | } | 50 | } |
| 47 | 51 | ||
| 48 | @Override | 52 | @Override |
| @@ -73,7 +77,7 @@ public class ApiAccessLogFilter extends OncePerRequestFilter { | @@ -73,7 +77,7 @@ public class ApiAccessLogFilter extends OncePerRequestFilter { | ||
| 73 | this.buildApiAccessLogDTO(accessLog, request, beginTime, queryString, requestBody, ex); | 77 | this.buildApiAccessLogDTO(accessLog, request, beginTime, queryString, requestBody, ex); |
| 74 | apiAccessLogFrameworkService.createApiAccessLogAsync(accessLog); | 78 | apiAccessLogFrameworkService.createApiAccessLogAsync(accessLog); |
| 75 | } catch (Throwable th) { | 79 | } catch (Throwable th) { |
| 76 | - log.error("[createApiAccessLog][url({}) log({}) 发生异常]", request.getRequestURI(), JsonUtils.toJsonString(accessLog), th); | 80 | + log.error("[createApiAccessLog][url({}) log({}) 发生异常]", request.getRequestURI(), toJsonString(accessLog), th); |
| 77 | } | 81 | } |
| 78 | } | 82 | } |
| 79 | 83 | ||
| @@ -99,7 +103,7 @@ public class ApiAccessLogFilter extends OncePerRequestFilter { | @@ -99,7 +103,7 @@ public class ApiAccessLogFilter extends OncePerRequestFilter { | ||
| 99 | accessLog.setApplicationName(applicationName); | 103 | accessLog.setApplicationName(applicationName); |
| 100 | accessLog.setRequestUrl(request.getRequestURI()); | 104 | accessLog.setRequestUrl(request.getRequestURI()); |
| 101 | Map<String, Object> requestParams = MapUtil.<String, Object>builder().put("query", queryString).put("body", requestBody).build(); | 105 | Map<String, Object> requestParams = MapUtil.<String, Object>builder().put("query", queryString).put("body", requestBody).build(); |
| 102 | - accessLog.setRequestParams(JsonUtils.toJsonString(requestParams)); | 106 | + accessLog.setRequestParams(toJsonString(requestParams)); |
| 103 | accessLog.setRequestMethod(request.getMethod()); | 107 | accessLog.setRequestMethod(request.getMethod()); |
| 104 | accessLog.setUserAgent(ServletUtils.getUserAgent(request)); | 108 | accessLog.setUserAgent(ServletUtils.getUserAgent(request)); |
| 105 | accessLog.setUserIp(ServletUtil.getClientIP(request)); | 109 | accessLog.setUserIp(ServletUtil.getClientIP(request)); |
yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/web/config/WebProperties.java
| @@ -5,6 +5,8 @@ import org.springframework.boot.context.properties.ConfigurationProperties; | @@ -5,6 +5,8 @@ import org.springframework.boot.context.properties.ConfigurationProperties; | ||
| 5 | import org.springframework.validation.annotation.Validated; | 5 | import org.springframework.validation.annotation.Validated; |
| 6 | import org.springframework.web.servlet.config.annotation.PathMatchConfigurer; | 6 | import org.springframework.web.servlet.config.annotation.PathMatchConfigurer; |
| 7 | 7 | ||
| 8 | +import javax.validation.Valid; | ||
| 9 | +import javax.validation.constraints.NotEmpty; | ||
| 8 | import javax.validation.constraints.NotNull; | 10 | import javax.validation.constraints.NotNull; |
| 9 | 11 | ||
| 10 | @ConfigurationProperties(prefix = "yudao.web") | 12 | @ConfigurationProperties(prefix = "yudao.web") |
| @@ -12,26 +14,37 @@ import javax.validation.constraints.NotNull; | @@ -12,26 +14,37 @@ import javax.validation.constraints.NotNull; | ||
| 12 | @Data | 14 | @Data |
| 13 | public class WebProperties { | 15 | public class WebProperties { |
| 14 | 16 | ||
| 15 | - /** | ||
| 16 | - * API 前缀,实现所有 Controller 提供的 RESTFul API 的统一前缀 | ||
| 17 | - * | ||
| 18 | - * | ||
| 19 | - * 意义:通过该前缀,避免 Swagger、Actuator 意外通过 Nginx 暴露出来给外部,带来安全性问题 | ||
| 20 | - * 这样,Nginx 只需要配置转发到 /api/* 的所有接口即可。 | ||
| 21 | - * | ||
| 22 | - * @see YudaoWebAutoConfiguration#configurePathMatch(PathMatchConfigurer) | ||
| 23 | - */ | ||
| 24 | - @NotNull(message = "API 前缀不能为空") | ||
| 25 | - private String apiPrefix; | ||
| 26 | - | ||
| 27 | - /** | ||
| 28 | - * Controller 所在包 | ||
| 29 | - * | ||
| 30 | - * 主要目的是,给该 Controller 设置指定的 {@link #apiPrefix} | ||
| 31 | - * | ||
| 32 | - * 因为我们有多个 modules 包里会包含 Controller,所以只需要写到 cn.iocoder.yudao 这样的层级 | ||
| 33 | - */ | ||
| 34 | - @NotNull(message = "Controller 所在包不能为空") | ||
| 35 | - private String controllerPackage; | 17 | + @NotNull(message = "APP API 不能为空") |
| 18 | + private Api appApi; | ||
| 19 | + @NotNull(message = "Admin API 不能为空") | ||
| 20 | + private Api adminApi; | ||
| 21 | + | ||
| 22 | + @Data | ||
| 23 | + @Valid | ||
| 24 | + public static class Api { | ||
| 25 | + | ||
| 26 | + /** | ||
| 27 | + * API 前缀,实现所有 Controller 提供的 RESTFul API 的统一前缀 | ||
| 28 | + * | ||
| 29 | + * | ||
| 30 | + * 意义:通过该前缀,避免 Swagger、Actuator 意外通过 Nginx 暴露出来给外部,带来安全性问题 | ||
| 31 | + * 这样,Nginx 只需要配置转发到 /api/* 的所有接口即可。 | ||
| 32 | + * | ||
| 33 | + * @see YudaoWebAutoConfiguration#configurePathMatch(PathMatchConfigurer) | ||
| 34 | + */ | ||
| 35 | + @NotEmpty(message = "API 前缀不能为空") | ||
| 36 | + private String prefix; | ||
| 37 | + | ||
| 38 | + /** | ||
| 39 | + * Controller 所在包 | ||
| 40 | + * | ||
| 41 | + * 主要目的是,给该 Controller 设置指定的 {@link #prefix} | ||
| 42 | + * | ||
| 43 | + * 因为我们有多个 modules 包里会包含 Controller,所以只需要写到 cn.iocoder.yudao 这样的层级 | ||
| 44 | + */ | ||
| 45 | + @NotEmpty(message = "Controller 所在包不能为空") | ||
| 46 | + private String controller; | ||
| 47 | + | ||
| 48 | + } | ||
| 36 | 49 | ||
| 37 | } | 50 | } |
yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/web/config/YudaoWebAutoConfiguration.java
| @@ -38,10 +38,19 @@ public class YudaoWebAutoConfiguration implements WebMvcConfigurer { | @@ -38,10 +38,19 @@ public class YudaoWebAutoConfiguration implements WebMvcConfigurer { | ||
| 38 | 38 | ||
| 39 | @Override | 39 | @Override |
| 40 | public void configurePathMatch(PathMatchConfigurer configurer) { | 40 | public void configurePathMatch(PathMatchConfigurer configurer) { |
| 41 | - // 设置 API 前缀,仅仅匹配 controller 包下的 | ||
| 42 | - configurer.addPathPrefix(webProperties.getApiPrefix(), clazz -> | ||
| 43 | - clazz.isAnnotationPresent(RestController.class) | ||
| 44 | - && clazz.getPackage().getName().startsWith(webProperties.getControllerPackage())); // 仅仅匹配 controller 包 | 41 | + configurePathMatch(configurer, webProperties.getAdminApi()); |
| 42 | + configurePathMatch(configurer, webProperties.getAppApi()); | ||
| 43 | + } | ||
| 44 | + | ||
| 45 | + /** | ||
| 46 | + * 设置 API 前缀,仅仅匹配 controller 包下的 | ||
| 47 | + * | ||
| 48 | + * @param configurer 配置 | ||
| 49 | + * @param api API 配置 | ||
| 50 | + */ | ||
| 51 | + private void configurePathMatch(PathMatchConfigurer configurer, WebProperties.Api api) { | ||
| 52 | + configurer.addPathPrefix(api.getPrefix(), clazz -> clazz.isAnnotationPresent(RestController.class) | ||
| 53 | + && clazz.getPackage().getName().startsWith(api.getController())); // 仅仅匹配 controller 包 | ||
| 45 | } | 54 | } |
| 46 | 55 | ||
| 47 | @Bean | 56 | @Bean |
yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/user/MemberUserApi.java renamed to yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/user/UserApi.java
| 1 | package cn.iocoder.yudao.module.member.api.user; | 1 | package cn.iocoder.yudao.module.member.api.user; |
| 2 | 2 | ||
| 3 | -import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; | 3 | +import cn.iocoder.yudao.module.member.api.user.dto.UserRespDTO; |
| 4 | 4 | ||
| 5 | /** | 5 | /** |
| 6 | * 会员用户的 API 接口 | 6 | * 会员用户的 API 接口 |
| 7 | * | 7 | * |
| 8 | * @author 芋道源码 | 8 | * @author 芋道源码 |
| 9 | */ | 9 | */ |
| 10 | -public interface MemberUserApi { | 10 | +public interface UserApi { |
| 11 | 11 | ||
| 12 | /** | 12 | /** |
| 13 | * 获得会员用户信息 | 13 | * 获得会员用户信息 |
| @@ -15,6 +15,6 @@ public interface MemberUserApi { | @@ -15,6 +15,6 @@ public interface MemberUserApi { | ||
| 15 | * @param id 用户编号 | 15 | * @param id 用户编号 |
| 16 | * @return 用户信息 | 16 | * @return 用户信息 |
| 17 | */ | 17 | */ |
| 18 | - MemberUserRespDTO getMemberUser(Long id); | 18 | + UserRespDTO getUser(Long id); |
| 19 | 19 | ||
| 20 | } | 20 | } |
yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/user/dto/MemberUserRespDTO.java renamed to yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/user/dto/UserRespDTO.java
| @@ -7,7 +7,7 @@ import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | @@ -7,7 +7,7 @@ import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | ||
| 7 | * | 7 | * |
| 8 | * @author 芋道源码 | 8 | * @author 芋道源码 |
| 9 | */ | 9 | */ |
| 10 | -public class MemberUserRespDTO { | 10 | +public class UserRespDTO { |
| 11 | 11 | ||
| 12 | /** | 12 | /** |
| 13 | * 用户ID | 13 | * 用户ID |
yudao-module-member/yudao-module-member-impl/pom.xml
| @@ -18,16 +18,18 @@ | @@ -18,16 +18,18 @@ | ||
| 18 | </description> | 18 | </description> |
| 19 | 19 | ||
| 20 | <dependencies> | 20 | <dependencies> |
| 21 | - <!-- 业务组件 --> | ||
| 22 | <dependency> | 21 | <dependency> |
| 23 | <groupId>cn.iocoder.boot</groupId> | 22 | <groupId>cn.iocoder.boot</groupId> |
| 24 | - <artifactId>yudao-core-service</artifactId> | 23 | + <artifactId>yudao-module-member-api</artifactId> |
| 24 | + <version>${revision}</version> | ||
| 25 | </dependency> | 25 | </dependency> |
| 26 | 26 | ||
| 27 | + <!-- 业务组件 --> | ||
| 27 | <dependency> | 28 | <dependency> |
| 28 | <groupId>cn.iocoder.boot</groupId> | 29 | <groupId>cn.iocoder.boot</groupId> |
| 29 | - <artifactId>yudao-spring-boot-starter-biz-dict</artifactId> | 30 | + <artifactId>yudao-core-service</artifactId> |
| 30 | </dependency> | 31 | </dependency> |
| 32 | + | ||
| 31 | <dependency> | 33 | <dependency> |
| 32 | <groupId>cn.iocoder.boot</groupId> | 34 | <groupId>cn.iocoder.boot</groupId> |
| 33 | <artifactId>yudao-spring-boot-starter-biz-sms</artifactId> | 35 | <artifactId>yudao-spring-boot-starter-biz-sms</artifactId> |
| @@ -40,11 +42,6 @@ | @@ -40,11 +42,6 @@ | ||
| 40 | <!-- Web 相关 --> | 42 | <!-- Web 相关 --> |
| 41 | <dependency> | 43 | <dependency> |
| 42 | <groupId>cn.iocoder.boot</groupId> | 44 | <groupId>cn.iocoder.boot</groupId> |
| 43 | - <artifactId>yudao-spring-boot-starter-web</artifactId> | ||
| 44 | - </dependency> | ||
| 45 | - | ||
| 46 | - <dependency> | ||
| 47 | - <groupId>cn.iocoder.boot</groupId> | ||
| 48 | <artifactId>yudao-spring-boot-starter-security</artifactId> | 45 | <artifactId>yudao-spring-boot-starter-security</artifactId> |
| 49 | </dependency> | 46 | </dependency> |
| 50 | 47 | ||
| @@ -59,32 +56,12 @@ | @@ -59,32 +56,12 @@ | ||
| 59 | <artifactId>yudao-spring-boot-starter-redis</artifactId> | 56 | <artifactId>yudao-spring-boot-starter-redis</artifactId> |
| 60 | </dependency> | 57 | </dependency> |
| 61 | 58 | ||
| 62 | - <!-- Config 配置中心相关 --> | ||
| 63 | - <dependency> | ||
| 64 | - <groupId>cn.iocoder.boot</groupId> | ||
| 65 | - <artifactId>yudao-spring-boot-starter-config</artifactId> | ||
| 66 | - </dependency> | ||
| 67 | - | ||
| 68 | - <!-- Job 定时任务相关 --> | ||
| 69 | - | ||
| 70 | <!-- 消息队列相关 --> | 59 | <!-- 消息队列相关 --> |
| 71 | <dependency> | 60 | <dependency> |
| 72 | <groupId>cn.iocoder.boot</groupId> | 61 | <groupId>cn.iocoder.boot</groupId> |
| 73 | <artifactId>yudao-spring-boot-starter-mq</artifactId> | 62 | <artifactId>yudao-spring-boot-starter-mq</artifactId> |
| 74 | </dependency> | 63 | </dependency> |
| 75 | 64 | ||
| 76 | - <!-- 服务保障相关 --> | ||
| 77 | - <dependency> | ||
| 78 | - <groupId>cn.iocoder.boot</groupId> | ||
| 79 | - <artifactId>yudao-spring-boot-starter-protection</artifactId> | ||
| 80 | - </dependency> | ||
| 81 | - | ||
| 82 | - <!-- 监控相关 --> | ||
| 83 | - <dependency> | ||
| 84 | - <groupId>cn.iocoder.boot</groupId> | ||
| 85 | - <artifactId>yudao-spring-boot-starter-monitor</artifactId> | ||
| 86 | - </dependency> | ||
| 87 | - | ||
| 88 | <!-- Test 测试相关 --> | 65 | <!-- Test 测试相关 --> |
| 89 | <dependency> | 66 | <dependency> |
| 90 | <groupId>cn.iocoder.boot</groupId> | 67 | <groupId>cn.iocoder.boot</groupId> |
yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/api/package-info.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.member.api; |
yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/api/user/UserApiImpl.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.member.api.user; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.module.member.api.user.dto.UserRespDTO; | ||
| 4 | +import cn.iocoder.yudao.module.member.convert.user.UserConvert; | ||
| 5 | +import cn.iocoder.yudao.module.member.dal.dataobject.user.UserDO; | ||
| 6 | +import cn.iocoder.yudao.module.member.service.user.UserService; | ||
| 7 | +import org.springframework.stereotype.Service; | ||
| 8 | +import org.springframework.validation.annotation.Validated; | ||
| 9 | + | ||
| 10 | +import javax.annotation.Resource; | ||
| 11 | + | ||
| 12 | +/** | ||
| 13 | + * 会员用户的 API 实现类 | ||
| 14 | + * | ||
| 15 | + * @author 芋道源码 | ||
| 16 | + */ | ||
| 17 | +@Service | ||
| 18 | +@Validated | ||
| 19 | +public class UserApiImpl implements UserApi { | ||
| 20 | + | ||
| 21 | + @Resource | ||
| 22 | + private UserService userService; | ||
| 23 | + | ||
| 24 | + @Override | ||
| 25 | + public UserRespDTO getUser(Long id) { | ||
| 26 | + UserDO user = userService.getUser(id); | ||
| 27 | + return UserConvert.INSTANCE.convert2(user); | ||
| 28 | + } | ||
| 29 | + | ||
| 30 | +} |
yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/controller/admin/address/package-info.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.member.controller.admin.address; |
yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/controller/admin/user/package-info.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.member.controller.admin.user; |
yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/controller/app/address/package-info.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.member.controller.app.address; |
yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/controller/app/auth/AppAuthController.java
| @@ -5,8 +5,8 @@ import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; | @@ -5,8 +5,8 @@ import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; | ||
| 5 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; | 5 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 6 | import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated; | 6 | import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated; |
| 7 | import cn.iocoder.yudao.module.member.controller.app.auth.vo.*; | 7 | import cn.iocoder.yudao.module.member.controller.app.auth.vo.*; |
| 8 | -import cn.iocoder.yudao.userserver.modules.system.service.auth.SysAuthService; | ||
| 9 | -import cn.iocoder.yudao.userserver.modules.system.service.sms.SysSmsCodeService; | 8 | +import cn.iocoder.yudao.module.member.service.auth.AuthService; |
| 9 | +import cn.iocoder.yudao.module.member.service.sms.SysSmsCodeService; | ||
| 10 | import io.swagger.annotations.Api; | 10 | import io.swagger.annotations.Api; |
| 11 | import io.swagger.annotations.ApiImplicitParam; | 11 | import io.swagger.annotations.ApiImplicitParam; |
| 12 | import io.swagger.annotations.ApiImplicitParams; | 12 | import io.swagger.annotations.ApiImplicitParams; |
| @@ -31,7 +31,8 @@ import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUti | @@ -31,7 +31,8 @@ import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUti | ||
| 31 | public class AppAuthController { | 31 | public class AppAuthController { |
| 32 | 32 | ||
| 33 | @Resource | 33 | @Resource |
| 34 | - private SysAuthService authService; | 34 | + private AuthService authService; |
| 35 | + | ||
| 35 | @Resource | 36 | @Resource |
| 36 | private SysSmsCodeService smsCodeService; | 37 | private SysSmsCodeService smsCodeService; |
| 37 | @Resource | 38 | @Resource |
| @@ -55,7 +56,7 @@ public class AppAuthController { | @@ -55,7 +56,7 @@ public class AppAuthController { | ||
| 55 | 56 | ||
| 56 | @PostMapping("/send-sms-code") | 57 | @PostMapping("/send-sms-code") |
| 57 | @ApiOperation(value = "发送手机验证码") | 58 | @ApiOperation(value = "发送手机验证码") |
| 58 | - public CommonResult<Boolean> sendSmsCode(@RequestBody @Valid SysAuthSendSmsReqVO reqVO) { | 59 | + public CommonResult<Boolean> sendSmsCode(@RequestBody @Valid AppAuthSendSmsReqVO reqVO) { |
| 59 | smsCodeService.sendSmsCode(reqVO.getMobile(), reqVO.getScene(), getClientIP()); | 60 | smsCodeService.sendSmsCode(reqVO.getMobile(), reqVO.getScene(), getClientIP()); |
| 60 | return success(true); | 61 | return success(true); |
| 61 | } | 62 | } |
yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/controller/app/auth/vo/AppAuthCheckCodeReqVO.java
| @@ -2,7 +2,7 @@ package cn.iocoder.yudao.module.member.controller.app.auth.vo; | @@ -2,7 +2,7 @@ package cn.iocoder.yudao.module.member.controller.app.auth.vo; | ||
| 2 | 2 | ||
| 3 | import cn.iocoder.yudao.framework.common.validation.InEnum; | 3 | import cn.iocoder.yudao.framework.common.validation.InEnum; |
| 4 | import cn.iocoder.yudao.framework.common.validation.Mobile; | 4 | import cn.iocoder.yudao.framework.common.validation.Mobile; |
| 5 | -import cn.iocoder.yudao.userserver.modules.system.enums.sms.SysSmsSceneEnum; | 5 | +import cn.iocoder.yudao.module.member.enums.sms.SysSmsSceneEnum; |
| 6 | import io.swagger.annotations.ApiModel; | 6 | import io.swagger.annotations.ApiModel; |
| 7 | import io.swagger.annotations.ApiModelProperty; | 7 | import io.swagger.annotations.ApiModelProperty; |
| 8 | import lombok.AllArgsConstructor; | 8 | import lombok.AllArgsConstructor; |
| @@ -15,6 +15,7 @@ import javax.validation.constraints.NotBlank; | @@ -15,6 +15,7 @@ import javax.validation.constraints.NotBlank; | ||
| 15 | import javax.validation.constraints.NotNull; | 15 | import javax.validation.constraints.NotNull; |
| 16 | import javax.validation.constraints.Pattern; | 16 | import javax.validation.constraints.Pattern; |
| 17 | 17 | ||
| 18 | +// TODO 芋艿:code review 相关逻辑 | ||
| 18 | @ApiModel("APP 端 - 校验验证码 Request VO") | 19 | @ApiModel("APP 端 - 校验验证码 Request VO") |
| 19 | @Data | 20 | @Data |
| 20 | @NoArgsConstructor | 21 | @NoArgsConstructor |
| @@ -37,4 +38,5 @@ public class AppAuthCheckCodeReqVO { | @@ -37,4 +38,5 @@ public class AppAuthCheckCodeReqVO { | ||
| 37 | @NotNull(message = "发送场景不能为空") | 38 | @NotNull(message = "发送场景不能为空") |
| 38 | @InEnum(SysSmsSceneEnum.class) | 39 | @InEnum(SysSmsSceneEnum.class) |
| 39 | private Integer scene; | 40 | private Integer scene; |
| 41 | + | ||
| 40 | } | 42 | } |
yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/controller/app/auth/vo/AppAuthResetPasswordReqVO.java
| @@ -13,6 +13,7 @@ import javax.validation.constraints.NotBlank; | @@ -13,6 +13,7 @@ import javax.validation.constraints.NotBlank; | ||
| 13 | import javax.validation.constraints.NotEmpty; | 13 | import javax.validation.constraints.NotEmpty; |
| 14 | import javax.validation.constraints.Pattern; | 14 | import javax.validation.constraints.Pattern; |
| 15 | 15 | ||
| 16 | +// TODO 芋艿:code review 相关逻辑 | ||
| 16 | @ApiModel("APP 端 - 重置密码 Request VO") | 17 | @ApiModel("APP 端 - 重置密码 Request VO") |
| 17 | @Data | 18 | @Data |
| 18 | @NoArgsConstructor | 19 | @NoArgsConstructor |
yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/controller/app/auth/vo/AppSendSmsReqVO.java renamed to yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/controller/app/auth/vo/AppAuthSendSmsReqVO.java
| @@ -2,7 +2,7 @@ package cn.iocoder.yudao.module.member.controller.app.auth.vo; | @@ -2,7 +2,7 @@ package cn.iocoder.yudao.module.member.controller.app.auth.vo; | ||
| 2 | 2 | ||
| 3 | import cn.iocoder.yudao.framework.common.validation.InEnum; | 3 | import cn.iocoder.yudao.framework.common.validation.InEnum; |
| 4 | import cn.iocoder.yudao.framework.common.validation.Mobile; | 4 | import cn.iocoder.yudao.framework.common.validation.Mobile; |
| 5 | -import cn.iocoder.yudao.userserver.modules.system.enums.sms.SysSmsSceneEnum; | 5 | +import cn.iocoder.yudao.module.member.enums.sms.SysSmsSceneEnum; |
| 6 | import io.swagger.annotations.ApiModel; | 6 | import io.swagger.annotations.ApiModel; |
| 7 | import io.swagger.annotations.ApiModelProperty; | 7 | import io.swagger.annotations.ApiModelProperty; |
| 8 | import lombok.Data; | 8 | import lombok.Data; |
| @@ -13,7 +13,7 @@ import javax.validation.constraints.NotNull; | @@ -13,7 +13,7 @@ import javax.validation.constraints.NotNull; | ||
| 13 | @ApiModel("APP 端 - 发送手机验证码 Response VO") | 13 | @ApiModel("APP 端 - 发送手机验证码 Response VO") |
| 14 | @Data | 14 | @Data |
| 15 | @Accessors(chain = true) | 15 | @Accessors(chain = true) |
| 16 | -public class AppSendSmsReqVO { | 16 | +public class AppAuthSendSmsReqVO { |
| 17 | 17 | ||
| 18 | @ApiModelProperty(value = "手机号", example = "15601691234") | 18 | @ApiModelProperty(value = "手机号", example = "15601691234") |
| 19 | @Mobile | 19 | @Mobile |
yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/controller/app/auth/vo/AppAuthUpdatePasswordReqVO.java
| @@ -11,6 +11,7 @@ import org.hibernate.validator.constraints.Length; | @@ -11,6 +11,7 @@ import org.hibernate.validator.constraints.Length; | ||
| 11 | import javax.validation.constraints.NotBlank; | 11 | import javax.validation.constraints.NotBlank; |
| 12 | import javax.validation.constraints.NotEmpty; | 12 | import javax.validation.constraints.NotEmpty; |
| 13 | 13 | ||
| 14 | +// TODO 芋艿:code review 相关逻辑 | ||
| 14 | @ApiModel("APP 端 - 修改密码 Request VO") | 15 | @ApiModel("APP 端 - 修改密码 Request VO") |
| 15 | @Data | 16 | @Data |
| 16 | @NoArgsConstructor | 17 | @NoArgsConstructor |
yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/controller/app/user/AppUserController.java
| 1 | package cn.iocoder.yudao.module.member.controller.app.user; | 1 | package cn.iocoder.yudao.module.member.controller.app.user; |
| 2 | 2 | ||
| 3 | -import cn.iocoder.yudao.userserver.modules.member.controller.user.vo.MbrUserInfoRespVO; | ||
| 4 | -import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil; | ||
| 5 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; | 3 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 6 | import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated; | 4 | import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated; |
| 7 | -import cn.iocoder.yudao.userserver.modules.member.service.user.MbrUserService; | ||
| 8 | -import cn.iocoder.yudao.userserver.modules.member.controller.user.vo.MbrUserUpdateMobileReqVO; | ||
| 9 | -import cn.iocoder.yudao.userserver.modules.system.enums.sms.SysSmsSceneEnum; | ||
| 10 | -import cn.iocoder.yudao.userserver.modules.system.service.sms.SysSmsCodeService; | 5 | +import cn.iocoder.yudao.module.member.controller.app.user.vo.AppUserInfoRespVO; |
| 6 | +import cn.iocoder.yudao.module.member.controller.app.user.vo.AppUserUpdateMobileReqVO; | ||
| 7 | +import cn.iocoder.yudao.module.member.convert.user.UserConvert; | ||
| 8 | +import cn.iocoder.yudao.module.member.dal.dataobject.user.UserDO; | ||
| 9 | +import cn.iocoder.yudao.module.member.service.user.UserService; | ||
| 11 | import io.swagger.annotations.Api; | 10 | import io.swagger.annotations.Api; |
| 12 | import io.swagger.annotations.ApiOperation; | 11 | import io.swagger.annotations.ApiOperation; |
| 13 | import lombok.extern.slf4j.Slf4j; | 12 | import lombok.extern.slf4j.Slf4j; |
| @@ -17,13 +16,12 @@ import org.springframework.web.multipart.MultipartFile; | @@ -17,13 +16,12 @@ import org.springframework.web.multipart.MultipartFile; | ||
| 17 | 16 | ||
| 18 | import javax.annotation.Resource; | 17 | import javax.annotation.Resource; |
| 19 | import javax.validation.Valid; | 18 | import javax.validation.Valid; |
| 20 | - | ||
| 21 | import java.io.IOException; | 19 | import java.io.IOException; |
| 22 | 20 | ||
| 21 | +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.*; | ||
| 23 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | 22 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| 24 | -import static cn.iocoder.yudao.framework.common.util.servlet.ServletUtils.getClientIP; | ||
| 25 | import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; | 23 | import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; |
| 26 | -import static cn.iocoder.yudao.userserver.modules.member.enums.MbrErrorCodeConstants.FILE_IS_EMPTY; | 24 | +import static cn.iocoder.yudao.module.member.enums.MemberErrorCodeConstants.FILE_IS_EMPTY; |
| 27 | 25 | ||
| 28 | @Api(tags = "APP 端 - 用户个人中心") | 26 | @Api(tags = "APP 端 - 用户个人中心") |
| 29 | @RestController | 27 | @RestController |
| @@ -33,39 +31,40 @@ import static cn.iocoder.yudao.userserver.modules.member.enums.MbrErrorCodeConst | @@ -33,39 +31,40 @@ import static cn.iocoder.yudao.userserver.modules.member.enums.MbrErrorCodeConst | ||
| 33 | public class AppUserController { | 31 | public class AppUserController { |
| 34 | 32 | ||
| 35 | @Resource | 33 | @Resource |
| 36 | - private MbrUserService userService; | 34 | + private UserService userService; |
| 37 | 35 | ||
| 38 | @PutMapping("/update-nickname") | 36 | @PutMapping("/update-nickname") |
| 39 | @ApiOperation("修改用户昵称") | 37 | @ApiOperation("修改用户昵称") |
| 40 | @PreAuthenticated | 38 | @PreAuthenticated |
| 41 | - public CommonResult<Boolean> updateNickname(@RequestParam("nickname") String nickname) { | ||
| 42 | - userService.updateNickname(getLoginUserId(), nickname); | 39 | + public CommonResult<Boolean> updateUserNickname(@RequestParam("nickname") String nickname) { |
| 40 | + userService.updateUserNickname(getLoginUserId(), nickname); | ||
| 43 | return success(true); | 41 | return success(true); |
| 44 | } | 42 | } |
| 45 | 43 | ||
| 46 | @PutMapping("/update-avatar") | 44 | @PutMapping("/update-avatar") |
| 47 | @ApiOperation("修改用户头像") | 45 | @ApiOperation("修改用户头像") |
| 48 | @PreAuthenticated | 46 | @PreAuthenticated |
| 49 | - public CommonResult<String> updateAvatar(@RequestParam("avatarFile") MultipartFile file) throws IOException { | 47 | + public CommonResult<String> updateUserAvatar(@RequestParam("avatarFile") MultipartFile file) throws IOException { |
| 50 | if (file.isEmpty()) { | 48 | if (file.isEmpty()) { |
| 51 | - throw ServiceExceptionUtil.exception(MbrErrorCodeConstants.FILE_IS_EMPTY); | 49 | + throw exception(FILE_IS_EMPTY); |
| 52 | } | 50 | } |
| 53 | - String avatar = userService.updateAvatar(getLoginUserId(), file.getInputStream()); | 51 | + String avatar = userService.updateUserAvatar(getLoginUserId(), file.getInputStream()); |
| 54 | return success(avatar); | 52 | return success(avatar); |
| 55 | } | 53 | } |
| 56 | 54 | ||
| 57 | @GetMapping("/get") | 55 | @GetMapping("/get") |
| 58 | @ApiOperation("获得基本信息") | 56 | @ApiOperation("获得基本信息") |
| 59 | @PreAuthenticated | 57 | @PreAuthenticated |
| 60 | - public CommonResult<MbrUserInfoRespVO> getUserInfo() { | ||
| 61 | - return success(userService.getUserInfo(getLoginUserId())); | 58 | + public CommonResult<AppUserInfoRespVO> getUserInfo() { |
| 59 | + UserDO user = userService.getUser(getLoginUserId()); | ||
| 60 | + return success(UserConvert.INSTANCE.convert(user)); | ||
| 62 | } | 61 | } |
| 63 | 62 | ||
| 64 | @PostMapping("/update-mobile") | 63 | @PostMapping("/update-mobile") |
| 65 | @ApiOperation(value = "修改用户手机") | 64 | @ApiOperation(value = "修改用户手机") |
| 66 | @PreAuthenticated | 65 | @PreAuthenticated |
| 67 | - public CommonResult<Boolean> updateMobile(@RequestBody @Valid MbrUserUpdateMobileReqVO reqVO) { | ||
| 68 | - userService.updateMobile(getLoginUserId(), reqVO); | 66 | + public CommonResult<Boolean> updateMobile(@RequestBody @Valid AppUserUpdateMobileReqVO reqVO) { |
| 67 | + userService.updateUserMobile(getLoginUserId(), reqVO); | ||
| 69 | return success(true); | 68 | return success(true); |
| 70 | } | 69 | } |
| 71 | 70 |
yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/controller/app/user/vo/AppUserUpdateMobileReqVO.java
| @@ -38,6 +38,8 @@ public class AppUserUpdateMobileReqVO { | @@ -38,6 +38,8 @@ public class AppUserUpdateMobileReqVO { | ||
| 38 | @Pattern(regexp = "^[0-9]+$", message = "手机验证码必须都是数字") | 38 | @Pattern(regexp = "^[0-9]+$", message = "手机验证码必须都是数字") |
| 39 | private String oldCode; | 39 | private String oldCode; |
| 40 | 40 | ||
| 41 | + // TODO @芋艿:oldMobile 应该不用传递 | ||
| 42 | + | ||
| 41 | @ApiModelProperty(value = "原手机号",required = true,example = "15823654487") | 43 | @ApiModelProperty(value = "原手机号",required = true,example = "15823654487") |
| 42 | @NotBlank(message = "手机号不能为空") | 44 | @NotBlank(message = "手机号不能为空") |
| 43 | @Length(min = 8, max = 11, message = "手机号码长度为 8-11 位") | 45 | @Length(min = 8, max = 11, message = "手机号码长度为 8-11 位") |
yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/convert/auth/SysAuthConvert.java renamed to yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/convert/auth/AuthConvert.java
| 1 | package cn.iocoder.yudao.module.member.convert.auth; | 1 | package cn.iocoder.yudao.module.member.convert.auth; |
| 2 | 2 | ||
| 3 | -import cn.iocoder.yudao.coreservice.modules.member.dal.dataobject.user.MbrUserDO; | ||
| 4 | import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; | 3 | import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; |
| 5 | import cn.iocoder.yudao.framework.security.core.LoginUser; | 4 | import cn.iocoder.yudao.framework.security.core.LoginUser; |
| 5 | +import cn.iocoder.yudao.module.member.dal.dataobject.user.UserDO; | ||
| 6 | import org.mapstruct.Mapper; | 6 | import org.mapstruct.Mapper; |
| 7 | import org.mapstruct.Mapping; | 7 | import org.mapstruct.Mapping; |
| 8 | import org.mapstruct.factory.Mappers; | 8 | import org.mapstruct.factory.Mappers; |
| 9 | 9 | ||
| 10 | @Mapper | 10 | @Mapper |
| 11 | -public interface SysAuthConvert { | 11 | +public interface AuthConvert { |
| 12 | 12 | ||
| 13 | - SysAuthConvert INSTANCE = Mappers.getMapper(SysAuthConvert.class); | 13 | + AuthConvert INSTANCE = Mappers.getMapper(AuthConvert.class); |
| 14 | 14 | ||
| 15 | @Mapping(source = "mobile", target = "username") | 15 | @Mapping(source = "mobile", target = "username") |
| 16 | - LoginUser convert0(MbrUserDO bean); | 16 | + LoginUser convert0(UserDO bean); |
| 17 | 17 | ||
| 18 | - default LoginUser convert(MbrUserDO bean) { | 18 | + default LoginUser convert(UserDO bean) { |
| 19 | // 目的,为了设置 UserTypeEnum.MEMBER.getValue() | 19 | // 目的,为了设置 UserTypeEnum.MEMBER.getValue() |
| 20 | return convert0(bean).setUserType(UserTypeEnum.MEMBER.getValue()); | 20 | return convert0(bean).setUserType(UserTypeEnum.MEMBER.getValue()); |
| 21 | } | 21 | } |
yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/convert/user/UserConvert.java
| 1 | package cn.iocoder.yudao.module.member.convert.user; | 1 | package cn.iocoder.yudao.module.member.convert.user; |
| 2 | 2 | ||
| 3 | -import cn.iocoder.yudao.module.member.dal.dataobject.user.MemberUserDO; | 3 | +import cn.iocoder.yudao.module.member.api.user.dto.UserRespDTO; |
| 4 | +import cn.iocoder.yudao.module.member.controller.app.user.vo.AppUserInfoRespVO; | ||
| 5 | +import cn.iocoder.yudao.module.member.dal.dataobject.user.UserDO; | ||
| 4 | import org.mapstruct.Mapper; | 6 | import org.mapstruct.Mapper; |
| 5 | import org.mapstruct.factory.Mappers; | 7 | import org.mapstruct.factory.Mappers; |
| 6 | 8 | ||
| @@ -9,6 +11,7 @@ public interface UserConvert { | @@ -9,6 +11,7 @@ public interface UserConvert { | ||
| 9 | 11 | ||
| 10 | UserConvert INSTANCE = Mappers.getMapper(UserConvert.class); | 12 | UserConvert INSTANCE = Mappers.getMapper(UserConvert.class); |
| 11 | 13 | ||
| 12 | - AppUserInfoRespVO convert(MemberUserDO bean); | 14 | + AppUserInfoRespVO convert(UserDO bean); |
| 13 | 15 | ||
| 16 | + UserRespDTO convert2(UserDO bean); | ||
| 14 | } | 17 | } |
yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/dal/dataobject/user/MemberUserDO.java renamed to yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/dal/dataobject/user/UserDO.java
| @@ -10,19 +10,19 @@ import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; | @@ -10,19 +10,19 @@ import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; | ||
| 10 | import java.util.Date; | 10 | import java.util.Date; |
| 11 | 11 | ||
| 12 | /** | 12 | /** |
| 13 | - * 会员中心的用户 DO | 13 | + * 会员用户 DO |
| 14 | * | 14 | * |
| 15 | * uk_mobile 索引:基于 {@link #mobile} 字段 | 15 | * uk_mobile 索引:基于 {@link #mobile} 字段 |
| 16 | * | 16 | * |
| 17 | * @author 芋道源码 | 17 | * @author 芋道源码 |
| 18 | */ | 18 | */ |
| 19 | -@TableName(value = "member_user", autoResultMap = true) | 19 | +@TableName(value = "mbr_user", autoResultMap = true) |
| 20 | @Data | 20 | @Data |
| 21 | @EqualsAndHashCode(callSuper = true) | 21 | @EqualsAndHashCode(callSuper = true) |
| 22 | @Builder | 22 | @Builder |
| 23 | @NoArgsConstructor | 23 | @NoArgsConstructor |
| 24 | @AllArgsConstructor | 24 | @AllArgsConstructor |
| 25 | -public class MemberUserDO extends TenantBaseDO { | 25 | +public class UserDO extends TenantBaseDO { |
| 26 | 26 | ||
| 27 | /** | 27 | /** |
| 28 | * 用户ID | 28 | * 用户ID |
yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/sms/SysSmsCodeMapper.java
| @@ -3,10 +3,9 @@ package cn.iocoder.yudao.module.member.dal.mysql.sms; | @@ -3,10 +3,9 @@ package cn.iocoder.yudao.module.member.dal.mysql.sms; | ||
| 3 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | 3 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; |
| 4 | import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX; | 4 | import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX; |
| 5 | import cn.iocoder.yudao.module.member.dal.dataobject.sms.SysSmsCodeDO; | 5 | import cn.iocoder.yudao.module.member.dal.dataobject.sms.SysSmsCodeDO; |
| 6 | -import cn.iocoder.yudao.userserver.modules.system.dal.dataobject.sms.SysSmsCodeDO; | ||
| 7 | import org.apache.ibatis.annotations.Mapper; | 6 | import org.apache.ibatis.annotations.Mapper; |
| 8 | 7 | ||
| 9 | -// TODO @芋艿: | 8 | +// TODO @芋艿:拿到 system 模块下 |
| 10 | @Mapper | 9 | @Mapper |
| 11 | public interface SysSmsCodeMapper extends BaseMapperX<SysSmsCodeDO> { | 10 | public interface SysSmsCodeMapper extends BaseMapperX<SysSmsCodeDO> { |
| 12 | 11 |
yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/user/MbrUserMapper.java renamed to yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/user/UserMapper.java
| 1 | package cn.iocoder.yudao.module.member.dal.mysql.user; | 1 | package cn.iocoder.yudao.module.member.dal.mysql.user; |
| 2 | 2 | ||
| 3 | -import cn.iocoder.yudao.coreservice.modules.member.dal.dataobject.user.MbrUserDO; | ||
| 4 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | 3 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; |
| 4 | +import cn.iocoder.yudao.module.member.dal.dataobject.user.UserDO; | ||
| 5 | import org.apache.ibatis.annotations.Mapper; | 5 | import org.apache.ibatis.annotations.Mapper; |
| 6 | 6 | ||
| 7 | /** | 7 | /** |
| 8 | - * MbrUserDO Mapper | 8 | + * 会员 User Mapper |
| 9 | * | 9 | * |
| 10 | * @author 芋道源码 | 10 | * @author 芋道源码 |
| 11 | */ | 11 | */ |
| 12 | @Mapper | 12 | @Mapper |
| 13 | -public interface MbrUserMapper extends BaseMapperX<MbrUserDO> { | 13 | +public interface UserMapper extends BaseMapperX<UserDO> { |
| 14 | 14 | ||
| 15 | - default MbrUserDO selectByMobile(String mobile) { | ||
| 16 | - return selectOne(MbrUserDO::getMobile, mobile); | 15 | + default UserDO selectByMobile(String mobile) { |
| 16 | + return selectOne(UserDO::getMobile, mobile); | ||
| 17 | } | 17 | } |
| 18 | 18 | ||
| 19 | } | 19 | } |
yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/dal/package-info.java
| @@ -3,5 +3,7 @@ | @@ -3,5 +3,7 @@ | ||
| 3 | * 1. data object:数据对象 | 3 | * 1. data object:数据对象 |
| 4 | * 2. redis:Redis 的 CRUD 操作 | 4 | * 2. redis:Redis 的 CRUD 操作 |
| 5 | * 3. mysql:MySQL 的 CRUD 操作 | 5 | * 3. mysql:MySQL 的 CRUD 操作 |
| 6 | + * | ||
| 7 | + * 其中,MySQL 的表以 mbr_ 作为前缀 | ||
| 6 | */ | 8 | */ |
| 7 | package cn.iocoder.yudao.module.member.dal; | 9 | package cn.iocoder.yudao.module.member.dal; |
yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/dal/redis/package-info.java
yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/framework/security/SecurityConfiguration.java deleted
| 1 | -package cn.iocoder.yudao.module.member.framework.security; | ||
| 2 | - | ||
| 3 | -import cn.iocoder.yudao.framework.web.config.WebProperties; | ||
| 4 | -import org.springframework.context.annotation.Bean; | ||
| 5 | -import org.springframework.context.annotation.Configuration; | ||
| 6 | -import org.springframework.security.config.Customizer; | ||
| 7 | -import org.springframework.security.config.annotation.web.builders.HttpSecurity; | ||
| 8 | -import org.springframework.security.config.annotation.web.configurers.ExpressionUrlAuthorizationConfigurer; | ||
| 9 | - | ||
| 10 | -import javax.annotation.Resource; | ||
| 11 | - | ||
| 12 | -@Configuration | ||
| 13 | -public class SecurityConfiguration { | ||
| 14 | - | ||
| 15 | - @Resource | ||
| 16 | - private WebProperties webProperties; | ||
| 17 | - | ||
| 18 | - @Bean | ||
| 19 | - public Customizer<ExpressionUrlAuthorizationConfigurer<HttpSecurity>.ExpressionInterceptUrlRegistry> authorizeRequestsCustomizer() { | ||
| 20 | - return registry -> { | ||
| 21 | - registry.antMatchers(api("/**")).permitAll(); // 默认 API 都是用户可访问 | ||
| 22 | - }; | ||
| 23 | - } | ||
| 24 | - | ||
| 25 | - private String api(String url) { | ||
| 26 | - return webProperties.getApiPrefix() + url; | ||
| 27 | - } | ||
| 28 | - | ||
| 29 | -} |
yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/service/auth/SysAuthService.java renamed to yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/service/auth/AuthService.java
| @@ -6,13 +6,13 @@ import cn.iocoder.yudao.module.member.controller.app.auth.vo.*; | @@ -6,13 +6,13 @@ import cn.iocoder.yudao.module.member.controller.app.auth.vo.*; | ||
| 6 | import javax.validation.Valid; | 6 | import javax.validation.Valid; |
| 7 | 7 | ||
| 8 | /** | 8 | /** |
| 9 | - * 用户前台的认证 Service 接口 | 9 | + * 会员的认证 Service 接口 |
| 10 | * | 10 | * |
| 11 | * 提供用户的账号密码登录、token 的校验等认证相关的功能 | 11 | * 提供用户的账号密码登录、token 的校验等认证相关的功能 |
| 12 | * | 12 | * |
| 13 | * @author 芋道源码 | 13 | * @author 芋道源码 |
| 14 | */ | 14 | */ |
| 15 | -public interface SysAuthService extends SecurityAuthFrameworkService { | 15 | +public interface AuthService extends SecurityAuthFrameworkService { |
| 16 | 16 | ||
| 17 | /** | 17 | /** |
| 18 | * 手机 + 密码登录 | 18 | * 手机 + 密码登录 |
| @@ -22,7 +22,7 @@ public interface SysAuthService extends SecurityAuthFrameworkService { | @@ -22,7 +22,7 @@ public interface SysAuthService extends SecurityAuthFrameworkService { | ||
| 22 | * @param userAgent 用户 UA | 22 | * @param userAgent 用户 UA |
| 23 | * @return 身份令牌,使用 JWT 方式 | 23 | * @return 身份令牌,使用 JWT 方式 |
| 24 | */ | 24 | */ |
| 25 | - String login(@Valid SysAuthLoginReqVO reqVO, String userIp, String userAgent); | 25 | + String login(@Valid AppAuthLoginReqVO reqVO, String userIp, String userAgent); |
| 26 | 26 | ||
| 27 | /** | 27 | /** |
| 28 | * 手机 + 验证码登陆 | 28 | * 手机 + 验证码登陆 |
| @@ -32,7 +32,7 @@ public interface SysAuthService extends SecurityAuthFrameworkService { | @@ -32,7 +32,7 @@ public interface SysAuthService extends SecurityAuthFrameworkService { | ||
| 32 | * @param userAgent 用户 UA | 32 | * @param userAgent 用户 UA |
| 33 | * @return 身份令牌,使用 JWT 方式 | 33 | * @return 身份令牌,使用 JWT 方式 |
| 34 | */ | 34 | */ |
| 35 | - String smsLogin(@Valid SysAuthSmsLoginReqVO reqVO, String userIp, String userAgent); | 35 | + String smsLogin(@Valid AppAuthSmsLoginReqVO reqVO, String userIp, String userAgent); |
| 36 | 36 | ||
| 37 | 37 | ||
| 38 | /** | 38 | /** |
| @@ -43,7 +43,7 @@ public interface SysAuthService extends SecurityAuthFrameworkService { | @@ -43,7 +43,7 @@ public interface SysAuthService extends SecurityAuthFrameworkService { | ||
| 43 | * @param userAgent 用户 UA | 43 | * @param userAgent 用户 UA |
| 44 | * @return 身份令牌,使用 JWT 方式 | 44 | * @return 身份令牌,使用 JWT 方式 |
| 45 | */ | 45 | */ |
| 46 | - String socialLogin(@Valid MbrAuthSocialLoginReqVO reqVO, String userIp, String userAgent); | 46 | + String socialLogin(@Valid AppAuthSocialLoginReqVO reqVO, String userIp, String userAgent); |
| 47 | 47 | ||
| 48 | /** | 48 | /** |
| 49 | * 社交登录,使用 手机号 + 手机验证码 | 49 | * 社交登录,使用 手机号 + 手机验证码 |
| @@ -53,7 +53,7 @@ public interface SysAuthService extends SecurityAuthFrameworkService { | @@ -53,7 +53,7 @@ public interface SysAuthService extends SecurityAuthFrameworkService { | ||
| 53 | * @param userAgent 用户 UA | 53 | * @param userAgent 用户 UA |
| 54 | * @return 身份令牌,使用 JWT 方式 | 54 | * @return 身份令牌,使用 JWT 方式 |
| 55 | */ | 55 | */ |
| 56 | - String socialLogin2(@Valid MbrAuthSocialLogin2ReqVO reqVO, String userIp, String userAgent); | 56 | + String socialLogin2(@Valid AppAuthSocialLogin2ReqVO reqVO, String userIp, String userAgent); |
| 57 | 57 | ||
| 58 | /** | 58 | /** |
| 59 | * 社交绑定,使用 code 授权码 | 59 | * 社交绑定,使用 code 授权码 |
| @@ -61,18 +61,19 @@ public interface SysAuthService extends SecurityAuthFrameworkService { | @@ -61,18 +61,19 @@ public interface SysAuthService extends SecurityAuthFrameworkService { | ||
| 61 | * @param userId 用户编号 | 61 | * @param userId 用户编号 |
| 62 | * @param reqVO 绑定信息 | 62 | * @param reqVO 绑定信息 |
| 63 | */ | 63 | */ |
| 64 | - void socialBind(Long userId, @Valid MbrAuthSocialBindReqVO reqVO); | 64 | + void socialBind(Long userId, @Valid AppAuthSocialBindReqVO reqVO); |
| 65 | 65 | ||
| 66 | /** | 66 | /** |
| 67 | * 修改用户密码 | 67 | * 修改用户密码 |
| 68 | * @param userId 用户id | 68 | * @param userId 用户id |
| 69 | * @param userReqVO 用户请求实体类 | 69 | * @param userReqVO 用户请求实体类 |
| 70 | */ | 70 | */ |
| 71 | - void updatePassword(Long userId,MbrAuthUpdatePasswordReqVO userReqVO); | 71 | + void updatePassword(Long userId, AppAuthUpdatePasswordReqVO userReqVO); |
| 72 | 72 | ||
| 73 | /** | 73 | /** |
| 74 | * 忘记密码 | 74 | * 忘记密码 |
| 75 | * @param userReqVO 用户请求实体类 | 75 | * @param userReqVO 用户请求实体类 |
| 76 | */ | 76 | */ |
| 77 | - void resetPassword(MbrAuthResetPasswordReqVO userReqVO); | 77 | + void resetPassword(AppAuthResetPasswordReqVO userReqVO); |
| 78 | + | ||
| 78 | } | 79 | } |
yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/service/auth/SysAuthServiceImpl.java renamed to yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/service/auth/AuthServiceImpl.java
| @@ -2,7 +2,6 @@ package cn.iocoder.yudao.module.member.service.auth; | @@ -2,7 +2,6 @@ package cn.iocoder.yudao.module.member.service.auth; | ||
| 2 | 2 | ||
| 3 | import cn.hutool.core.collection.CollUtil; | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | import cn.hutool.core.lang.Assert; | 4 | import cn.hutool.core.lang.Assert; |
| 5 | -import cn.iocoder.yudao.coreservice.modules.member.dal.dataobject.user.MbrUserDO; | ||
| 6 | import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.social.SysSocialUserDO; | 5 | import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.social.SysSocialUserDO; |
| 7 | import cn.iocoder.yudao.coreservice.modules.system.enums.logger.SysLoginLogTypeEnum; | 6 | import cn.iocoder.yudao.coreservice.modules.system.enums.logger.SysLoginLogTypeEnum; |
| 8 | import cn.iocoder.yudao.coreservice.modules.system.enums.logger.SysLoginResultEnum; | 7 | import cn.iocoder.yudao.coreservice.modules.system.enums.logger.SysLoginResultEnum; |
| @@ -12,22 +11,20 @@ import cn.iocoder.yudao.coreservice.modules.system.service.logger.dto.SysLoginLo | @@ -12,22 +11,20 @@ import cn.iocoder.yudao.coreservice.modules.system.service.logger.dto.SysLoginLo | ||
| 12 | import cn.iocoder.yudao.coreservice.modules.system.service.social.SysSocialCoreService; | 11 | import cn.iocoder.yudao.coreservice.modules.system.service.social.SysSocialCoreService; |
| 13 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | 12 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 14 | import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; | 13 | import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; |
| 15 | -import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil; | ||
| 16 | import cn.iocoder.yudao.framework.common.util.monitor.TracerUtils; | 14 | import cn.iocoder.yudao.framework.common.util.monitor.TracerUtils; |
| 17 | import cn.iocoder.yudao.framework.common.util.servlet.ServletUtils; | 15 | import cn.iocoder.yudao.framework.common.util.servlet.ServletUtils; |
| 18 | import cn.iocoder.yudao.framework.security.core.LoginUser; | 16 | import cn.iocoder.yudao.framework.security.core.LoginUser; |
| 19 | -import cn.iocoder.yudao.userserver.modules.member.dal.mysql.user.MbrUserMapper; | ||
| 20 | -import cn.iocoder.yudao.userserver.modules.member.service.user.MbrUserService; | ||
| 21 | import cn.iocoder.yudao.module.member.controller.app.auth.vo.*; | 17 | import cn.iocoder.yudao.module.member.controller.app.auth.vo.*; |
| 22 | -import cn.iocoder.yudao.userserver.modules.system.convert.auth.SysAuthConvert; | ||
| 23 | -import cn.iocoder.yudao.userserver.modules.system.enums.sms.SysSmsSceneEnum; | ||
| 24 | -import cn.iocoder.yudao.userserver.modules.system.service.auth.SysAuthService; | ||
| 25 | -import cn.iocoder.yudao.userserver.modules.system.service.sms.SysSmsCodeService; | 18 | +import cn.iocoder.yudao.module.member.convert.auth.AuthConvert; |
| 19 | +import cn.iocoder.yudao.module.member.dal.dataobject.user.UserDO; | ||
| 20 | +import cn.iocoder.yudao.module.member.dal.mysql.user.UserMapper; | ||
| 21 | +import cn.iocoder.yudao.module.member.enums.sms.SysSmsSceneEnum; | ||
| 22 | +import cn.iocoder.yudao.module.member.service.sms.SysSmsCodeService; | ||
| 23 | +import cn.iocoder.yudao.module.member.service.user.UserService; | ||
| 26 | import com.google.common.annotations.VisibleForTesting; | 24 | import com.google.common.annotations.VisibleForTesting; |
| 27 | import lombok.extern.slf4j.Slf4j; | 25 | import lombok.extern.slf4j.Slf4j; |
| 28 | import me.zhyd.oauth.model.AuthUser; | 26 | import me.zhyd.oauth.model.AuthUser; |
| 29 | import org.springframework.context.annotation.Lazy; | 27 | import org.springframework.context.annotation.Lazy; |
| 30 | -import org.springframework.data.redis.core.StringRedisTemplate; | ||
| 31 | import org.springframework.security.authentication.AuthenticationManager; | 28 | import org.springframework.security.authentication.AuthenticationManager; |
| 32 | import org.springframework.security.authentication.BadCredentialsException; | 29 | import org.springframework.security.authentication.BadCredentialsException; |
| 33 | import org.springframework.security.authentication.DisabledException; | 30 | import org.springframework.security.authentication.DisabledException; |
| @@ -46,25 +43,23 @@ import java.util.Objects; | @@ -46,25 +43,23 @@ import java.util.Objects; | ||
| 46 | 43 | ||
| 47 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | 44 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 48 | import static cn.iocoder.yudao.framework.common.util.servlet.ServletUtils.getClientIP; | 45 | import static cn.iocoder.yudao.framework.common.util.servlet.ServletUtils.getClientIP; |
| 49 | -import static cn.iocoder.yudao.userserver.modules.system.enums.SysErrorCodeConstants.*; | 46 | +import static cn.iocoder.yudao.module.member.enums.SysErrorCodeConstants.*; |
| 50 | 47 | ||
| 51 | /** | 48 | /** |
| 52 | - * Auth Service 实现类 | 49 | + * 会员的认证 Service 接口 |
| 53 | * | 50 | * |
| 54 | * @author 芋道源码 | 51 | * @author 芋道源码 |
| 55 | */ | 52 | */ |
| 56 | @Service | 53 | @Service |
| 57 | @Slf4j | 54 | @Slf4j |
| 58 | -public class SysAuthServiceImpl implements SysAuthService { | ||
| 59 | - | ||
| 60 | - private static final UserTypeEnum USER_TYPE_ENUM = UserTypeEnum.MEMBER; | 55 | +public class AuthServiceImpl implements AuthService { |
| 61 | 56 | ||
| 62 | @Resource | 57 | @Resource |
| 63 | @Lazy // 延迟加载,因为存在相互依赖的问题 | 58 | @Lazy // 延迟加载,因为存在相互依赖的问题 |
| 64 | private AuthenticationManager authenticationManager; | 59 | private AuthenticationManager authenticationManager; |
| 65 | 60 | ||
| 66 | @Resource | 61 | @Resource |
| 67 | - private MbrUserService userService; | 62 | + private UserService userService; |
| 68 | @Resource | 63 | @Resource |
| 69 | private SysSmsCodeService smsCodeService; | 64 | private SysSmsCodeService smsCodeService; |
| 70 | @Resource | 65 | @Resource |
| @@ -75,27 +70,23 @@ public class SysAuthServiceImpl implements SysAuthService { | @@ -75,27 +70,23 @@ public class SysAuthServiceImpl implements SysAuthService { | ||
| 75 | private SysSocialCoreService socialService; | 70 | private SysSocialCoreService socialService; |
| 76 | 71 | ||
| 77 | @Resource | 72 | @Resource |
| 78 | - private StringRedisTemplate stringRedisTemplate; | ||
| 79 | - @Resource | ||
| 80 | private PasswordEncoder passwordEncoder; | 73 | private PasswordEncoder passwordEncoder; |
| 81 | @Resource | 74 | @Resource |
| 82 | - private MbrUserMapper userMapper; | ||
| 83 | - | ||
| 84 | - private static final UserTypeEnum userTypeEnum = UserTypeEnum.MEMBER; | 75 | + private UserMapper userMapper; |
| 85 | 76 | ||
| 86 | @Override | 77 | @Override |
| 87 | public UserDetails loadUserByUsername(String mobile) throws UsernameNotFoundException { | 78 | public UserDetails loadUserByUsername(String mobile) throws UsernameNotFoundException { |
| 88 | // 获取 username 对应的 SysUserDO | 79 | // 获取 username 对应的 SysUserDO |
| 89 | - MbrUserDO user = userService.getUserByMobile(mobile); | 80 | + UserDO user = userService.getUserByMobile(mobile); |
| 90 | if (user == null) { | 81 | if (user == null) { |
| 91 | throw new UsernameNotFoundException(mobile); | 82 | throw new UsernameNotFoundException(mobile); |
| 92 | } | 83 | } |
| 93 | // 创建 LoginUser 对象 | 84 | // 创建 LoginUser 对象 |
| 94 | - return SysAuthConvert.INSTANCE.convert(user); | 85 | + return AuthConvert.INSTANCE.convert(user); |
| 95 | } | 86 | } |
| 96 | 87 | ||
| 97 | @Override | 88 | @Override |
| 98 | - public String login(SysAuthLoginReqVO reqVO, String userIp, String userAgent) { | 89 | + public String login(AppAuthLoginReqVO reqVO, String userIp, String userAgent) { |
| 99 | // 使用手机 + 密码,进行登录。 | 90 | // 使用手机 + 密码,进行登录。 |
| 100 | LoginUser loginUser = this.login0(reqVO.getMobile(), reqVO.getPassword()); | 91 | LoginUser loginUser = this.login0(reqVO.getMobile(), reqVO.getPassword()); |
| 101 | 92 | ||
| @@ -105,80 +96,77 @@ public class SysAuthServiceImpl implements SysAuthService { | @@ -105,80 +96,77 @@ public class SysAuthServiceImpl implements SysAuthService { | ||
| 105 | 96 | ||
| 106 | @Override | 97 | @Override |
| 107 | @Transactional | 98 | @Transactional |
| 108 | - public String smsLogin(SysAuthSmsLoginReqVO reqVO, String userIp, String userAgent) { | 99 | + public String smsLogin(AppAuthSmsLoginReqVO reqVO, String userIp, String userAgent) { |
| 109 | // 校验验证码 | 100 | // 校验验证码 |
| 110 | smsCodeService.useSmsCode(reqVO.getMobile(), SysSmsSceneEnum.LOGIN_BY_SMS.getScene(), | 101 | smsCodeService.useSmsCode(reqVO.getMobile(), SysSmsSceneEnum.LOGIN_BY_SMS.getScene(), |
| 111 | reqVO.getCode(), userIp); | 102 | reqVO.getCode(), userIp); |
| 112 | 103 | ||
| 113 | // 获得获得注册用户 | 104 | // 获得获得注册用户 |
| 114 | - MbrUserDO user = userService.createUserIfAbsent(reqVO.getMobile(), userIp); | 105 | + UserDO user = userService.createUserIfAbsent(reqVO.getMobile(), userIp); |
| 115 | Assert.notNull(user, "获取用户失败,结果为空"); | 106 | Assert.notNull(user, "获取用户失败,结果为空"); |
| 116 | 107 | ||
| 117 | // 执行登陆 | 108 | // 执行登陆 |
| 118 | this.createLoginLog(user.getMobile(), SysLoginLogTypeEnum.LOGIN_SMS, SysLoginResultEnum.SUCCESS); | 109 | this.createLoginLog(user.getMobile(), SysLoginLogTypeEnum.LOGIN_SMS, SysLoginResultEnum.SUCCESS); |
| 119 | - LoginUser loginUser = SysAuthConvert.INSTANCE.convert(user); | 110 | + LoginUser loginUser = AuthConvert.INSTANCE.convert(user); |
| 120 | 111 | ||
| 121 | // 缓存登录用户到 Redis 中,返回 sessionId 编号 | 112 | // 缓存登录用户到 Redis 中,返回 sessionId 编号 |
| 122 | return userSessionCoreService.createUserSession(loginUser, userIp, userAgent); | 113 | return userSessionCoreService.createUserSession(loginUser, userIp, userAgent); |
| 123 | } | 114 | } |
| 124 | 115 | ||
| 125 | @Override | 116 | @Override |
| 126 | - public String socialLogin(MbrAuthSocialLoginReqVO reqVO, String userIp, String userAgent) { | 117 | + public String socialLogin(AppAuthSocialLoginReqVO reqVO, String userIp, String userAgent) { |
| 127 | // 使用 code 授权码,进行登录 | 118 | // 使用 code 授权码,进行登录 |
| 128 | AuthUser authUser = socialService.getAuthUser(reqVO.getType(), reqVO.getCode(), reqVO.getState()); | 119 | AuthUser authUser = socialService.getAuthUser(reqVO.getType(), reqVO.getCode(), reqVO.getState()); |
| 129 | org.springframework.util.Assert.notNull(authUser, "授权用户不为空"); | 120 | org.springframework.util.Assert.notNull(authUser, "授权用户不为空"); |
| 130 | 121 | ||
| 131 | // 如果未绑定 SysSocialUserDO 用户,则无法自动登录,进行报错 | 122 | // 如果未绑定 SysSocialUserDO 用户,则无法自动登录,进行报错 |
| 132 | String unionId = socialService.getAuthUserUnionId(authUser); | 123 | String unionId = socialService.getAuthUserUnionId(authUser); |
| 133 | - List<SysSocialUserDO> socialUsers = socialService.getAllSocialUserList(reqVO.getType(), unionId, USER_TYPE_ENUM); | 124 | + List<SysSocialUserDO> socialUsers = socialService.getAllSocialUserList(reqVO.getType(), unionId, getUserType()); |
| 134 | if (CollUtil.isEmpty(socialUsers)) { | 125 | if (CollUtil.isEmpty(socialUsers)) { |
| 135 | - throw ServiceExceptionUtil.exception(SysErrorCodeConstants.AUTH_THIRD_LOGIN_NOT_BIND); | 126 | + throw exception(AUTH_THIRD_LOGIN_NOT_BIND); |
| 136 | } | 127 | } |
| 137 | 128 | ||
| 138 | // 自动登录 | 129 | // 自动登录 |
| 139 | - MbrUserDO user = userService.getUser(socialUsers.get(0).getUserId()); | 130 | + UserDO user = userService.getUser(socialUsers.get(0).getUserId()); |
| 140 | if (user == null) { | 131 | if (user == null) { |
| 141 | - throw ServiceExceptionUtil.exception(SysErrorCodeConstants.USER_NOT_EXISTS); | 132 | + throw exception(USER_NOT_EXISTS); |
| 142 | } | 133 | } |
| 143 | this.createLoginLog(user.getMobile(), SysLoginLogTypeEnum.LOGIN_SOCIAL, SysLoginResultEnum.SUCCESS); | 134 | this.createLoginLog(user.getMobile(), SysLoginLogTypeEnum.LOGIN_SOCIAL, SysLoginResultEnum.SUCCESS); |
| 144 | 135 | ||
| 145 | // 创建 LoginUser 对象 | 136 | // 创建 LoginUser 对象 |
| 146 | - LoginUser loginUser = SysAuthConvert.INSTANCE.convert(user); | 137 | + LoginUser loginUser = AuthConvert.INSTANCE.convert(user); |
| 147 | 138 | ||
| 148 | // 绑定社交用户(更新) | 139 | // 绑定社交用户(更新) |
| 149 | - socialService.bindSocialUser(loginUser.getId(), reqVO.getType(), authUser, USER_TYPE_ENUM); | 140 | + socialService.bindSocialUser(loginUser.getId(), reqVO.getType(), authUser, getUserType()); |
| 150 | 141 | ||
| 151 | // 缓存登录用户到 Redis 中,返回 sessionId 编号 | 142 | // 缓存登录用户到 Redis 中,返回 sessionId 编号 |
| 152 | return userSessionCoreService.createUserSession(loginUser, userIp, userAgent); | 143 | return userSessionCoreService.createUserSession(loginUser, userIp, userAgent); |
| 153 | } | 144 | } |
| 154 | 145 | ||
| 155 | @Override | 146 | @Override |
| 156 | - public String socialLogin2(MbrAuthSocialLogin2ReqVO reqVO, String userIp, String userAgent) { | 147 | + public String socialLogin2(AppAuthSocialLogin2ReqVO reqVO, String userIp, String userAgent) { |
| 157 | AuthUser authUser = socialService.getAuthUser(reqVO.getType(), reqVO.getCode(), reqVO.getState()); | 148 | AuthUser authUser = socialService.getAuthUser(reqVO.getType(), reqVO.getCode(), reqVO.getState()); |
| 158 | org.springframework.util.Assert.notNull(authUser, "授权用户不为空"); | 149 | org.springframework.util.Assert.notNull(authUser, "授权用户不为空"); |
| 159 | 150 | ||
| 160 | // 使用手机号、手机验证码登录 | 151 | // 使用手机号、手机验证码登录 |
| 161 | - SysAuthSmsLoginReqVO loginReqVO = SysAuthSmsLoginReqVO | ||
| 162 | - .builder() | ||
| 163 | - .mobile(reqVO.getMobile()) | ||
| 164 | - .code(reqVO.getSmsCode()) | ||
| 165 | - .build(); | 152 | + AppAuthSmsLoginReqVO loginReqVO = AppAuthSmsLoginReqVO.builder() |
| 153 | + .mobile(reqVO.getMobile()).code(reqVO.getSmsCode()).build(); | ||
| 166 | String sessionId = this.smsLogin(loginReqVO, userIp, userAgent); | 154 | String sessionId = this.smsLogin(loginReqVO, userIp, userAgent); |
| 167 | LoginUser loginUser = userSessionCoreService.getLoginUser(sessionId); | 155 | LoginUser loginUser = userSessionCoreService.getLoginUser(sessionId); |
| 168 | 156 | ||
| 169 | // 绑定社交用户(新增) | 157 | // 绑定社交用户(新增) |
| 170 | - socialService.bindSocialUser(loginUser.getId(), reqVO.getType(), authUser, USER_TYPE_ENUM); | 158 | + socialService.bindSocialUser(loginUser.getId(), reqVO.getType(), authUser, getUserType()); |
| 171 | return sessionId; | 159 | return sessionId; |
| 172 | } | 160 | } |
| 173 | 161 | ||
| 174 | @Override | 162 | @Override |
| 175 | - public void socialBind(Long userId, MbrAuthSocialBindReqVO reqVO) { | 163 | + public void socialBind(Long userId, AppAuthSocialBindReqVO reqVO) { |
| 176 | // 使用 code 授权码,进行登录 | 164 | // 使用 code 授权码,进行登录 |
| 177 | AuthUser authUser = socialService.getAuthUser(reqVO.getType(), reqVO.getCode(), reqVO.getState()); | 165 | AuthUser authUser = socialService.getAuthUser(reqVO.getType(), reqVO.getCode(), reqVO.getState()); |
| 178 | org.springframework.util.Assert.notNull(authUser, "授权用户不为空"); | 166 | org.springframework.util.Assert.notNull(authUser, "授权用户不为空"); |
| 179 | 167 | ||
| 180 | // 绑定社交用户(新增) | 168 | // 绑定社交用户(新增) |
| 181 | - socialService.bindSocialUser(userId, reqVO.getType(), authUser, USER_TYPE_ENUM); | 169 | + socialService.bindSocialUser(userId, reqVO.getType(), authUser, getUserType()); |
| 182 | } | 170 | } |
| 183 | 171 | ||
| 184 | private LoginUser login0(String username, String password) { | 172 | private LoginUser login0(String username, String password) { |
| @@ -191,14 +179,14 @@ public class SysAuthServiceImpl implements SysAuthService { | @@ -191,14 +179,14 @@ public class SysAuthServiceImpl implements SysAuthService { | ||
| 191 | authentication = authenticationManager.authenticate(new UsernamePasswordAuthenticationToken(username, password)); | 179 | authentication = authenticationManager.authenticate(new UsernamePasswordAuthenticationToken(username, password)); |
| 192 | } catch (BadCredentialsException badCredentialsException) { | 180 | } catch (BadCredentialsException badCredentialsException) { |
| 193 | this.createLoginLog(username, logTypeEnum, SysLoginResultEnum.BAD_CREDENTIALS); | 181 | this.createLoginLog(username, logTypeEnum, SysLoginResultEnum.BAD_CREDENTIALS); |
| 194 | - throw ServiceExceptionUtil.exception(SysErrorCodeConstants.AUTH_LOGIN_BAD_CREDENTIALS); | 182 | + throw exception(AUTH_LOGIN_BAD_CREDENTIALS); |
| 195 | } catch (DisabledException disabledException) { | 183 | } catch (DisabledException disabledException) { |
| 196 | this.createLoginLog(username, logTypeEnum, SysLoginResultEnum.USER_DISABLED); | 184 | this.createLoginLog(username, logTypeEnum, SysLoginResultEnum.USER_DISABLED); |
| 197 | - throw ServiceExceptionUtil.exception(SysErrorCodeConstants.AUTH_LOGIN_USER_DISABLED); | 185 | + throw exception(AUTH_LOGIN_USER_DISABLED); |
| 198 | } catch (AuthenticationException authenticationException) { | 186 | } catch (AuthenticationException authenticationException) { |
| 199 | log.error("[login0][username({}) 发生未知异常]", username, authenticationException); | 187 | log.error("[login0][username({}) 发生未知异常]", username, authenticationException); |
| 200 | this.createLoginLog(username, logTypeEnum, SysLoginResultEnum.UNKNOWN_ERROR); | 188 | this.createLoginLog(username, logTypeEnum, SysLoginResultEnum.UNKNOWN_ERROR); |
| 201 | - throw ServiceExceptionUtil.exception(SysErrorCodeConstants.AUTH_LOGIN_FAIL_UNKNOWN); | 189 | + throw exception(AUTH_LOGIN_FAIL_UNKNOWN); |
| 202 | } | 190 | } |
| 203 | // 登录成功的日志 | 191 | // 登录成功的日志 |
| 204 | Assert.notNull(authentication.getPrincipal(), "Principal 不会为空"); | 192 | Assert.notNull(authentication.getPrincipal(), "Principal 不会为空"); |
| @@ -208,7 +196,7 @@ public class SysAuthServiceImpl implements SysAuthService { | @@ -208,7 +196,7 @@ public class SysAuthServiceImpl implements SysAuthService { | ||
| 208 | 196 | ||
| 209 | private void createLoginLog(String mobile, SysLoginLogTypeEnum logTypeEnum, SysLoginResultEnum loginResult) { | 197 | private void createLoginLog(String mobile, SysLoginLogTypeEnum logTypeEnum, SysLoginResultEnum loginResult) { |
| 210 | // 获得用户 | 198 | // 获得用户 |
| 211 | - MbrUserDO user = userService.getUserByMobile(mobile); | 199 | + UserDO user = userService.getUserByMobile(mobile); |
| 212 | // 插入登录日志 | 200 | // 插入登录日志 |
| 213 | SysLoginLogCreateReqDTO reqDTO = new SysLoginLogCreateReqDTO(); | 201 | SysLoginLogCreateReqDTO reqDTO = new SysLoginLogCreateReqDTO(); |
| 214 | reqDTO.setLogType(logTypeEnum.getType()); | 202 | reqDTO.setLogType(logTypeEnum.getType()); |
| @@ -246,10 +234,11 @@ public class SysAuthServiceImpl implements SysAuthService { | @@ -246,10 +234,11 @@ public class SysAuthServiceImpl implements SysAuthService { | ||
| 246 | return; | 234 | return; |
| 247 | } | 235 | } |
| 248 | 236 | ||
| 249 | - // 重新加载 MbrUserDO 信息 | ||
| 250 | - MbrUserDO user = userService.getUser(loginUser.getId()); | 237 | + // 重新加载 UserDO 信息 |
| 238 | + UserDO user = userService.getUser(loginUser.getId()); | ||
| 251 | if (user == null || CommonStatusEnum.DISABLE.getStatus().equals(user.getStatus())) { | 239 | if (user == null || CommonStatusEnum.DISABLE.getStatus().equals(user.getStatus())) { |
| 252 | - throw ServiceExceptionUtil.exception(SysErrorCodeConstants.AUTH_TOKEN_EXPIRED); // 校验 token 时,用户被禁用的情况下,也认为 token 过期,方便前端跳转到登录界面 | 240 | + // 校验 token 时,用户被禁用的情况下,也认为 token 过期,方便前端跳转到登录界面 |
| 241 | + throw exception(AUTH_TOKEN_EXPIRED); | ||
| 253 | } | 242 | } |
| 254 | 243 | ||
| 255 | // 刷新 LoginUser 缓存 | 244 | // 刷新 LoginUser 缓存 |
| @@ -258,8 +247,8 @@ public class SysAuthServiceImpl implements SysAuthService { | @@ -258,8 +247,8 @@ public class SysAuthServiceImpl implements SysAuthService { | ||
| 258 | 247 | ||
| 259 | @Override | 248 | @Override |
| 260 | public LoginUser mockLogin(Long userId) { | 249 | public LoginUser mockLogin(Long userId) { |
| 261 | - // 获取用户编号对应的 MbrUserDO | ||
| 262 | - MbrUserDO user = userService.getUser(userId); | 250 | + // 获取用户编号对应的 UserDO |
| 251 | + UserDO user = userService.getUser(userId); | ||
| 263 | if (user == null) { | 252 | if (user == null) { |
| 264 | throw new UsernameNotFoundException(String.valueOf(userId)); | 253 | throw new UsernameNotFoundException(String.valueOf(userId)); |
| 265 | } | 254 | } |
| @@ -268,7 +257,7 @@ public class SysAuthServiceImpl implements SysAuthService { | @@ -268,7 +257,7 @@ public class SysAuthServiceImpl implements SysAuthService { | ||
| 268 | this.createLoginLog(user.getMobile(), SysLoginLogTypeEnum.LOGIN_MOCK, SysLoginResultEnum.SUCCESS); | 257 | this.createLoginLog(user.getMobile(), SysLoginLogTypeEnum.LOGIN_MOCK, SysLoginResultEnum.SUCCESS); |
| 269 | 258 | ||
| 270 | // 创建 LoginUser 对象 | 259 | // 创建 LoginUser 对象 |
| 271 | - return SysAuthConvert.INSTANCE.convert(user); | 260 | + return AuthConvert.INSTANCE.convert(user); |
| 272 | } | 261 | } |
| 273 | 262 | ||
| 274 | @Override | 263 | @Override |
| @@ -285,27 +274,32 @@ public class SysAuthServiceImpl implements SysAuthService { | @@ -285,27 +274,32 @@ public class SysAuthServiceImpl implements SysAuthService { | ||
| 285 | } | 274 | } |
| 286 | 275 | ||
| 287 | @Override | 276 | @Override |
| 288 | - public void updatePassword(Long userId,MbrAuthUpdatePasswordReqVO reqVO) { | 277 | + public UserTypeEnum getUserType() { |
| 278 | + return UserTypeEnum.MEMBER; | ||
| 279 | + } | ||
| 280 | + | ||
| 281 | + @Override | ||
| 282 | + public void updatePassword(Long userId, AppAuthUpdatePasswordReqVO reqVO) { | ||
| 289 | // 检验旧密码 | 283 | // 检验旧密码 |
| 290 | - MbrUserDO userDO = checkOldPassword(userId, reqVO.getOldPassword()); | 284 | + UserDO userDO = checkOldPassword(userId, reqVO.getOldPassword()); |
| 291 | 285 | ||
| 292 | // 更新用户密码 | 286 | // 更新用户密码 |
| 293 | - MbrUserDO mbrUserDO = MbrUserDO.builder().build(); | ||
| 294 | - mbrUserDO.setId(userDO.getId()); | ||
| 295 | - mbrUserDO.setPassword(passwordEncoder.encode(reqVO.getPassword())); | 287 | + UserDO mbrUserDO = UserDO.builder().id(userDO.getId()) |
| 288 | + .password(passwordEncoder.encode(reqVO.getPassword())).build(); | ||
| 296 | userMapper.updateById(mbrUserDO); | 289 | userMapper.updateById(mbrUserDO); |
| 297 | } | 290 | } |
| 298 | 291 | ||
| 299 | @Override | 292 | @Override |
| 300 | - public void resetPassword(MbrAuthResetPasswordReqVO reqVO) { | 293 | + public void resetPassword(AppAuthResetPasswordReqVO reqVO) { |
| 301 | // 检验用户是否存在 | 294 | // 检验用户是否存在 |
| 302 | - MbrUserDO userDO = checkUserIfExists(reqVO.getMobile()); | 295 | + UserDO userDO = checkUserIfExists(reqVO.getMobile()); |
| 303 | 296 | ||
| 304 | // 使用验证码 | 297 | // 使用验证码 |
| 305 | - smsCodeService.useSmsCode(reqVO.getMobile(),SysSmsSceneEnum.FORGET_MOBILE_BY_SMS.getScene(),reqVO.getCode(),getClientIP()); | 298 | + smsCodeService.useSmsCode(reqVO.getMobile(),SysSmsSceneEnum.FORGET_MOBILE_BY_SMS.getScene(), reqVO.getCode(), |
| 299 | + getClientIP()); | ||
| 306 | 300 | ||
| 307 | // 更新密码 | 301 | // 更新密码 |
| 308 | - MbrUserDO mbrUserDO = MbrUserDO.builder().build(); | 302 | + UserDO mbrUserDO = UserDO.builder().build(); |
| 309 | mbrUserDO.setId(userDO.getId()); | 303 | mbrUserDO.setId(userDO.getId()); |
| 310 | mbrUserDO.setPassword(passwordEncoder.encode(reqVO.getPassword())); | 304 | mbrUserDO.setPassword(passwordEncoder.encode(reqVO.getPassword())); |
| 311 | userMapper.updateById(mbrUserDO); | 305 | userMapper.updateById(mbrUserDO); |
| @@ -316,36 +310,35 @@ public class SysAuthServiceImpl implements SysAuthService { | @@ -316,36 +310,35 @@ public class SysAuthServiceImpl implements SysAuthService { | ||
| 316 | * | 310 | * |
| 317 | * @param id 用户 id | 311 | * @param id 用户 id |
| 318 | * @param oldPassword 旧密码 | 312 | * @param oldPassword 旧密码 |
| 319 | - * @return MbrUserDO 用户实体 | 313 | + * @return MemberUserDO 用户实体 |
| 320 | */ | 314 | */ |
| 321 | @VisibleForTesting | 315 | @VisibleForTesting |
| 322 | - public MbrUserDO checkOldPassword(Long id, String oldPassword) { | ||
| 323 | - MbrUserDO user = userMapper.selectById(id); | 316 | + public UserDO checkOldPassword(Long id, String oldPassword) { |
| 317 | + UserDO user = userMapper.selectById(id); | ||
| 324 | if (user == null) { | 318 | if (user == null) { |
| 325 | - throw ServiceExceptionUtil.exception(SysErrorCodeConstants.USER_NOT_EXISTS); | 319 | + throw exception(USER_NOT_EXISTS); |
| 326 | } | 320 | } |
| 327 | // 参数:未加密密码,编码后的密码 | 321 | // 参数:未加密密码,编码后的密码 |
| 328 | if (!passwordEncoder.matches(oldPassword,user.getPassword())) { | 322 | if (!passwordEncoder.matches(oldPassword,user.getPassword())) { |
| 329 | - throw ServiceExceptionUtil.exception(SysErrorCodeConstants.USER_PASSWORD_FAILED); | 323 | + throw exception(USER_PASSWORD_FAILED); |
| 330 | } | 324 | } |
| 331 | return user; | 325 | return user; |
| 332 | } | 326 | } |
| 333 | 327 | ||
| 334 | - public MbrUserDO checkUserIfExists(String mobile) { | ||
| 335 | - MbrUserDO user = userMapper.selectByMobile(mobile); | 328 | + public UserDO checkUserIfExists(String mobile) { |
| 329 | + UserDO user = userMapper.selectByMobile(mobile); | ||
| 336 | if (user == null) { | 330 | if (user == null) { |
| 337 | - throw ServiceExceptionUtil.exception(SysErrorCodeConstants.USER_NOT_EXISTS); | 331 | + throw exception(USER_NOT_EXISTS); |
| 338 | } | 332 | } |
| 339 | return user; | 333 | return user; |
| 340 | } | 334 | } |
| 341 | 335 | ||
| 342 | - | ||
| 343 | private void createLogoutLog(Long userId, String username) { | 336 | private void createLogoutLog(Long userId, String username) { |
| 344 | SysLoginLogCreateReqDTO reqDTO = new SysLoginLogCreateReqDTO(); | 337 | SysLoginLogCreateReqDTO reqDTO = new SysLoginLogCreateReqDTO(); |
| 345 | reqDTO.setLogType(SysLoginLogTypeEnum.LOGOUT_SELF.getType()); | 338 | reqDTO.setLogType(SysLoginLogTypeEnum.LOGOUT_SELF.getType()); |
| 346 | reqDTO.setTraceId(TracerUtils.getTraceId()); | 339 | reqDTO.setTraceId(TracerUtils.getTraceId()); |
| 347 | reqDTO.setUserId(userId); | 340 | reqDTO.setUserId(userId); |
| 348 | - reqDTO.setUserType(USER_TYPE_ENUM.getValue()); | 341 | + reqDTO.setUserType(getUserType().getValue()); |
| 349 | reqDTO.setUsername(username); | 342 | reqDTO.setUsername(username); |
| 350 | reqDTO.setUserAgent(ServletUtils.getUserAgent()); | 343 | reqDTO.setUserAgent(ServletUtils.getUserAgent()); |
| 351 | reqDTO.setUserIp(getClientIP()); | 344 | reqDTO.setUserIp(getClientIP()); |
yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/service/package-info.java deleted
| 1 | -package cn.iocoder.yudao.module.member.service; |
yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/service/sms/SysSmsCodeService.java
| @@ -2,8 +2,8 @@ package cn.iocoder.yudao.module.member.service.sms; | @@ -2,8 +2,8 @@ package cn.iocoder.yudao.module.member.service.sms; | ||
| 2 | 2 | ||
| 3 | import cn.iocoder.yudao.framework.common.exception.ServiceException; | 3 | import cn.iocoder.yudao.framework.common.exception.ServiceException; |
| 4 | import cn.iocoder.yudao.framework.common.validation.Mobile; | 4 | import cn.iocoder.yudao.framework.common.validation.Mobile; |
| 5 | -import cn.iocoder.yudao.userserver.modules.system.dal.dataobject.sms.SysSmsCodeDO; | ||
| 6 | -import cn.iocoder.yudao.userserver.modules.system.enums.sms.SysSmsSceneEnum; | 5 | +import cn.iocoder.yudao.module.member.dal.dataobject.sms.SysSmsCodeDO; |
| 6 | +import cn.iocoder.yudao.module.member.enums.sms.SysSmsSceneEnum; | ||
| 7 | 7 | ||
| 8 | /** | 8 | /** |
| 9 | * 短信验证码 Service 接口 | 9 | * 短信验证码 Service 接口 |
| @@ -40,7 +40,6 @@ public interface SysSmsCodeService { | @@ -40,7 +40,6 @@ public interface SysSmsCodeService { | ||
| 40 | */ | 40 | */ |
| 41 | void sendSmsCodeLogin(Long userId); | 41 | void sendSmsCodeLogin(Long userId); |
| 42 | 42 | ||
| 43 | - | ||
| 44 | /** | 43 | /** |
| 45 | * 检查验证码是否有效 | 44 | * 检查验证码是否有效 |
| 46 | * @param mobile 手机 | 45 | * @param mobile 手机 |
yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/service/sms/SysSmsCodeServiceImpl.java
| 1 | package cn.iocoder.yudao.module.member.service.sms; | 1 | package cn.iocoder.yudao.module.member.service.sms; |
| 2 | 2 | ||
| 3 | import cn.hutool.core.map.MapUtil; | 3 | import cn.hutool.core.map.MapUtil; |
| 4 | -import cn.iocoder.yudao.coreservice.modules.member.dal.dataobject.user.MbrUserDO; | ||
| 5 | import cn.iocoder.yudao.coreservice.modules.system.service.sms.SysSmsCoreService; | 4 | import cn.iocoder.yudao.coreservice.modules.system.service.sms.SysSmsCoreService; |
| 6 | import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil; | 5 | import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil; |
| 7 | -import cn.iocoder.yudao.userserver.modules.member.service.user.MbrUserService; | ||
| 8 | -import cn.iocoder.yudao.userserver.modules.system.dal.dataobject.sms.SysSmsCodeDO; | ||
| 9 | -import cn.iocoder.yudao.userserver.modules.system.dal.mysql.sms.SysSmsCodeMapper; | ||
| 10 | -import cn.iocoder.yudao.userserver.modules.system.enums.sms.SysSmsSceneEnum; | ||
| 11 | -import cn.iocoder.yudao.userserver.modules.system.framework.sms.SmsCodeProperties; | ||
| 12 | -import cn.iocoder.yudao.userserver.modules.system.service.sms.SysSmsCodeService; | 6 | +import cn.iocoder.yudao.module.member.dal.dataobject.sms.SysSmsCodeDO; |
| 7 | +import cn.iocoder.yudao.module.member.dal.dataobject.user.UserDO; | ||
| 8 | +import cn.iocoder.yudao.module.member.dal.mysql.sms.SysSmsCodeMapper; | ||
| 9 | +import cn.iocoder.yudao.module.member.enums.sms.SysSmsSceneEnum; | ||
| 10 | +import cn.iocoder.yudao.module.member.framework.sms.SmsCodeProperties; | ||
| 11 | +import cn.iocoder.yudao.module.member.service.user.UserService; | ||
| 13 | import org.springframework.stereotype.Service; | 12 | import org.springframework.stereotype.Service; |
| 14 | import org.springframework.validation.annotation.Validated; | 13 | import org.springframework.validation.annotation.Validated; |
| 15 | 14 | ||
| @@ -17,9 +16,8 @@ import javax.annotation.Resource; | @@ -17,9 +16,8 @@ import javax.annotation.Resource; | ||
| 17 | import java.util.Date; | 16 | import java.util.Date; |
| 18 | 17 | ||
| 19 | import static cn.hutool.core.util.RandomUtil.randomInt; | 18 | import static cn.hutool.core.util.RandomUtil.randomInt; |
| 20 | -import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | ||
| 21 | import static cn.iocoder.yudao.framework.common.util.servlet.ServletUtils.getClientIP; | 19 | import static cn.iocoder.yudao.framework.common.util.servlet.ServletUtils.getClientIP; |
| 22 | -import static cn.iocoder.yudao.userserver.modules.system.enums.SysErrorCodeConstants.*; | 20 | +import static cn.iocoder.yudao.module.member.enums.SysErrorCodeConstants.*; |
| 23 | 21 | ||
| 24 | /** | 22 | /** |
| 25 | * 短信验证码 Service 实现类 | 23 | * 短信验证码 Service 实现类 |
| @@ -37,7 +35,7 @@ public class SysSmsCodeServiceImpl implements SysSmsCodeService { | @@ -37,7 +35,7 @@ public class SysSmsCodeServiceImpl implements SysSmsCodeService { | ||
| 37 | private SysSmsCodeMapper smsCodeMapper; | 35 | private SysSmsCodeMapper smsCodeMapper; |
| 38 | 36 | ||
| 39 | @Resource | 37 | @Resource |
| 40 | - private MbrUserService mbrUserService; | 38 | + private UserService userService; |
| 41 | 39 | ||
| 42 | @Resource | 40 | @Resource |
| 43 | private SysSmsCoreService smsCoreService; | 41 | private SysSmsCoreService smsCoreService; |
| @@ -62,9 +60,9 @@ public class SysSmsCodeServiceImpl implements SysSmsCodeService { | @@ -62,9 +60,9 @@ public class SysSmsCodeServiceImpl implements SysSmsCodeService { | ||
| 62 | 60 | ||
| 63 | public void checkMobileIsRegister(String mobile, Integer scene) { | 61 | public void checkMobileIsRegister(String mobile, Integer scene) { |
| 64 | // 检测手机号是否已被使用 | 62 | // 检测手机号是否已被使用 |
| 65 | - MbrUserDO userByMobile = mbrUserService.getUserByMobile(mobile); | ||
| 66 | - if (userByMobile != null){ | ||
| 67 | - throw ServiceExceptionUtil.exception(SysErrorCodeConstants.USER_SMS_CODE_IS_EXISTS); | 63 | + UserDO user = userService.getUserByMobile(mobile); |
| 64 | + if (user != null) { | ||
| 65 | + throw ServiceExceptionUtil.exception(USER_SMS_CODE_IS_EXISTS); | ||
| 68 | } | 66 | } |
| 69 | 67 | ||
| 70 | // 发送短信 | 68 | // 发送短信 |
| @@ -76,11 +74,11 @@ public class SysSmsCodeServiceImpl implements SysSmsCodeService { | @@ -76,11 +74,11 @@ public class SysSmsCodeServiceImpl implements SysSmsCodeService { | ||
| 76 | SysSmsCodeDO lastSmsCode = smsCodeMapper.selectLastByMobile(mobile, null,null); | 74 | SysSmsCodeDO lastSmsCode = smsCodeMapper.selectLastByMobile(mobile, null,null); |
| 77 | if (lastSmsCode != null) { | 75 | if (lastSmsCode != null) { |
| 78 | if (lastSmsCode.getTodayIndex() >= smsCodeProperties.getSendMaximumQuantityPerDay()) { // 超过当天发送的上限。 | 76 | if (lastSmsCode.getTodayIndex() >= smsCodeProperties.getSendMaximumQuantityPerDay()) { // 超过当天发送的上限。 |
| 79 | - throw ServiceExceptionUtil.exception(SysErrorCodeConstants.USER_SMS_CODE_EXCEED_SEND_MAXIMUM_QUANTITY_PER_DAY); | 77 | + throw ServiceExceptionUtil.exception(USER_SMS_CODE_EXCEED_SEND_MAXIMUM_QUANTITY_PER_DAY); |
| 80 | } | 78 | } |
| 81 | if (System.currentTimeMillis() - lastSmsCode.getCreateTime().getTime() | 79 | if (System.currentTimeMillis() - lastSmsCode.getCreateTime().getTime() |
| 82 | < smsCodeProperties.getSendFrequency().toMillis()) { // 发送过于频繁 | 80 | < smsCodeProperties.getSendFrequency().toMillis()) { // 发送过于频繁 |
| 83 | - throw ServiceExceptionUtil.exception(SysErrorCodeConstants.USER_SMS_CODE_SEND_TOO_FAST); | 81 | + throw ServiceExceptionUtil.exception(USER_SMS_CODE_SEND_TOO_FAST); |
| 84 | } | 82 | } |
| 85 | // TODO 芋艿:提升,每个 IP 每天可发送数量 | 83 | // TODO 芋艿:提升,每个 IP 每天可发送数量 |
| 86 | // TODO 芋艿:提升,每个 IP 每小时可发送数量 | 84 | // TODO 芋艿:提升,每个 IP 每小时可发送数量 |
| @@ -97,13 +95,12 @@ public class SysSmsCodeServiceImpl implements SysSmsCodeService { | @@ -97,13 +95,12 @@ public class SysSmsCodeServiceImpl implements SysSmsCodeService { | ||
| 97 | 95 | ||
| 98 | @Override | 96 | @Override |
| 99 | public void useSmsCode(String mobile, Integer scene, String code, String usedIp) { | 97 | public void useSmsCode(String mobile, Integer scene, String code, String usedIp) { |
| 100 | - | ||
| 101 | // 检测验证码是否有效 | 98 | // 检测验证码是否有效 |
| 102 | SysSmsCodeDO lastSmsCode = this.checkCodeIsExpired(mobile, code, scene); | 99 | SysSmsCodeDO lastSmsCode = this.checkCodeIsExpired(mobile, code, scene); |
| 103 | 100 | ||
| 104 | // 判断验证码是否已被使用 | 101 | // 判断验证码是否已被使用 |
| 105 | if (Boolean.TRUE.equals(lastSmsCode.getUsed())) { | 102 | if (Boolean.TRUE.equals(lastSmsCode.getUsed())) { |
| 106 | - throw ServiceExceptionUtil.exception(SysErrorCodeConstants.USER_SMS_CODE_USED); | 103 | + throw ServiceExceptionUtil.exception(USER_SMS_CODE_USED); |
| 107 | } | 104 | } |
| 108 | 105 | ||
| 109 | // 使用验证码 | 106 | // 使用验证码 |
| @@ -113,9 +110,9 @@ public class SysSmsCodeServiceImpl implements SysSmsCodeService { | @@ -113,9 +110,9 @@ public class SysSmsCodeServiceImpl implements SysSmsCodeService { | ||
| 113 | 110 | ||
| 114 | @Override | 111 | @Override |
| 115 | public void sendSmsCodeLogin(Long userId) { | 112 | public void sendSmsCodeLogin(Long userId) { |
| 116 | - MbrUserDO user = mbrUserService.getUser(userId); | 113 | + UserDO user = userService.getUser(userId); |
| 117 | if (user == null){ | 114 | if (user == null){ |
| 118 | - throw ServiceExceptionUtil.exception(SysErrorCodeConstants.USER_NOT_EXISTS); | 115 | + throw ServiceExceptionUtil.exception(USER_NOT_EXISTS); |
| 119 | } | 116 | } |
| 120 | // 发送验证码 | 117 | // 发送验证码 |
| 121 | this.sendSmsCode(user.getMobile(),SysSmsSceneEnum.CHANGE_MOBILE_BY_SMS.getScene(), getClientIP()); | 118 | this.sendSmsCode(user.getMobile(),SysSmsSceneEnum.CHANGE_MOBILE_BY_SMS.getScene(), getClientIP()); |
| @@ -128,15 +125,13 @@ public class SysSmsCodeServiceImpl implements SysSmsCodeService { | @@ -128,15 +125,13 @@ public class SysSmsCodeServiceImpl implements SysSmsCodeService { | ||
| 128 | 125 | ||
| 129 | // 若验证码不存在,抛出异常 | 126 | // 若验证码不存在,抛出异常 |
| 130 | if (lastSmsCode == null) { | 127 | if (lastSmsCode == null) { |
| 131 | - throw ServiceExceptionUtil.exception(SysErrorCodeConstants.USER_SMS_CODE_NOT_FOUND); | 128 | + throw ServiceExceptionUtil.exception(USER_SMS_CODE_NOT_FOUND); |
| 132 | } | 129 | } |
| 133 | if (System.currentTimeMillis() - lastSmsCode.getCreateTime().getTime() | 130 | if (System.currentTimeMillis() - lastSmsCode.getCreateTime().getTime() |
| 134 | >= smsCodeProperties.getExpireTimes().toMillis()) { // 验证码已过期 | 131 | >= smsCodeProperties.getExpireTimes().toMillis()) { // 验证码已过期 |
| 135 | - throw ServiceExceptionUtil.exception(SysErrorCodeConstants.USER_SMS_CODE_EXPIRED); | 132 | + throw ServiceExceptionUtil.exception(USER_SMS_CODE_EXPIRED); |
| 136 | } | 133 | } |
| 137 | - | ||
| 138 | return lastSmsCode; | 134 | return lastSmsCode; |
| 139 | - | ||
| 140 | } | 135 | } |
| 141 | 136 | ||
| 142 | } | 137 | } |
yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/service/user/MbrUserService.java renamed to yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/service/user/UserService.java
| 1 | package cn.iocoder.yudao.module.member.service.user; | 1 | package cn.iocoder.yudao.module.member.service.user; |
| 2 | 2 | ||
| 3 | -import cn.iocoder.yudao.coreservice.modules.member.dal.dataobject.user.MbrUserDO; | ||
| 4 | -import cn.iocoder.yudao.userserver.modules.member.controller.user.vo.MbrUserInfoRespVO; | ||
| 5 | import cn.iocoder.yudao.framework.common.validation.Mobile; | 3 | import cn.iocoder.yudao.framework.common.validation.Mobile; |
| 6 | -import cn.iocoder.yudao.userserver.modules.member.controller.user.vo.MbrUserUpdateMobileReqVO; | 4 | +import cn.iocoder.yudao.module.member.controller.app.user.vo.AppUserInfoRespVO; |
| 5 | +import cn.iocoder.yudao.module.member.controller.app.user.vo.AppUserUpdateMobileReqVO; | ||
| 6 | +import cn.iocoder.yudao.module.member.dal.dataobject.user.UserDO; | ||
| 7 | 7 | ||
| 8 | import java.io.InputStream; | 8 | import java.io.InputStream; |
| 9 | 9 | ||
| 10 | /** | 10 | /** |
| 11 | - * 前台用户 Service 接口 | 11 | + * 会员用户 Service 接口 |
| 12 | * | 12 | * |
| 13 | * @author 芋道源码 | 13 | * @author 芋道源码 |
| 14 | */ | 14 | */ |
| 15 | -public interface MbrUserService { | 15 | +public interface UserService { |
| 16 | 16 | ||
| 17 | /** | 17 | /** |
| 18 | * 通过手机查询用户 | 18 | * 通过手机查询用户 |
| @@ -20,7 +20,7 @@ public interface MbrUserService { | @@ -20,7 +20,7 @@ public interface MbrUserService { | ||
| 20 | * @param mobile 手机 | 20 | * @param mobile 手机 |
| 21 | * @return 用户对象 | 21 | * @return 用户对象 |
| 22 | */ | 22 | */ |
| 23 | - MbrUserDO getUserByMobile(String mobile); | 23 | + UserDO getUserByMobile(String mobile); |
| 24 | 24 | ||
| 25 | /** | 25 | /** |
| 26 | * 基于手机号创建用户。 | 26 | * 基于手机号创建用户。 |
| @@ -30,7 +30,7 @@ public interface MbrUserService { | @@ -30,7 +30,7 @@ public interface MbrUserService { | ||
| 30 | * @param registerIp 注册 IP | 30 | * @param registerIp 注册 IP |
| 31 | * @return 用户对象 | 31 | * @return 用户对象 |
| 32 | */ | 32 | */ |
| 33 | - MbrUserDO createUserIfAbsent(@Mobile String mobile, String registerIp); | 33 | + UserDO createUserIfAbsent(@Mobile String mobile, String registerIp); |
| 34 | 34 | ||
| 35 | /** | 35 | /** |
| 36 | * 更新用户的最后登陆信息 | 36 | * 更新用户的最后登陆信息 |
| @@ -46,14 +46,14 @@ public interface MbrUserService { | @@ -46,14 +46,14 @@ public interface MbrUserService { | ||
| 46 | * @param id 用户ID | 46 | * @param id 用户ID |
| 47 | * @return 用户对象信息 | 47 | * @return 用户对象信息 |
| 48 | */ | 48 | */ |
| 49 | - MbrUserDO getUser(Long id); | 49 | + UserDO getUser(Long id); |
| 50 | 50 | ||
| 51 | /** | 51 | /** |
| 52 | * 修改用户昵称 | 52 | * 修改用户昵称 |
| 53 | * @param userId 用户id | 53 | * @param userId 用户id |
| 54 | * @param nickname 用户新昵称 | 54 | * @param nickname 用户新昵称 |
| 55 | */ | 55 | */ |
| 56 | - void updateNickname(Long userId, String nickname); | 56 | + void updateUserNickname(Long userId, String nickname); |
| 57 | 57 | ||
| 58 | /** | 58 | /** |
| 59 | * 修改用户头像 | 59 | * 修改用户头像 |
| @@ -61,21 +61,13 @@ public interface MbrUserService { | @@ -61,21 +61,13 @@ public interface MbrUserService { | ||
| 61 | * @param inputStream 头像文件 | 61 | * @param inputStream 头像文件 |
| 62 | * @return 头像url | 62 | * @return 头像url |
| 63 | */ | 63 | */ |
| 64 | - String updateAvatar(Long userId, InputStream inputStream); | ||
| 65 | - | ||
| 66 | - /** | ||
| 67 | - * 根据用户id,获取用户头像与昵称 | ||
| 68 | - * | ||
| 69 | - * @param userId 用户id | ||
| 70 | - * @return 用户响应实体类 | ||
| 71 | - */ | ||
| 72 | - MbrUserInfoRespVO getUserInfo(Long userId); | 64 | + String updateUserAvatar(Long userId, InputStream inputStream); |
| 73 | 65 | ||
| 74 | /** | 66 | /** |
| 75 | * 修改手机 | 67 | * 修改手机 |
| 76 | * @param userId 用户id | 68 | * @param userId 用户id |
| 77 | * @param reqVO 请求实体 | 69 | * @param reqVO 请求实体 |
| 78 | */ | 70 | */ |
| 79 | - void updateMobile(Long userId, MbrUserUpdateMobileReqVO reqVO); | 71 | + void updateUserMobile(Long userId, AppUserUpdateMobileReqVO reqVO); |
| 80 | 72 | ||
| 81 | } | 73 | } |
yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/service/user/MbrUserServiceImpl.java renamed to yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/service/user/UserServiceImpl.java
| @@ -3,17 +3,15 @@ package cn.iocoder.yudao.module.member.service.user; | @@ -3,17 +3,15 @@ package cn.iocoder.yudao.module.member.service.user; | ||
| 3 | import cn.hutool.core.io.IoUtil; | 3 | import cn.hutool.core.io.IoUtil; |
| 4 | import cn.hutool.core.util.IdUtil; | 4 | import cn.hutool.core.util.IdUtil; |
| 5 | import cn.iocoder.yudao.coreservice.modules.infra.service.file.InfFileCoreService; | 5 | import cn.iocoder.yudao.coreservice.modules.infra.service.file.InfFileCoreService; |
| 6 | -import cn.iocoder.yudao.coreservice.modules.member.dal.dataobject.user.MbrUserDO; | ||
| 7 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | 6 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 8 | import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil; | 7 | import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil; |
| 9 | -import cn.iocoder.yudao.userserver.modules.member.controller.user.vo.MbrUserInfoRespVO; | ||
| 10 | -import cn.iocoder.yudao.userserver.modules.member.controller.user.vo.MbrUserUpdateMobileReqVO; | ||
| 11 | -import cn.iocoder.yudao.userserver.modules.member.convert.user.UserProfileConvert; | ||
| 12 | -import cn.iocoder.yudao.userserver.modules.member.dal.mysql.user.MbrUserMapper; | ||
| 13 | -import cn.iocoder.yudao.userserver.modules.member.service.user.MbrUserService; | ||
| 14 | -import cn.iocoder.yudao.userserver.modules.system.dal.dataobject.sms.SysSmsCodeDO; | ||
| 15 | -import cn.iocoder.yudao.userserver.modules.system.enums.sms.SysSmsSceneEnum; | ||
| 16 | -import cn.iocoder.yudao.userserver.modules.system.service.sms.SysSmsCodeService; | 8 | +import cn.iocoder.yudao.module.member.controller.app.user.vo.AppUserUpdateMobileReqVO; |
| 9 | +import cn.iocoder.yudao.module.member.dal.dataobject.sms.SysSmsCodeDO; | ||
| 10 | +import cn.iocoder.yudao.module.member.dal.dataobject.user.UserDO; | ||
| 11 | +import cn.iocoder.yudao.module.member.dal.mysql.user.UserMapper; | ||
| 12 | +import cn.iocoder.yudao.module.member.enums.SysErrorCodeConstants; | ||
| 13 | +import cn.iocoder.yudao.module.member.enums.sms.SysSmsSceneEnum; | ||
| 14 | +import cn.iocoder.yudao.module.member.service.sms.SysSmsCodeService; | ||
| 17 | import com.google.common.annotations.VisibleForTesting; | 15 | import com.google.common.annotations.VisibleForTesting; |
| 18 | import lombok.extern.slf4j.Slf4j; | 16 | import lombok.extern.slf4j.Slf4j; |
| 19 | import org.springframework.security.crypto.password.PasswordEncoder; | 17 | import org.springframework.security.crypto.password.PasswordEncoder; |
| @@ -27,41 +25,38 @@ import java.util.Date; | @@ -27,41 +25,38 @@ import java.util.Date; | ||
| 27 | 25 | ||
| 28 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | 26 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 29 | import static cn.iocoder.yudao.framework.common.util.servlet.ServletUtils.getClientIP; | 27 | import static cn.iocoder.yudao.framework.common.util.servlet.ServletUtils.getClientIP; |
| 30 | -import static cn.iocoder.yudao.userserver.modules.member.enums.MbrErrorCodeConstants.USER_NOT_EXISTS; | ||
| 31 | -import static cn.iocoder.yudao.userserver.modules.system.enums.SysErrorCodeConstants.USER_SMS_CODE_IS_UNUSED; | 28 | +import static cn.iocoder.yudao.module.member.enums.MemberErrorCodeConstants.USER_NOT_EXISTS; |
| 32 | 29 | ||
| 33 | /** | 30 | /** |
| 34 | - * User Service 实现类 | 31 | + * 会员 User Service 实现类 |
| 35 | * | 32 | * |
| 36 | * @author 芋道源码 | 33 | * @author 芋道源码 |
| 37 | */ | 34 | */ |
| 38 | @Service | 35 | @Service |
| 39 | @Valid | 36 | @Valid |
| 40 | @Slf4j | 37 | @Slf4j |
| 41 | -public class MbrUserServiceImpl implements MbrUserService { | 38 | +public class UserServiceImpl implements UserService { |
| 42 | 39 | ||
| 43 | @Resource | 40 | @Resource |
| 44 | - private MbrUserMapper userMapper; | 41 | + private UserMapper memberUserMapper; |
| 45 | 42 | ||
| 46 | @Resource | 43 | @Resource |
| 47 | private InfFileCoreService fileCoreService; | 44 | private InfFileCoreService fileCoreService; |
| 48 | - | ||
| 49 | - @Resource | ||
| 50 | - private PasswordEncoder passwordEncoder; | ||
| 51 | - | ||
| 52 | @Resource | 45 | @Resource |
| 53 | private SysSmsCodeService smsCodeService; | 46 | private SysSmsCodeService smsCodeService; |
| 54 | 47 | ||
| 48 | + @Resource | ||
| 49 | + private PasswordEncoder passwordEncoder; | ||
| 55 | 50 | ||
| 56 | @Override | 51 | @Override |
| 57 | - public MbrUserDO getUserByMobile(String mobile) { | ||
| 58 | - return userMapper.selectByMobile(mobile); | 52 | + public UserDO getUserByMobile(String mobile) { |
| 53 | + return memberUserMapper.selectByMobile(mobile); | ||
| 59 | } | 54 | } |
| 60 | 55 | ||
| 61 | @Override | 56 | @Override |
| 62 | - public MbrUserDO createUserIfAbsent(String mobile, String registerIp) { | 57 | + public UserDO createUserIfAbsent(String mobile, String registerIp) { |
| 63 | // 用户已经存在 | 58 | // 用户已经存在 |
| 64 | - MbrUserDO user = userMapper.selectByMobile(mobile); | 59 | + UserDO user = memberUserMapper.selectByMobile(mobile); |
| 65 | if (user != null) { | 60 | if (user != null) { |
| 66 | return user; | 61 | return user; |
| 67 | } | 62 | } |
| @@ -69,94 +64,84 @@ public class MbrUserServiceImpl implements MbrUserService { | @@ -69,94 +64,84 @@ public class MbrUserServiceImpl implements MbrUserService { | ||
| 69 | return this.createUser(mobile, registerIp); | 64 | return this.createUser(mobile, registerIp); |
| 70 | } | 65 | } |
| 71 | 66 | ||
| 72 | - private MbrUserDO createUser(String mobile, String registerIp) { | 67 | + private UserDO createUser(String mobile, String registerIp) { |
| 73 | // 生成密码 | 68 | // 生成密码 |
| 74 | String password = IdUtil.fastSimpleUUID(); | 69 | String password = IdUtil.fastSimpleUUID(); |
| 75 | // 插入用户 | 70 | // 插入用户 |
| 76 | - MbrUserDO user = new MbrUserDO(); | 71 | + UserDO user = new UserDO(); |
| 77 | user.setMobile(mobile); | 72 | user.setMobile(mobile); |
| 78 | user.setStatus(CommonStatusEnum.ENABLE.getStatus()); // 默认开启 | 73 | user.setStatus(CommonStatusEnum.ENABLE.getStatus()); // 默认开启 |
| 79 | user.setPassword(passwordEncoder.encode(password)); // 加密密码 | 74 | user.setPassword(passwordEncoder.encode(password)); // 加密密码 |
| 80 | user.setRegisterIp(registerIp); | 75 | user.setRegisterIp(registerIp); |
| 81 | - userMapper.insert(user); | 76 | + memberUserMapper.insert(user); |
| 82 | return user; | 77 | return user; |
| 83 | } | 78 | } |
| 84 | 79 | ||
| 85 | @Override | 80 | @Override |
| 86 | public void updateUserLogin(Long id, String loginIp) { | 81 | public void updateUserLogin(Long id, String loginIp) { |
| 87 | - userMapper.updateById(new MbrUserDO().setId(id).setLoginIp(loginIp).setLoginDate(new Date())); | 82 | + memberUserMapper.updateById(new UserDO().setId(id) |
| 83 | + .setLoginIp(loginIp).setLoginDate(new Date())); | ||
| 88 | } | 84 | } |
| 89 | 85 | ||
| 90 | @Override | 86 | @Override |
| 91 | - public MbrUserDO getUser(Long id) { | ||
| 92 | - return userMapper.selectById(id); | 87 | + public UserDO getUser(Long id) { |
| 88 | + return memberUserMapper.selectById(id); | ||
| 93 | } | 89 | } |
| 94 | 90 | ||
| 95 | @Override | 91 | @Override |
| 96 | - public void updateNickname(Long userId, String nickname) { | ||
| 97 | - MbrUserDO user = this.checkUserExists(userId); | 92 | + public void updateUserNickname(Long userId, String nickname) { |
| 93 | + UserDO user = this.checkUserExists(userId); | ||
| 98 | // 仅当新昵称不等于旧昵称时进行修改 | 94 | // 仅当新昵称不等于旧昵称时进行修改 |
| 99 | if (nickname.equals(user.getNickname())){ | 95 | if (nickname.equals(user.getNickname())){ |
| 100 | return; | 96 | return; |
| 101 | } | 97 | } |
| 102 | - MbrUserDO userDO = new MbrUserDO(); | 98 | + UserDO userDO = new UserDO(); |
| 103 | userDO.setId(user.getId()); | 99 | userDO.setId(user.getId()); |
| 104 | userDO.setNickname(nickname); | 100 | userDO.setNickname(nickname); |
| 105 | - userMapper.updateById(userDO); | 101 | + memberUserMapper.updateById(userDO); |
| 106 | } | 102 | } |
| 107 | 103 | ||
| 108 | @Override | 104 | @Override |
| 109 | - public String updateAvatar(Long userId, InputStream avatarFile) { | 105 | + public String updateUserAvatar(Long userId, InputStream avatarFile) { |
| 110 | this.checkUserExists(userId); | 106 | this.checkUserExists(userId); |
| 111 | // 创建文件 | 107 | // 创建文件 |
| 112 | String avatar = fileCoreService.createFile(IdUtil.fastUUID(), IoUtil.readBytes(avatarFile)); | 108 | String avatar = fileCoreService.createFile(IdUtil.fastUUID(), IoUtil.readBytes(avatarFile)); |
| 113 | // 更新头像路径 | 109 | // 更新头像路径 |
| 114 | - MbrUserDO userDO = MbrUserDO.builder() | ||
| 115 | - .id(userId) | ||
| 116 | - .avatar(avatar) | ||
| 117 | - .build(); | ||
| 118 | - userMapper.updateById(userDO); | 110 | + memberUserMapper.updateById(UserDO.builder().id(userId).avatar(avatar).build()); |
| 119 | return avatar; | 111 | return avatar; |
| 120 | } | 112 | } |
| 121 | 113 | ||
| 122 | - @Override | ||
| 123 | - public MbrUserInfoRespVO getUserInfo(Long userId) { | ||
| 124 | - MbrUserDO user = this.checkUserExists(userId); | ||
| 125 | - // 拼接返回结果 | ||
| 126 | - return UserProfileConvert.INSTANCE.convert(user); | ||
| 127 | - } | ||
| 128 | - | ||
| 129 | - @Override | ||
| 130 | @Transactional(rollbackFor = Exception.class) | 114 | @Transactional(rollbackFor = Exception.class) |
| 131 | - public void updateMobile(Long userId, MbrUserUpdateMobileReqVO reqVO) { | 115 | + public void updateUserMobile(Long userId, AppUserUpdateMobileReqVO reqVO) { |
| 132 | // 检测用户是否存在 | 116 | // 检测用户是否存在 |
| 133 | checkUserExists(userId); | 117 | checkUserExists(userId); |
| 134 | 118 | ||
| 135 | // 校验旧手机和旧验证码 | 119 | // 校验旧手机和旧验证码 |
| 136 | - SysSmsCodeDO sysSmsCodeDO = smsCodeService.checkCodeIsExpired(reqVO.getOldMobile(), reqVO.getOldCode(), SysSmsSceneEnum.CHANGE_MOBILE_BY_SMS.getScene()); | ||
| 137 | - // 判断旧code是否未被使用,如果是,抛出异常 | 120 | + SysSmsCodeDO sysSmsCodeDO = smsCodeService.checkCodeIsExpired(reqVO.getOldMobile(), reqVO.getOldCode(), |
| 121 | + SysSmsSceneEnum.CHANGE_MOBILE_BY_SMS.getScene()); | ||
| 122 | + // 判断旧 code 是否未被使用,如果是,抛出异常 | ||
| 138 | if (Boolean.FALSE.equals(sysSmsCodeDO.getUsed())){ | 123 | if (Boolean.FALSE.equals(sysSmsCodeDO.getUsed())){ |
| 139 | throw ServiceExceptionUtil.exception(SysErrorCodeConstants.USER_SMS_CODE_IS_UNUSED); | 124 | throw ServiceExceptionUtil.exception(SysErrorCodeConstants.USER_SMS_CODE_IS_UNUSED); |
| 140 | } | 125 | } |
| 141 | 126 | ||
| 142 | // 使用新验证码 | 127 | // 使用新验证码 |
| 143 | - smsCodeService.useSmsCode(reqVO.getMobile(), SysSmsSceneEnum.CHANGE_MOBILE_BY_SMS.getScene(), reqVO.getCode(),getClientIP()); | 128 | + smsCodeService.useSmsCode(reqVO.getMobile(), SysSmsSceneEnum.CHANGE_MOBILE_BY_SMS.getScene(), |
| 129 | + reqVO.getCode(),getClientIP()); | ||
| 144 | 130 | ||
| 145 | // 更新用户手机 | 131 | // 更新用户手机 |
| 146 | - MbrUserDO userDO = MbrUserDO.builder().id(userId).mobile(reqVO.getMobile()).build(); | ||
| 147 | - userMapper.updateById(userDO); | 132 | + memberUserMapper.updateById(UserDO.builder().id(userId).mobile(reqVO.getMobile()).build()); |
| 148 | } | 133 | } |
| 149 | 134 | ||
| 150 | @VisibleForTesting | 135 | @VisibleForTesting |
| 151 | - public MbrUserDO checkUserExists(Long id) { | 136 | + public UserDO checkUserExists(Long id) { |
| 152 | if (id == null) { | 137 | if (id == null) { |
| 153 | return null; | 138 | return null; |
| 154 | } | 139 | } |
| 155 | - MbrUserDO user = userMapper.selectById(id); | 140 | + UserDO user = memberUserMapper.selectById(id); |
| 156 | if (user == null) { | 141 | if (user == null) { |
| 157 | throw exception(USER_NOT_EXISTS); | 142 | throw exception(USER_NOT_EXISTS); |
| 158 | - }else{ | ||
| 159 | - return user; | ||
| 160 | } | 143 | } |
| 144 | + return user; | ||
| 161 | } | 145 | } |
| 146 | + | ||
| 162 | } | 147 | } |
yudao-module-member/yudao-module-member-impl/src/test/java/cn/iocoder/yudao/module/member/service/auth/SysAuthServiceTest.java
| 1 | package cn.iocoder.yudao.module.member.service.auth; | 1 | package cn.iocoder.yudao.module.member.service.auth; |
| 2 | 2 | ||
| 3 | -import cn.iocoder.yudao.coreservice.modules.member.dal.dataobject.user.MbrUserDO; | ||
| 4 | import cn.iocoder.yudao.coreservice.modules.system.service.auth.SysUserSessionCoreService; | 3 | import cn.iocoder.yudao.coreservice.modules.system.service.auth.SysUserSessionCoreService; |
| 5 | import cn.iocoder.yudao.coreservice.modules.system.service.logger.SysLoginLogCoreService; | 4 | import cn.iocoder.yudao.coreservice.modules.system.service.logger.SysLoginLogCoreService; |
| 6 | import cn.iocoder.yudao.coreservice.modules.system.service.social.SysSocialCoreService; | 5 | import cn.iocoder.yudao.coreservice.modules.system.service.social.SysSocialCoreService; |
| 7 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | 6 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 8 | import cn.iocoder.yudao.framework.common.util.collection.ArrayUtils; | 7 | import cn.iocoder.yudao.framework.common.util.collection.ArrayUtils; |
| 9 | import cn.iocoder.yudao.framework.redis.config.YudaoRedisAutoConfiguration; | 8 | import cn.iocoder.yudao.framework.redis.config.YudaoRedisAutoConfiguration; |
| 10 | -import cn.iocoder.yudao.userserver.BaseDbAndRedisUnitTest; | ||
| 11 | -import cn.iocoder.yudao.userserver.modules.member.dal.mysql.user.MbrUserMapper; | ||
| 12 | -import cn.iocoder.yudao.userserver.modules.member.service.user.MbrUserService; | ||
| 13 | -import cn.iocoder.yudao.module.member.controller.app.auth.vo.MbrAuthResetPasswordReqVO; | ||
| 14 | -import cn.iocoder.yudao.module.member.controller.app.auth.vo.MbrAuthUpdatePasswordReqVO; | ||
| 15 | -import cn.iocoder.yudao.userserver.modules.system.service.auth.SysAuthService; | ||
| 16 | -import cn.iocoder.yudao.userserver.modules.system.service.auth.impl.SysAuthServiceImpl; | ||
| 17 | -import cn.iocoder.yudao.userserver.modules.system.service.sms.SysSmsCodeService; | 9 | +import cn.iocoder.yudao.module.member.controller.app.auth.vo.AppAuthResetPasswordReqVO; |
| 10 | +import cn.iocoder.yudao.module.member.controller.app.auth.vo.AppAuthUpdatePasswordReqVO; | ||
| 11 | +import cn.iocoder.yudao.module.member.dal.dataobject.user.UserDO; | ||
| 12 | +import cn.iocoder.yudao.module.member.dal.mysql.user.UserMapper; | ||
| 13 | +import cn.iocoder.yudao.module.member.service.sms.SysSmsCodeService; | ||
| 14 | +import cn.iocoder.yudao.module.member.service.user.UserService; | ||
| 15 | +import cn.iocoder.yudao.module.member.test.BaseDbAndRedisUnitTest; | ||
| 18 | import org.junit.jupiter.api.Test; | 16 | import org.junit.jupiter.api.Test; |
| 19 | import org.springframework.boot.test.mock.mockito.MockBean; | 17 | import org.springframework.boot.test.mock.mockito.MockBean; |
| 20 | import org.springframework.context.annotation.Import; | 18 | import org.springframework.context.annotation.Import; |
| @@ -34,17 +32,17 @@ import static org.mockito.Mockito.when; | @@ -34,17 +32,17 @@ import static org.mockito.Mockito.when; | ||
| 34 | 32 | ||
| 35 | // TODO @芋艿:单测的 review,等逻辑都达成一致后 | 33 | // TODO @芋艿:单测的 review,等逻辑都达成一致后 |
| 36 | /** | 34 | /** |
| 37 | - * {@link SysAuthService} 的单元测试类 | 35 | + * {@link AuthService} 的单元测试类 |
| 38 | * | 36 | * |
| 39 | * @author 宋天 | 37 | * @author 宋天 |
| 40 | */ | 38 | */ |
| 41 | -@Import({SysAuthServiceImpl.class, YudaoRedisAutoConfiguration.class}) | 39 | +@Import({AuthServiceImpl.class, YudaoRedisAutoConfiguration.class}) |
| 42 | public class SysAuthServiceTest extends BaseDbAndRedisUnitTest { | 40 | public class SysAuthServiceTest extends BaseDbAndRedisUnitTest { |
| 43 | 41 | ||
| 44 | @MockBean | 42 | @MockBean |
| 45 | private AuthenticationManager authenticationManager; | 43 | private AuthenticationManager authenticationManager; |
| 46 | @MockBean | 44 | @MockBean |
| 47 | - private MbrUserService userService; | 45 | + private UserService userService; |
| 48 | @MockBean | 46 | @MockBean |
| 49 | private SysSmsCodeService smsCodeService; | 47 | private SysSmsCodeService smsCodeService; |
| 50 | @MockBean | 48 | @MockBean |
| @@ -58,21 +56,21 @@ public class SysAuthServiceTest extends BaseDbAndRedisUnitTest { | @@ -58,21 +56,21 @@ public class SysAuthServiceTest extends BaseDbAndRedisUnitTest { | ||
| 58 | @MockBean | 56 | @MockBean |
| 59 | private PasswordEncoder passwordEncoder; | 57 | private PasswordEncoder passwordEncoder; |
| 60 | @Resource | 58 | @Resource |
| 61 | - private MbrUserMapper mbrUserMapper; | 59 | + private UserMapper mbrUserMapper; |
| 62 | @Resource | 60 | @Resource |
| 63 | - private SysAuthServiceImpl authService; | 61 | + private AuthServiceImpl authService; |
| 64 | 62 | ||
| 65 | @Test | 63 | @Test |
| 66 | public void testUpdatePassword_success(){ | 64 | public void testUpdatePassword_success(){ |
| 67 | // 准备参数 | 65 | // 准备参数 |
| 68 | - MbrUserDO userDO = randomMbrUserDO(); | 66 | + UserDO userDO = randomUserDO(); |
| 69 | mbrUserMapper.insert(userDO); | 67 | mbrUserMapper.insert(userDO); |
| 70 | 68 | ||
| 71 | // 新密码 | 69 | // 新密码 |
| 72 | String newPassword = randomString(); | 70 | String newPassword = randomString(); |
| 73 | 71 | ||
| 74 | // 请求实体 | 72 | // 请求实体 |
| 75 | - MbrAuthUpdatePasswordReqVO reqVO = MbrAuthUpdatePasswordReqVO.builder() | 73 | + AppAuthUpdatePasswordReqVO reqVO = AppAuthUpdatePasswordReqVO.builder() |
| 76 | .oldPassword(userDO.getPassword()) | 74 | .oldPassword(userDO.getPassword()) |
| 77 | .password(newPassword) | 75 | .password(newPassword) |
| 78 | .build(); | 76 | .build(); |
| @@ -83,14 +81,14 @@ public class SysAuthServiceTest extends BaseDbAndRedisUnitTest { | @@ -83,14 +81,14 @@ public class SysAuthServiceTest extends BaseDbAndRedisUnitTest { | ||
| 83 | when(passwordEncoder.encode(newPassword)).thenReturn(newPassword); | 81 | when(passwordEncoder.encode(newPassword)).thenReturn(newPassword); |
| 84 | 82 | ||
| 85 | // 更新用户密码 | 83 | // 更新用户密码 |
| 86 | - authService.updatePassword(userDO.getId(),reqVO); | 84 | + authService.updatePassword(userDO.getId(), reqVO); |
| 87 | assertEquals(mbrUserMapper.selectById(userDO.getId()).getPassword(),newPassword); | 85 | assertEquals(mbrUserMapper.selectById(userDO.getId()).getPassword(),newPassword); |
| 88 | } | 86 | } |
| 89 | 87 | ||
| 90 | @Test | 88 | @Test |
| 91 | public void testResetPassword_success(){ | 89 | public void testResetPassword_success(){ |
| 92 | // 准备参数 | 90 | // 准备参数 |
| 93 | - MbrUserDO userDO = randomMbrUserDO(); | 91 | + UserDO userDO = randomUserDO(); |
| 94 | mbrUserMapper.insert(userDO); | 92 | mbrUserMapper.insert(userDO); |
| 95 | 93 | ||
| 96 | // 随机密码 | 94 | // 随机密码 |
| @@ -102,7 +100,7 @@ public class SysAuthServiceTest extends BaseDbAndRedisUnitTest { | @@ -102,7 +100,7 @@ public class SysAuthServiceTest extends BaseDbAndRedisUnitTest { | ||
| 102 | when(passwordEncoder.encode(password)).thenReturn(password); | 100 | when(passwordEncoder.encode(password)).thenReturn(password); |
| 103 | 101 | ||
| 104 | // 更新用户密码 | 102 | // 更新用户密码 |
| 105 | - MbrAuthResetPasswordReqVO reqVO = new MbrAuthResetPasswordReqVO(); | 103 | + AppAuthResetPasswordReqVO reqVO = new AppAuthResetPasswordReqVO(); |
| 106 | reqVO.setMobile(userDO.getMobile()); | 104 | reqVO.setMobile(userDO.getMobile()); |
| 107 | reqVO.setPassword(password); | 105 | reqVO.setPassword(password); |
| 108 | reqVO.setCode(code); | 106 | reqVO.setCode(code); |
| @@ -115,12 +113,12 @@ public class SysAuthServiceTest extends BaseDbAndRedisUnitTest { | @@ -115,12 +113,12 @@ public class SysAuthServiceTest extends BaseDbAndRedisUnitTest { | ||
| 115 | // ========== 随机对象 ========== | 113 | // ========== 随机对象 ========== |
| 116 | 114 | ||
| 117 | @SafeVarargs | 115 | @SafeVarargs |
| 118 | - private static MbrUserDO randomMbrUserDO(Consumer<MbrUserDO>... consumers) { | ||
| 119 | - Consumer<MbrUserDO> consumer = (o) -> { | 116 | + private static UserDO randomUserDO(Consumer<UserDO>... consumers) { |
| 117 | + Consumer<UserDO> consumer = (o) -> { | ||
| 120 | o.setStatus(randomEle(CommonStatusEnum.values()).getStatus()); // 保证 status 的范围 | 118 | o.setStatus(randomEle(CommonStatusEnum.values()).getStatus()); // 保证 status 的范围 |
| 121 | o.setPassword(randomString()); | 119 | o.setPassword(randomString()); |
| 122 | }; | 120 | }; |
| 123 | - return randomPojo(MbrUserDO.class, ArrayUtils.append(consumer, consumers)); | 121 | + return randomPojo(UserDO.class, ArrayUtils.append(consumer, consumers)); |
| 124 | } | 122 | } |
| 125 | 123 | ||
| 126 | 124 |
yudao-module-member/yudao-module-member-impl/src/test/java/cn/iocoder/yudao/module/member/service/package-info.java deleted
| 1 | -package cn.iocoder.yudao.module.member.service; |
yudao-module-member/yudao-module-member-impl/src/test/java/cn/iocoder/yudao/module/member/service/user/MbrUserServiceImplTest.java
| @@ -2,18 +2,17 @@ package cn.iocoder.yudao.module.member.service.user; | @@ -2,18 +2,17 @@ package cn.iocoder.yudao.module.member.service.user; | ||
| 2 | 2 | ||
| 3 | import cn.hutool.core.util.RandomUtil; | 3 | import cn.hutool.core.util.RandomUtil; |
| 4 | import cn.iocoder.yudao.coreservice.modules.infra.service.file.InfFileCoreService; | 4 | import cn.iocoder.yudao.coreservice.modules.infra.service.file.InfFileCoreService; |
| 5 | -import cn.iocoder.yudao.coreservice.modules.member.dal.dataobject.user.MbrUserDO; | ||
| 6 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | 5 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 7 | import cn.iocoder.yudao.framework.common.util.collection.ArrayUtils; | 6 | import cn.iocoder.yudao.framework.common.util.collection.ArrayUtils; |
| 8 | import cn.iocoder.yudao.framework.redis.config.YudaoRedisAutoConfiguration; | 7 | import cn.iocoder.yudao.framework.redis.config.YudaoRedisAutoConfiguration; |
| 9 | -import cn.iocoder.yudao.userserver.BaseDbAndRedisUnitTest; | ||
| 10 | -import cn.iocoder.yudao.userserver.modules.member.controller.user.vo.MbrUserInfoRespVO; | ||
| 11 | -import cn.iocoder.yudao.userserver.modules.member.controller.user.vo.MbrUserUpdateMobileReqVO; | ||
| 12 | -import cn.iocoder.yudao.userserver.modules.member.dal.mysql.user.MbrUserMapper; | ||
| 13 | -import cn.iocoder.yudao.userserver.modules.member.service.user.impl.MbrUserServiceImpl; | ||
| 14 | -import cn.iocoder.yudao.userserver.modules.system.dal.dataobject.sms.SysSmsCodeDO; | ||
| 15 | -import cn.iocoder.yudao.userserver.modules.system.service.auth.impl.SysAuthServiceImpl; | ||
| 16 | -import cn.iocoder.yudao.userserver.modules.system.service.sms.SysSmsCodeService; | 8 | +import cn.iocoder.yudao.module.member.controller.app.user.vo.AppUserUpdateMobileReqVO; |
| 9 | +import cn.iocoder.yudao.module.member.dal.dataobject.sms.SysSmsCodeDO; | ||
| 10 | +import cn.iocoder.yudao.module.member.dal.dataobject.user.UserDO; | ||
| 11 | +import cn.iocoder.yudao.module.member.dal.mysql.user.UserMapper; | ||
| 12 | +import cn.iocoder.yudao.module.member.enums.sms.SysSmsSceneEnum; | ||
| 13 | +import cn.iocoder.yudao.module.member.service.auth.AuthServiceImpl; | ||
| 14 | +import cn.iocoder.yudao.module.member.service.sms.SysSmsCodeService; | ||
| 15 | +import cn.iocoder.yudao.module.member.test.BaseDbAndRedisUnitTest; | ||
| 17 | import org.junit.jupiter.api.Test; | 16 | import org.junit.jupiter.api.Test; |
| 18 | import org.springframework.boot.test.mock.mockito.MockBean; | 17 | import org.springframework.boot.test.mock.mockito.MockBean; |
| 19 | import org.springframework.context.annotation.Import; | 18 | import org.springframework.context.annotation.Import; |
| @@ -27,30 +26,29 @@ import java.util.function.Consumer; | @@ -27,30 +26,29 @@ import java.util.function.Consumer; | ||
| 27 | import static cn.hutool.core.util.RandomUtil.*; | 26 | import static cn.hutool.core.util.RandomUtil.*; |
| 28 | import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo; | 27 | import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo; |
| 29 | import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomString; | 28 | import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomString; |
| 30 | -import static cn.iocoder.yudao.userserver.modules.system.enums.sms.SysSmsSceneEnum.CHANGE_MOBILE_BY_SMS; | ||
| 31 | import static org.junit.jupiter.api.Assertions.assertEquals; | 29 | import static org.junit.jupiter.api.Assertions.assertEquals; |
| 32 | import static org.mockito.Mockito.*; | 30 | import static org.mockito.Mockito.*; |
| 33 | 31 | ||
| 34 | // TODO @芋艿:单测的 review,等逻辑都达成一致后 | 32 | // TODO @芋艿:单测的 review,等逻辑都达成一致后 |
| 35 | /** | 33 | /** |
| 36 | - * {@link MbrUserServiceImpl} 的单元测试类 | 34 | + * {@link UserServiceImpl} 的单元测试类 |
| 37 | * | 35 | * |
| 38 | * @author 宋天 | 36 | * @author 宋天 |
| 39 | */ | 37 | */ |
| 40 | -@Import({MbrUserServiceImpl.class, YudaoRedisAutoConfiguration.class}) | 38 | +@Import({UserServiceImpl.class, YudaoRedisAutoConfiguration.class}) |
| 41 | public class MbrUserServiceImplTest extends BaseDbAndRedisUnitTest { | 39 | public class MbrUserServiceImplTest extends BaseDbAndRedisUnitTest { |
| 42 | 40 | ||
| 43 | @Resource | 41 | @Resource |
| 44 | - private MbrUserServiceImpl mbrUserService; | 42 | + private UserServiceImpl mbrUserService; |
| 45 | 43 | ||
| 46 | @Resource | 44 | @Resource |
| 47 | private StringRedisTemplate stringRedisTemplate; | 45 | private StringRedisTemplate stringRedisTemplate; |
| 48 | 46 | ||
| 49 | @Resource | 47 | @Resource |
| 50 | - private MbrUserMapper userMapper; | 48 | + private UserMapper userMapper; |
| 51 | 49 | ||
| 52 | @MockBean | 50 | @MockBean |
| 53 | - private SysAuthServiceImpl authService; | 51 | + private AuthServiceImpl authService; |
| 54 | 52 | ||
| 55 | @MockBean | 53 | @MockBean |
| 56 | private InfFileCoreService fileCoreService; | 54 | private InfFileCoreService fileCoreService; |
| @@ -64,14 +62,14 @@ public class MbrUserServiceImplTest extends BaseDbAndRedisUnitTest { | @@ -64,14 +62,14 @@ public class MbrUserServiceImplTest extends BaseDbAndRedisUnitTest { | ||
| 64 | @Test | 62 | @Test |
| 65 | public void testUpdateNickName_success(){ | 63 | public void testUpdateNickName_success(){ |
| 66 | // mock 数据 | 64 | // mock 数据 |
| 67 | - MbrUserDO userDO = randomMbrUserDO(); | 65 | + UserDO userDO = randomUserDO(); |
| 68 | userMapper.insert(userDO); | 66 | userMapper.insert(userDO); |
| 69 | 67 | ||
| 70 | // 随机昵称 | 68 | // 随机昵称 |
| 71 | String newNickName = randomString(); | 69 | String newNickName = randomString(); |
| 72 | 70 | ||
| 73 | // 调用接口修改昵称 | 71 | // 调用接口修改昵称 |
| 74 | - mbrUserService.updateNickname(userDO.getId(),newNickName); | 72 | + mbrUserService.updateUserNickname(userDO.getId(),newNickName); |
| 75 | // 查询新修改后的昵称 | 73 | // 查询新修改后的昵称 |
| 76 | String nickname = mbrUserService.getUser(userDO.getId()).getNickname(); | 74 | String nickname = mbrUserService.getUser(userDO.getId()).getNickname(); |
| 77 | // 断言 | 75 | // 断言 |
| @@ -79,20 +77,9 @@ public class MbrUserServiceImplTest extends BaseDbAndRedisUnitTest { | @@ -79,20 +77,9 @@ public class MbrUserServiceImplTest extends BaseDbAndRedisUnitTest { | ||
| 79 | } | 77 | } |
| 80 | 78 | ||
| 81 | @Test | 79 | @Test |
| 82 | - public void testGetUserInfo_success(){ | ||
| 83 | - // mock 数据 | ||
| 84 | - MbrUserDO userDO = randomMbrUserDO(); | ||
| 85 | - userMapper.insert(userDO); | ||
| 86 | - | ||
| 87 | - // 查询用户昵称与头像 | ||
| 88 | - MbrUserInfoRespVO userInfo = mbrUserService.getUserInfo(userDO.getId()); | ||
| 89 | - System.out.println(userInfo); | ||
| 90 | - } | ||
| 91 | - | ||
| 92 | - @Test | ||
| 93 | public void testUpdateAvatar_success(){ | 80 | public void testUpdateAvatar_success(){ |
| 94 | // mock 数据 | 81 | // mock 数据 |
| 95 | - MbrUserDO dbUser = randomMbrUserDO(); | 82 | + UserDO dbUser = randomUserDO(); |
| 96 | userMapper.insert(dbUser); | 83 | userMapper.insert(dbUser); |
| 97 | 84 | ||
| 98 | // 准备参数 | 85 | // 准备参数 |
| @@ -103,7 +90,7 @@ public class MbrUserServiceImplTest extends BaseDbAndRedisUnitTest { | @@ -103,7 +90,7 @@ public class MbrUserServiceImplTest extends BaseDbAndRedisUnitTest { | ||
| 103 | String avatar = randomString(); | 90 | String avatar = randomString(); |
| 104 | when(fileCoreService.createFile(anyString(), eq(avatarFileBytes))).thenReturn(avatar); | 91 | when(fileCoreService.createFile(anyString(), eq(avatarFileBytes))).thenReturn(avatar); |
| 105 | // 调用 | 92 | // 调用 |
| 106 | - String str = mbrUserService.updateAvatar(userId, avatarFile); | 93 | + String str = mbrUserService.updateUserAvatar(userId, avatarFile); |
| 107 | // 断言 | 94 | // 断言 |
| 108 | assertEquals(avatar, str); | 95 | assertEquals(avatar, str); |
| 109 | } | 96 | } |
| @@ -112,11 +99,10 @@ public class MbrUserServiceImplTest extends BaseDbAndRedisUnitTest { | @@ -112,11 +99,10 @@ public class MbrUserServiceImplTest extends BaseDbAndRedisUnitTest { | ||
| 112 | public void updateMobile_success(){ | 99 | public void updateMobile_success(){ |
| 113 | // mock数据 | 100 | // mock数据 |
| 114 | String oldMobile = randomNumbers(11); | 101 | String oldMobile = randomNumbers(11); |
| 115 | - MbrUserDO userDO = randomMbrUserDO(); | 102 | + UserDO userDO = randomUserDO(); |
| 116 | userDO.setMobile(oldMobile); | 103 | userDO.setMobile(oldMobile); |
| 117 | userMapper.insert(userDO); | 104 | userMapper.insert(userDO); |
| 118 | 105 | ||
| 119 | - | ||
| 120 | // 旧手机和旧验证码 | 106 | // 旧手机和旧验证码 |
| 121 | SysSmsCodeDO codeDO = new SysSmsCodeDO(); | 107 | SysSmsCodeDO codeDO = new SysSmsCodeDO(); |
| 122 | String oldCode = RandomUtil.randomString(4); | 108 | String oldCode = RandomUtil.randomString(4); |
| @@ -129,12 +115,12 @@ public class MbrUserServiceImplTest extends BaseDbAndRedisUnitTest { | @@ -129,12 +115,12 @@ public class MbrUserServiceImplTest extends BaseDbAndRedisUnitTest { | ||
| 129 | // 更新手机号 | 115 | // 更新手机号 |
| 130 | String newMobile = randomNumbers(11); | 116 | String newMobile = randomNumbers(11); |
| 131 | String newCode = randomNumbers(4); | 117 | String newCode = randomNumbers(4); |
| 132 | - MbrUserUpdateMobileReqVO reqVO = new MbrUserUpdateMobileReqVO(); | 118 | + AppUserUpdateMobileReqVO reqVO = new AppUserUpdateMobileReqVO(); |
| 133 | reqVO.setMobile(newMobile); | 119 | reqVO.setMobile(newMobile); |
| 134 | reqVO.setCode(newCode); | 120 | reqVO.setCode(newCode); |
| 135 | reqVO.setOldMobile(oldMobile); | 121 | reqVO.setOldMobile(oldMobile); |
| 136 | reqVO.setOldCode(oldCode); | 122 | reqVO.setOldCode(oldCode); |
| 137 | - mbrUserService.updateMobile(userDO.getId(),reqVO); | 123 | + mbrUserService.updateUserMobile(userDO.getId(),reqVO); |
| 138 | 124 | ||
| 139 | assertEquals(mbrUserService.getUser(userDO.getId()).getMobile(),newMobile); | 125 | assertEquals(mbrUserService.getUser(userDO.getId()).getMobile(),newMobile); |
| 140 | } | 126 | } |
| @@ -142,11 +128,11 @@ public class MbrUserServiceImplTest extends BaseDbAndRedisUnitTest { | @@ -142,11 +128,11 @@ public class MbrUserServiceImplTest extends BaseDbAndRedisUnitTest { | ||
| 142 | // ========== 随机对象 ========== | 128 | // ========== 随机对象 ========== |
| 143 | 129 | ||
| 144 | @SafeVarargs | 130 | @SafeVarargs |
| 145 | - private static MbrUserDO randomMbrUserDO(Consumer<MbrUserDO>... consumers) { | ||
| 146 | - Consumer<MbrUserDO> consumer = (o) -> { | 131 | + private static UserDO randomUserDO(Consumer<UserDO>... consumers) { |
| 132 | + Consumer<UserDO> consumer = (o) -> { | ||
| 147 | o.setStatus(randomEle(CommonStatusEnum.values()).getStatus()); // 保证 status 的范围 | 133 | o.setStatus(randomEle(CommonStatusEnum.values()).getStatus()); // 保证 status 的范围 |
| 148 | }; | 134 | }; |
| 149 | - return randomPojo(MbrUserDO.class, ArrayUtils.append(consumer, consumers)); | 135 | + return randomPojo(UserDO.class, ArrayUtils.append(consumer, consumers)); |
| 150 | } | 136 | } |
| 151 | 137 | ||
| 152 | } | 138 | } |
yudao-module-member/yudao-module-member-impl/src/test/java/cn/iocoder/yudao/module/member/test/BaseDbAndRedisUnitTest.java
| @@ -3,7 +3,6 @@ package cn.iocoder.yudao.module.member.test; | @@ -3,7 +3,6 @@ package cn.iocoder.yudao.module.member.test; | ||
| 3 | import cn.iocoder.yudao.framework.datasource.config.YudaoDataSourceAutoConfiguration; | 3 | import cn.iocoder.yudao.framework.datasource.config.YudaoDataSourceAutoConfiguration; |
| 4 | import cn.iocoder.yudao.framework.mybatis.config.YudaoMybatisAutoConfiguration; | 4 | import cn.iocoder.yudao.framework.mybatis.config.YudaoMybatisAutoConfiguration; |
| 5 | import cn.iocoder.yudao.framework.redis.config.YudaoRedisAutoConfiguration; | 5 | import cn.iocoder.yudao.framework.redis.config.YudaoRedisAutoConfiguration; |
| 6 | -import cn.iocoder.yudao.userserver.config.RedisTestConfiguration; | ||
| 7 | import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure; | 6 | import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure; |
| 8 | import com.baomidou.mybatisplus.autoconfigure.MybatisPlusAutoConfiguration; | 7 | import com.baomidou.mybatisplus.autoconfigure.MybatisPlusAutoConfiguration; |
| 9 | import org.redisson.spring.starter.RedissonAutoConfiguration; | 8 | import org.redisson.spring.starter.RedissonAutoConfiguration; |
yudao-module-member/yudao-module-member-impl/src/test/resources/application-unit-test.yaml
| @@ -42,3 +42,8 @@ mybatis: | @@ -42,3 +42,8 @@ mybatis: | ||
| 42 | --- #################### 芋道相关配置 #################### | 42 | --- #################### 芋道相关配置 #################### |
| 43 | 43 | ||
| 44 | # 芋道配置项,设置当前项目所有自定义的配置 | 44 | # 芋道配置项,设置当前项目所有自定义的配置 |
| 45 | +yudao: | ||
| 46 | + info: | ||
| 47 | + base-package: cn.iocoder.yudao.module.member.dal.mysql | ||
| 48 | + core-service: | ||
| 49 | + base-package: cn.iocoder.yudao.module.member.dal.mysql # TODO 芋艿:要清理掉 |
yudao-user-server/src/main/resources/application-dev.yaml
| @@ -124,6 +124,19 @@ logging: | @@ -124,6 +124,19 @@ logging: | ||
| 124 | file: | 124 | file: |
| 125 | name: ${user.home}/logs/${spring.application.name}.log # 日志文件名,全路径 | 125 | name: ${user.home}/logs/${spring.application.name}.log # 日志文件名,全路径 |
| 126 | 126 | ||
| 127 | + | ||
| 128 | +--- #################### 微信公众号相关配置 #################### | ||
| 129 | +wx: # 参见 https://github.com/Wechat-Group/WxJava/blob/develop/spring-boot-starters/wx-java-mp-spring-boot-starter/README.md 文档 | ||
| 130 | + mp: | ||
| 131 | + # 公众号配置(必填) | ||
| 132 | + app-id: wx041349c6f39b268b | ||
| 133 | + secret: 5abee519483bc9f8cb37ce280e814bd0 | ||
| 134 | + # 存储配置,解决 AccessToken 的跨节点的共享 | ||
| 135 | + config-storage: | ||
| 136 | + type: RedisTemplate # 采用 RedisTemplate 操作 Redis,会自动从 Spring 中获取 | ||
| 137 | + key-prefix: wx # Redis Key 的前缀 TODO 芋艿:解决下 Redis key 管理的配置 | ||
| 138 | + http-client-type: HttpClient # 采用 HttpClient 请求微信公众号平台 | ||
| 139 | + | ||
| 127 | --- #################### 芋道相关配置 #################### | 140 | --- #################### 芋道相关配置 #################### |
| 128 | 141 | ||
| 129 | # 芋道配置项,设置当前项目所有自定义的配置 | 142 | # 芋道配置项,设置当前项目所有自定义的配置 |
yudao-user-server/src/main/resources/application.yaml
| @@ -66,11 +66,6 @@ yudao: | @@ -66,11 +66,6 @@ yudao: | ||
| 66 | constants-class-list: | 66 | constants-class-list: |
| 67 | - cn.iocoder.yudao.userserver.modules.member.enums.MbrErrorCodeConstants | 67 | - cn.iocoder.yudao.userserver.modules.member.enums.MbrErrorCodeConstants |
| 68 | - cn.iocoder.yudao.userserver.modules.system.enums.SysErrorCodeConstants | 68 | - cn.iocoder.yudao.userserver.modules.system.enums.SysErrorCodeConstants |
| 69 | - sms-code: # 短信验证码相关的配置项 | ||
| 70 | - expire-times: 10m | ||
| 71 | - send-frequency: 1m | ||
| 72 | - send-maximum-quantity-per-day: 10 | ||
| 73 | - begin-code: 9999 # 这里配置 9999 的原因是,测试方便。 | ||
| 74 | - end-code: 9999 # 这里配置 9999 的原因是,测试方便。 | 69 | + |
| 75 | 70 | ||
| 76 | debug: false | 71 | debug: false |