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 | 17 | <url>https://github.com/YunaiV/ruoyi-vue-pro</url> |
| 18 | 18 | |
| 19 | 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 | 28 | <dependency> |
| 22 | 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 | 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; |
| 5 | 5 | |
| 6 | 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 | 9 | public class AdminServerApplication { |
| 9 | 10 | |
| 10 | 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 | 23 | public Customizer<ExpressionUrlAuthorizationConfigurer<HttpSecurity>.ExpressionInterceptUrlRegistry> authorizeRequestsCustomizer() { |
| 24 | 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 | 29 | // Spring Boot Admin Server 的安全配置 |
| 30 | 30 | registry.antMatchers(adminSeverContextPath).anonymous() |
| 31 | 31 | .antMatchers(adminSeverContextPath + "/**").anonymous(); |
| 32 | 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 | 11 | import cn.iocoder.yudao.adminserver.modules.system.service.permission.SysPermissionService; |
| 12 | 12 | import cn.iocoder.yudao.adminserver.modules.system.service.user.SysUserService; |
| 13 | 13 | import org.activiti.api.runtime.shared.identity.UserGroupManager; |
| 14 | +import org.activiti.core.common.spring.identity.ActivitiUserGroupManagerImpl; | |
| 14 | 15 | import org.activiti.spring.boot.ProcessEngineConfigurationConfigurer; |
| 15 | 16 | import org.springframework.context.ApplicationEventPublisher; |
| 16 | 17 | import org.springframework.context.annotation.Bean; |
| 17 | 18 | import org.springframework.context.annotation.Configuration; |
| 19 | +import org.springframework.security.core.userdetails.UserDetailsService; | |
| 18 | 20 | |
| 19 | 21 | import java.util.Collections; |
| 20 | 22 | import java.util.List; |
| ... | ... | @@ -28,7 +30,15 @@ import static org.activiti.spring.boot.ProcessEngineAutoConfiguration.BEHAVIOR_F |
| 28 | 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 | 43 | @Bean |
| 34 | 44 | public ProcessEngineConfigurationConfigurer bpmProcessEngineConfigurationConfigurer( |
| ... | ... | @@ -36,8 +46,6 @@ public class BpmActivitiConfiguration { |
| 36 | 46 | return configuration -> { |
| 37 | 47 | // 注册监听器,例如说 BpmActivitiEventListener |
| 38 | 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 | 60 | @Slf4j |
| 61 | 61 | public class SysAuthServiceImpl implements SysAuthService { |
| 62 | 62 | |
| 63 | - private static final UserTypeEnum USER_TYPE_ENUM = UserTypeEnum.ADMIN; | |
| 64 | - | |
| 65 | 63 | @Resource |
| 66 | 64 | @Lazy // 延迟加载,因为存在相互依赖的问题 |
| 67 | 65 | private AuthenticationManager authenticationManager; |
| ... | ... | @@ -83,7 +81,6 @@ public class SysAuthServiceImpl implements SysAuthService { |
| 83 | 81 | @Resource |
| 84 | 82 | private SysSocialCoreService socialService; |
| 85 | 83 | |
| 86 | - | |
| 87 | 84 | @Override |
| 88 | 85 | public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { |
| 89 | 86 | // 获取 username 对应的 SysUserDO |
| ... | ... | @@ -216,7 +213,7 @@ public class SysAuthServiceImpl implements SysAuthService { |
| 216 | 213 | |
| 217 | 214 | // 如果未绑定 SysSocialUserDO 用户,则无法自动登录,进行报错 |
| 218 | 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 | 217 | if (CollUtil.isEmpty(socialUsers)) { |
| 221 | 218 | throw exception(AUTH_THIRD_LOGIN_NOT_BIND); |
| 222 | 219 | } |
| ... | ... | @@ -232,7 +229,7 @@ public class SysAuthServiceImpl implements SysAuthService { |
| 232 | 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 | 234 | // 缓存登录用户到 Redis 中,返回 sessionId 编号 |
| 238 | 235 | return userSessionCoreService.createUserSession(loginUser, userIp, userAgent); |
| ... | ... | @@ -248,7 +245,7 @@ public class SysAuthServiceImpl implements SysAuthService { |
| 248 | 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 | 250 | // 缓存登录用户到 Redis 中,返回 sessionId 编号 |
| 254 | 251 | return userSessionCoreService.createUserSession(loginUser, userIp, userAgent); |
| ... | ... | @@ -261,7 +258,7 @@ public class SysAuthServiceImpl implements SysAuthService { |
| 261 | 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 | 264 | @Override |
| ... | ... | @@ -277,12 +274,17 @@ public class SysAuthServiceImpl implements SysAuthService { |
| 277 | 274 | this.createLogoutLog(loginUser.getId(), loginUser.getUsername()); |
| 278 | 275 | } |
| 279 | 276 | |
| 277 | + @Override | |
| 278 | + public UserTypeEnum getUserType() { | |
| 279 | + return UserTypeEnum.ADMIN; | |
| 280 | + } | |
| 281 | + | |
| 280 | 282 | private void createLogoutLog(Long userId, String username) { |
| 281 | 283 | SysLoginLogCreateReqDTO reqDTO = new SysLoginLogCreateReqDTO(); |
| 282 | 284 | reqDTO.setLogType(SysLoginLogTypeEnum.LOGOUT_SELF.getType()); |
| 283 | 285 | reqDTO.setTraceId(TracerUtils.getTraceId()); |
| 284 | 286 | reqDTO.setUserId(userId); |
| 285 | - reqDTO.setUserType(USER_TYPE_ENUM.getValue()); | |
| 287 | + reqDTO.setUserType(getUserType().getValue()); | |
| 286 | 288 | reqDTO.setUsername(username); |
| 287 | 289 | reqDTO.setUserAgent(ServletUtils.getUserAgent()); |
| 288 | 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 | 23 | import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; |
| 24 | 24 | import com.google.common.annotations.VisibleForTesting; |
| 25 | 25 | import lombok.extern.slf4j.Slf4j; |
| 26 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 26 | 27 | import org.springframework.beans.factory.annotation.Value; |
| 27 | 28 | import org.springframework.security.crypto.password.PasswordEncoder; |
| 28 | 29 | import org.springframework.stereotype.Service; |
| ... | ... | @@ -47,7 +48,7 @@ public class SysUserServiceImpl implements SysUserService { |
| 47 | 48 | @Value("${sys.user.init-password:yudaoyuanma}") |
| 48 | 49 | private String userInitPassword; |
| 49 | 50 | |
| 50 | - @Resource | |
| 51 | + @Resource(name = "sysUserMapper") // userMapper 存在重名 | |
| 51 | 52 | private SysUserMapper userMapper; |
| 52 | 53 | |
| 53 | 54 | @Resource | ... | ... |
yudao-admin-server/src/main/resources/application-local.yaml
| ... | ... | @@ -174,6 +174,18 @@ logging: |
| 174 | 174 | cn.iocoder.yudao.coreservice.modules.system.dal.mysql: debug |
| 175 | 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 | 48 | info: |
| 49 | 49 | version: 1.0.0 |
| 50 | 50 | base-package: cn.iocoder.yudao.adminserver |
| 51 | + member-package: cn.iocoder.yudao.module.member | |
| 51 | 52 | core-service: |
| 52 | 53 | base-package: cn.iocoder.yudao.coreservice |
| 53 | 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 | 62 | swagger: |
| 57 | 63 | title: 管理后台 |
| 58 | 64 | description: 提供管理员管理的所有功能 |
| ... | ... | @@ -72,7 +78,13 @@ yudao: |
| 72 | 78 | - cn.iocoder.yudao.adminserver.modules.bpm.enums.BpmErrorCodeConstants |
| 73 | 79 | tenant: # 多租户相关配置项 |
| 74 | 80 | tables: # 配置需要开启多租户的表;如果实体已经继承 TenantBaseDO 类,则无需重复配置 |
| 75 | - url: | |
| 81 | + url: ## TODO 芋艿:迁移到 web 配置项下, | |
| 76 | 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 | 90 | debug: false | ... | ... |
yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/service/file/InfFileCoreService.java
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 | 2 | |
| 3 | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | 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 | 5 | import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.sms.SysSmsTemplateDO; |
| 8 | 6 | import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.user.SysUserDO; |
| 9 | 7 | import cn.iocoder.yudao.coreservice.modules.system.mq.message.sms.SysSmsSendMessage; |
| ... | ... | @@ -43,8 +41,6 @@ public class SysSmsCoreServiceImpl implements SysSmsCoreService { |
| 43 | 41 | @Resource |
| 44 | 42 | private SysUserCoreService sysUserCoreService; |
| 45 | 43 | @Resource |
| 46 | - private MbrUserCoreService mbrUserCoreService; | |
| 47 | - @Resource | |
| 48 | 44 | private SysSmsTemplateCoreService smsTemplateCoreService; |
| 49 | 45 | @Resource |
| 50 | 46 | private SysSmsLogCoreService smsLogCoreService; |
| ... | ... | @@ -72,10 +68,11 @@ public class SysSmsCoreServiceImpl implements SysSmsCoreService { |
| 72 | 68 | public Long sendSingleSmsToMember(String mobile, Long userId, String templateCode, Map<String, Object> templateParams) { |
| 73 | 69 | // 如果 mobile 为空,则加载用户编号对应的手机号 |
| 74 | 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 | 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 | 15 | * @author 芋道源码 |
| 16 | 16 | */ |
| 17 | 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 | 20 | lazyInitialization = "${mybatis.lazy-initialization:false}") // Mapper 懒加载,目前仅用于单元测试 |
| 20 | 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 | 7 | import cn.iocoder.yudao.framework.security.core.handler.AuthenticationEntryPointImpl; |
| 8 | 8 | import cn.iocoder.yudao.framework.security.core.handler.LogoutSuccessHandlerImpl; |
| 9 | 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 | 13 | import cn.iocoder.yudao.framework.web.core.handler.GlobalExceptionHandler; |
| 11 | 14 | import org.springframework.beans.factory.config.MethodInvokingFactoryBean; |
| 12 | 15 | import org.springframework.boot.context.properties.EnableConfigurationProperties; |
| ... | ... | @@ -20,6 +23,7 @@ import org.springframework.security.web.access.AccessDeniedHandler; |
| 20 | 23 | import org.springframework.security.web.authentication.logout.LogoutSuccessHandler; |
| 21 | 24 | |
| 22 | 25 | import javax.annotation.Resource; |
| 26 | +import java.util.List; | |
| 23 | 27 | |
| 24 | 28 | /** |
| 25 | 29 | * Spring Security 自动配置类,主要用于相关组件的配置 |
| ... | ... | @@ -29,7 +33,7 @@ import javax.annotation.Resource; |
| 29 | 33 | * |
| 30 | 34 | * @author 芋道源码 |
| 31 | 35 | */ |
| 32 | -@Configuration | |
| 36 | +@Configuration(proxyBeanMethods = false) | |
| 33 | 37 | @EnableConfigurationProperties(SecurityProperties.class) |
| 34 | 38 | public class YudaoSecurityAutoConfiguration { |
| 35 | 39 | |
| ... | ... | @@ -64,8 +68,8 @@ public class YudaoSecurityAutoConfiguration { |
| 64 | 68 | * 退出处理类 Bean |
| 65 | 69 | */ |
| 66 | 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 | 87 | * Token 认证过滤器 Bean |
| 84 | 88 | */ |
| 85 | 89 | @Bean |
| 86 | - public JWTAuthenticationTokenFilter authenticationTokenFilter(SecurityAuthFrameworkService securityFrameworkService, | |
| 90 | + public JWTAuthenticationTokenFilter authenticationTokenFilter(SecurityAuthService securityAuthService, | |
| 87 | 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 | 65 | */ |
| 66 | 66 | @Resource |
| 67 | 67 | private JWTAuthenticationTokenFilter authenticationTokenFilter; |
| 68 | + | |
| 68 | 69 | /** |
| 69 | 70 | * 自定义的权限映射 Bean |
| 70 | 71 | * |
| 71 | 72 | * @see #configure(HttpSecurity) |
| 72 | 73 | */ |
| 73 | 74 | @Resource |
| 74 | - private Customizer<ExpressionUrlAuthorizationConfigurer<HttpSecurity>.ExpressionInterceptUrlRegistry> authorizeRequestsCustomizer; | |
| 75 | + private Customizer<ExpressionUrlAuthorizationConfigurer<HttpSecurity>.ExpressionInterceptUrlRegistry> | |
| 76 | + authorizeRequestsCustomizer; | |
| 75 | 77 | |
| 76 | 78 | /** |
| 77 | 79 | * 由于 Spring Security 创建 AuthenticationManager 对象时,没声明 @Bean 注解,导致无法被注入 |
| ... | ... | @@ -89,8 +91,8 @@ public class YudaoWebSecurityConfigurerAdapter extends WebSecurityConfigurerAdap |
| 89 | 91 | */ |
| 90 | 92 | @Override |
| 91 | 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 | 125 | // 一堆自定义的 Spring Security 处理器 |
| 124 | 126 | .exceptionHandling().authenticationEntryPoint(authenticationEntryPoint) |
| 125 | 127 | .accessDeniedHandler(accessDeniedHandler).and() |
| 126 | - .logout().logoutUrl(api("/logout")).logoutSuccessHandler(logoutSuccessHandler); // 登出 | |
| 128 | + .logout().logoutUrl(buildAdminApi("/logout")).logoutSuccessHandler(logoutSuccessHandler); // 登出 | |
| 127 | 129 | |
| 128 | 130 | // 设置每个请求的权限 ①:全局共享规则 |
| 129 | 131 | httpSecurity.authorizeRequests() |
| 130 | 132 | // 登录的接口,可匿名访问 |
| 131 | - .antMatchers(api("/login")).anonymous() | |
| 133 | + .antMatchers(buildAdminApi("/login")).anonymous() | |
| 132 | 134 | // 静态资源,可匿名访问 |
| 133 | 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 | 138 | // Swagger 接口文档 |
| 137 | 139 | .antMatchers("/swagger-ui.html").anonymous() |
| 138 | 140 | .antMatchers("/swagger-resources/**").anonymous() |
| ... | ... | @@ -143,11 +145,11 @@ public class YudaoWebSecurityConfigurerAdapter extends WebSecurityConfigurerAdap |
| 143 | 145 | .antMatchers("/actuator/**").anonymous() |
| 144 | 146 | // Druid 监控 TODO 芋艿:等对接了 druid admin 后,在调整下。 |
| 145 | 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 | 151 | .antMatchers("/api/callback/**").anonymous() |
| 150 | - // 设置每个请求的权限 ②:每个项目的自定义规则 | |
| 152 | + // 设置每个请求的权限 ②:每个项目的自定义规则 TODO 芋艿:改造成多个,方便每个模块自定义规则 | |
| 151 | 153 | .and().authorizeRequests(authorizeRequestsCustomizer) |
| 152 | 154 | // 设置每个请求的权限 ③:兜底规则,必须认证 |
| 153 | 155 | .authorizeRequests().anyRequest().authenticated() |
| ... | ... | @@ -156,8 +158,14 @@ public class YudaoWebSecurityConfigurerAdapter extends WebSecurityConfigurerAdap |
| 156 | 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 | 2 | |
| 3 | 3 | import cn.hutool.core.util.StrUtil; |
| 4 | 4 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 5 | +import cn.iocoder.yudao.framework.common.util.servlet.ServletUtils; | |
| 5 | 6 | import cn.iocoder.yudao.framework.security.config.SecurityProperties; |
| 6 | 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 | 9 | import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils; |
| 9 | 10 | import cn.iocoder.yudao.framework.web.core.handler.GlobalExceptionHandler; |
| 10 | -import cn.iocoder.yudao.framework.common.util.servlet.ServletUtils; | |
| 11 | 11 | import lombok.AllArgsConstructor; |
| 12 | -import org.springframework.stereotype.Component; | |
| 13 | 12 | import org.springframework.web.filter.OncePerRequestFilter; |
| 14 | 13 | |
| 15 | -import javax.annotation.Resource; | |
| 16 | 14 | import javax.servlet.FilterChain; |
| 17 | 15 | import javax.servlet.ServletException; |
| 18 | 16 | import javax.servlet.http.HttpServletRequest; |
| ... | ... | @@ -30,7 +28,7 @@ public class JWTAuthenticationTokenFilter extends OncePerRequestFilter { |
| 30 | 28 | |
| 31 | 29 | private final SecurityProperties securityProperties; |
| 32 | 30 | |
| 33 | - private final SecurityAuthFrameworkService authService; | |
| 31 | + private final SecurityAuthService authService; | |
| 34 | 32 | |
| 35 | 33 | private final GlobalExceptionHandler globalExceptionHandler; |
| 36 | 34 | |
| ... | ... | @@ -42,10 +40,10 @@ public class JWTAuthenticationTokenFilter extends OncePerRequestFilter { |
| 42 | 40 | if (StrUtil.isNotEmpty(token)) { |
| 43 | 41 | try { |
| 44 | 42 | // 验证 token 有效性 |
| 45 | - LoginUser loginUser = authService.verifyTokenAndRefresh(token); | |
| 43 | + LoginUser loginUser = authService.verifyTokenAndRefresh(request, token); | |
| 46 | 44 | // 模拟 Login 功能,方便日常开发调试 |
| 47 | 45 | if (loginUser == null) { |
| 48 | - loginUser = this.mockLoginUser(token); | |
| 46 | + loginUser = this.mockLoginUser(request, token); | |
| 49 | 47 | } |
| 50 | 48 | // 设置当前用户 |
| 51 | 49 | if (loginUser != null) { |
| ... | ... | @@ -67,10 +65,11 @@ public class JWTAuthenticationTokenFilter extends OncePerRequestFilter { |
| 67 | 65 | * |
| 68 | 66 | * 注意,在线上环境下,一定要关闭该功能!!! |
| 69 | 67 | * |
| 68 | + * @param request 请求 | |
| 70 | 69 | * @param token 模拟的 token,格式为 {@link SecurityProperties#getTokenSecret()} + 用户编号 |
| 71 | 70 | * @return 模拟的 LoginUser |
| 72 | 71 | */ |
| 73 | - private LoginUser mockLoginUser(String token) { | |
| 72 | + private LoginUser mockLoginUser(HttpServletRequest request, String token) { | |
| 74 | 73 | if (!securityProperties.getMockEnable()) { |
| 75 | 74 | return null; |
| 76 | 75 | } |
| ... | ... | @@ -79,7 +78,7 @@ public class JWTAuthenticationTokenFilter extends OncePerRequestFilter { |
| 79 | 78 | return null; |
| 80 | 79 | } |
| 81 | 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 | 2 | |
| 3 | 3 | import cn.hutool.core.util.StrUtil; |
| 4 | 4 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 5 | +import cn.iocoder.yudao.framework.common.util.servlet.ServletUtils; | |
| 5 | 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 | 8 | import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils; |
| 8 | -import cn.iocoder.yudao.framework.common.util.servlet.ServletUtils; | |
| 9 | 9 | import lombok.AllArgsConstructor; |
| 10 | 10 | import org.springframework.security.core.Authentication; |
| 11 | 11 | import org.springframework.security.web.authentication.logout.LogoutSuccessHandler; |
| 12 | -import org.springframework.stereotype.Component; | |
| 13 | 12 | |
| 14 | -import javax.annotation.Resource; | |
| 15 | 13 | import javax.servlet.http.HttpServletRequest; |
| 16 | 14 | import javax.servlet.http.HttpServletResponse; |
| 17 | 15 | |
| ... | ... | @@ -26,14 +24,14 @@ public class LogoutSuccessHandlerImpl implements LogoutSuccessHandler { |
| 26 | 24 | |
| 27 | 25 | private final SecurityProperties securityProperties; |
| 28 | 26 | |
| 29 | - private final SecurityAuthFrameworkService securityFrameworkService; | |
| 27 | + private final SecurityAuthService authService; | |
| 30 | 28 | |
| 31 | 29 | @Override |
| 32 | 30 | public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) { |
| 33 | 31 | // 执行退出 |
| 34 | 32 | String token = SecurityFrameworkUtils.obtainAuthorization(request, securityProperties.getTokenHeader()); |
| 35 | 33 | if (StrUtil.isNotBlank(token)) { |
| 36 | - securityFrameworkService.logout(token); | |
| 34 | + authService.logout(request, token); | |
| 37 | 35 | } |
| 38 | 36 | // 返回成功 |
| 39 | 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 | 1 | package cn.iocoder.yudao.framework.security.core.service; |
| 2 | 2 | |
| 3 | +import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; | |
| 3 | 4 | import cn.iocoder.yudao.framework.security.core.LoginUser; |
| 4 | 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 | 10 | * @author 芋道源码 |
| 10 | 11 | */ |
| ... | ... | @@ -34,4 +35,11 @@ public interface SecurityAuthFrameworkService extends UserDetailsService { |
| 34 | 35 | */ |
| 35 | 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 | 2 | |
| 3 | 3 | import cn.hutool.core.exceptions.ExceptionUtil; |
| 4 | 4 | import cn.hutool.core.map.MapUtil; |
| 5 | +import cn.hutool.core.util.StrUtil; | |
| 5 | 6 | import cn.hutool.extra.servlet.ServletUtil; |
| 6 | 7 | import cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants; |
| 7 | 8 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| ... | ... | @@ -25,6 +26,8 @@ import java.io.IOException; |
| 25 | 26 | import java.util.Date; |
| 26 | 27 | import java.util.Map; |
| 27 | 28 | |
| 29 | +import static cn.iocoder.yudao.framework.common.util.json.JsonUtils.*; | |
| 30 | + | |
| 28 | 31 | /** |
| 29 | 32 | * API 访问日志 Filter |
| 30 | 33 | * |
| ... | ... | @@ -42,7 +45,8 @@ public class ApiAccessLogFilter extends OncePerRequestFilter { |
| 42 | 45 | @Override |
| 43 | 46 | protected boolean shouldNotFilter(HttpServletRequest request) { |
| 44 | 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 | 52 | @Override |
| ... | ... | @@ -73,7 +77,7 @@ public class ApiAccessLogFilter extends OncePerRequestFilter { |
| 73 | 77 | this.buildApiAccessLogDTO(accessLog, request, beginTime, queryString, requestBody, ex); |
| 74 | 78 | apiAccessLogFrameworkService.createApiAccessLogAsync(accessLog); |
| 75 | 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 | 103 | accessLog.setApplicationName(applicationName); |
| 100 | 104 | accessLog.setRequestUrl(request.getRequestURI()); |
| 101 | 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 | 107 | accessLog.setRequestMethod(request.getMethod()); |
| 104 | 108 | accessLog.setUserAgent(ServletUtils.getUserAgent(request)); |
| 105 | 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 | 5 | import org.springframework.validation.annotation.Validated; |
| 6 | 6 | import org.springframework.web.servlet.config.annotation.PathMatchConfigurer; |
| 7 | 7 | |
| 8 | +import javax.validation.Valid; | |
| 9 | +import javax.validation.constraints.NotEmpty; | |
| 8 | 10 | import javax.validation.constraints.NotNull; |
| 9 | 11 | |
| 10 | 12 | @ConfigurationProperties(prefix = "yudao.web") |
| ... | ... | @@ -12,26 +14,37 @@ import javax.validation.constraints.NotNull; |
| 12 | 14 | @Data |
| 13 | 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 | 38 | |
| 39 | 39 | @Override |
| 40 | 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 | 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 | 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 | 6 | * 会员用户的 API 接口 |
| 7 | 7 | * |
| 8 | 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 | 15 | * @param id 用户编号 |
| 16 | 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
yudao-module-member/yudao-module-member-impl/pom.xml
| ... | ... | @@ -18,16 +18,18 @@ |
| 18 | 18 | </description> |
| 19 | 19 | |
| 20 | 20 | <dependencies> |
| 21 | - <!-- 业务组件 --> | |
| 22 | 21 | <dependency> |
| 23 | 22 | <groupId>cn.iocoder.boot</groupId> |
| 24 | - <artifactId>yudao-core-service</artifactId> | |
| 23 | + <artifactId>yudao-module-member-api</artifactId> | |
| 24 | + <version>${revision}</version> | |
| 25 | 25 | </dependency> |
| 26 | 26 | |
| 27 | + <!-- 业务组件 --> | |
| 27 | 28 | <dependency> |
| 28 | 29 | <groupId>cn.iocoder.boot</groupId> |
| 29 | - <artifactId>yudao-spring-boot-starter-biz-dict</artifactId> | |
| 30 | + <artifactId>yudao-core-service</artifactId> | |
| 30 | 31 | </dependency> |
| 32 | + | |
| 31 | 33 | <dependency> |
| 32 | 34 | <groupId>cn.iocoder.boot</groupId> |
| 33 | 35 | <artifactId>yudao-spring-boot-starter-biz-sms</artifactId> |
| ... | ... | @@ -40,11 +42,6 @@ |
| 40 | 42 | <!-- Web 相关 --> |
| 41 | 43 | <dependency> |
| 42 | 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 | 45 | <artifactId>yudao-spring-boot-starter-security</artifactId> |
| 49 | 46 | </dependency> |
| 50 | 47 | |
| ... | ... | @@ -59,32 +56,12 @@ |
| 59 | 56 | <artifactId>yudao-spring-boot-starter-redis</artifactId> |
| 60 | 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 | 60 | <dependency> |
| 72 | 61 | <groupId>cn.iocoder.boot</groupId> |
| 73 | 62 | <artifactId>yudao-spring-boot-starter-mq</artifactId> |
| 74 | 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 | 65 | <!-- Test 测试相关 --> |
| 89 | 66 | <dependency> |
| 90 | 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 | 5 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 6 | 6 | import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated; |
| 7 | 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 | 10 | import io.swagger.annotations.Api; |
| 11 | 11 | import io.swagger.annotations.ApiImplicitParam; |
| 12 | 12 | import io.swagger.annotations.ApiImplicitParams; |
| ... | ... | @@ -31,7 +31,8 @@ import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUti |
| 31 | 31 | public class AppAuthController { |
| 32 | 32 | |
| 33 | 33 | @Resource |
| 34 | - private SysAuthService authService; | |
| 34 | + private AuthService authService; | |
| 35 | + | |
| 35 | 36 | @Resource |
| 36 | 37 | private SysSmsCodeService smsCodeService; |
| 37 | 38 | @Resource |
| ... | ... | @@ -55,7 +56,7 @@ public class AppAuthController { |
| 55 | 56 | |
| 56 | 57 | @PostMapping("/send-sms-code") |
| 57 | 58 | @ApiOperation(value = "发送手机验证码") |
| 58 | - public CommonResult<Boolean> sendSmsCode(@RequestBody @Valid SysAuthSendSmsReqVO reqVO) { | |
| 59 | + public CommonResult<Boolean> sendSmsCode(@RequestBody @Valid AppAuthSendSmsReqVO reqVO) { | |
| 59 | 60 | smsCodeService.sendSmsCode(reqVO.getMobile(), reqVO.getScene(), getClientIP()); |
| 60 | 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 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.framework.common.validation.InEnum; |
| 4 | 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 | 6 | import io.swagger.annotations.ApiModel; |
| 7 | 7 | import io.swagger.annotations.ApiModelProperty; |
| 8 | 8 | import lombok.AllArgsConstructor; |
| ... | ... | @@ -15,6 +15,7 @@ import javax.validation.constraints.NotBlank; |
| 15 | 15 | import javax.validation.constraints.NotNull; |
| 16 | 16 | import javax.validation.constraints.Pattern; |
| 17 | 17 | |
| 18 | +// TODO 芋艿:code review 相关逻辑 | |
| 18 | 19 | @ApiModel("APP 端 - 校验验证码 Request VO") |
| 19 | 20 | @Data |
| 20 | 21 | @NoArgsConstructor |
| ... | ... | @@ -37,4 +38,5 @@ public class AppAuthCheckCodeReqVO { |
| 37 | 38 | @NotNull(message = "发送场景不能为空") |
| 38 | 39 | @InEnum(SysSmsSceneEnum.class) |
| 39 | 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 | 13 | import javax.validation.constraints.NotEmpty; |
| 14 | 14 | import javax.validation.constraints.Pattern; |
| 15 | 15 | |
| 16 | +// TODO 芋艿:code review 相关逻辑 | |
| 16 | 17 | @ApiModel("APP 端 - 重置密码 Request VO") |
| 17 | 18 | @Data |
| 18 | 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 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.framework.common.validation.InEnum; |
| 4 | 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 | 6 | import io.swagger.annotations.ApiModel; |
| 7 | 7 | import io.swagger.annotations.ApiModelProperty; |
| 8 | 8 | import lombok.Data; |
| ... | ... | @@ -13,7 +13,7 @@ import javax.validation.constraints.NotNull; |
| 13 | 13 | @ApiModel("APP 端 - 发送手机验证码 Response VO") |
| 14 | 14 | @Data |
| 15 | 15 | @Accessors(chain = true) |
| 16 | -public class AppSendSmsReqVO { | |
| 16 | +public class AppAuthSendSmsReqVO { | |
| 17 | 17 | |
| 18 | 18 | @ApiModelProperty(value = "手机号", example = "15601691234") |
| 19 | 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 | 11 | import javax.validation.constraints.NotBlank; |
| 12 | 12 | import javax.validation.constraints.NotEmpty; |
| 13 | 13 | |
| 14 | +// TODO 芋艿:code review 相关逻辑 | |
| 14 | 15 | @ApiModel("APP 端 - 修改密码 Request VO") |
| 15 | 16 | @Data |
| 16 | 17 | @NoArgsConstructor | ... | ... |
yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/controller/app/user/AppUserController.java
| 1 | 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 | 3 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 6 | 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 | 10 | import io.swagger.annotations.Api; |
| 12 | 11 | import io.swagger.annotations.ApiOperation; |
| 13 | 12 | import lombok.extern.slf4j.Slf4j; |
| ... | ... | @@ -17,13 +16,12 @@ import org.springframework.web.multipart.MultipartFile; |
| 17 | 16 | |
| 18 | 17 | import javax.annotation.Resource; |
| 19 | 18 | import javax.validation.Valid; |
| 20 | - | |
| 21 | 19 | import java.io.IOException; |
| 22 | 20 | |
| 21 | +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.*; | |
| 23 | 22 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| 24 | -import static cn.iocoder.yudao.framework.common.util.servlet.ServletUtils.getClientIP; | |
| 25 | 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 | 26 | @Api(tags = "APP 端 - 用户个人中心") |
| 29 | 27 | @RestController |
| ... | ... | @@ -33,39 +31,40 @@ import static cn.iocoder.yudao.userserver.modules.member.enums.MbrErrorCodeConst |
| 33 | 31 | public class AppUserController { |
| 34 | 32 | |
| 35 | 33 | @Resource |
| 36 | - private MbrUserService userService; | |
| 34 | + private UserService userService; | |
| 37 | 35 | |
| 38 | 36 | @PutMapping("/update-nickname") |
| 39 | 37 | @ApiOperation("修改用户昵称") |
| 40 | 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 | 41 | return success(true); |
| 44 | 42 | } |
| 45 | 43 | |
| 46 | 44 | @PutMapping("/update-avatar") |
| 47 | 45 | @ApiOperation("修改用户头像") |
| 48 | 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 | 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 | 52 | return success(avatar); |
| 55 | 53 | } |
| 56 | 54 | |
| 57 | 55 | @GetMapping("/get") |
| 58 | 56 | @ApiOperation("获得基本信息") |
| 59 | 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 | 63 | @PostMapping("/update-mobile") |
| 65 | 64 | @ApiOperation(value = "修改用户手机") |
| 66 | 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 | 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 | 38 | @Pattern(regexp = "^[0-9]+$", message = "手机验证码必须都是数字") |
| 39 | 39 | private String oldCode; |
| 40 | 40 | |
| 41 | + // TODO @芋艿:oldMobile 应该不用传递 | |
| 42 | + | |
| 41 | 43 | @ApiModelProperty(value = "原手机号",required = true,example = "15823654487") |
| 42 | 44 | @NotBlank(message = "手机号不能为空") |
| 43 | 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 | 1 | package cn.iocoder.yudao.module.member.convert.auth; |
| 2 | 2 | |
| 3 | -import cn.iocoder.yudao.coreservice.modules.member.dal.dataobject.user.MbrUserDO; | |
| 4 | 3 | import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; |
| 5 | 4 | import cn.iocoder.yudao.framework.security.core.LoginUser; |
| 5 | +import cn.iocoder.yudao.module.member.dal.dataobject.user.UserDO; | |
| 6 | 6 | import org.mapstruct.Mapper; |
| 7 | 7 | import org.mapstruct.Mapping; |
| 8 | 8 | import org.mapstruct.factory.Mappers; |
| 9 | 9 | |
| 10 | 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 | 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 | 19 | // 目的,为了设置 UserTypeEnum.MEMBER.getValue() |
| 20 | 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 | 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 | 6 | import org.mapstruct.Mapper; |
| 5 | 7 | import org.mapstruct.factory.Mappers; |
| 6 | 8 | |
| ... | ... | @@ -9,6 +11,7 @@ public interface UserConvert { |
| 9 | 11 | |
| 10 | 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 | 10 | import java.util.Date; |
| 11 | 11 | |
| 12 | 12 | /** |
| 13 | - * 会员中心的用户 DO | |
| 13 | + * 会员用户 DO | |
| 14 | 14 | * |
| 15 | 15 | * uk_mobile 索引:基于 {@link #mobile} 字段 |
| 16 | 16 | * |
| 17 | 17 | * @author 芋道源码 |
| 18 | 18 | */ |
| 19 | -@TableName(value = "member_user", autoResultMap = true) | |
| 19 | +@TableName(value = "mbr_user", autoResultMap = true) | |
| 20 | 20 | @Data |
| 21 | 21 | @EqualsAndHashCode(callSuper = true) |
| 22 | 22 | @Builder |
| 23 | 23 | @NoArgsConstructor |
| 24 | 24 | @AllArgsConstructor |
| 25 | -public class MemberUserDO extends TenantBaseDO { | |
| 25 | +public class UserDO extends TenantBaseDO { | |
| 26 | 26 | |
| 27 | 27 | /** |
| 28 | 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 | 3 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; |
| 4 | 4 | import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX; |
| 5 | 5 | import cn.iocoder.yudao.module.member.dal.dataobject.sms.SysSmsCodeDO; |
| 6 | -import cn.iocoder.yudao.userserver.modules.system.dal.dataobject.sms.SysSmsCodeDO; | |
| 7 | 6 | import org.apache.ibatis.annotations.Mapper; |
| 8 | 7 | |
| 9 | -// TODO @芋艿: | |
| 8 | +// TODO @芋艿:拿到 system 模块下 | |
| 10 | 9 | @Mapper |
| 11 | 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 | 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 | 3 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; |
| 4 | +import cn.iocoder.yudao.module.member.dal.dataobject.user.UserDO; | |
| 5 | 5 | import org.apache.ibatis.annotations.Mapper; |
| 6 | 6 | |
| 7 | 7 | /** |
| 8 | - * MbrUserDO Mapper | |
| 8 | + * 会员 User Mapper | |
| 9 | 9 | * |
| 10 | 10 | * @author 芋道源码 |
| 11 | 11 | */ |
| 12 | 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
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 | 6 | import javax.validation.Valid; |
| 7 | 7 | |
| 8 | 8 | /** |
| 9 | - * 用户前台的认证 Service 接口 | |
| 9 | + * 会员的认证 Service 接口 | |
| 10 | 10 | * |
| 11 | 11 | * 提供用户的账号密码登录、token 的校验等认证相关的功能 |
| 12 | 12 | * |
| 13 | 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 | 22 | * @param userAgent 用户 UA |
| 23 | 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 | 32 | * @param userAgent 用户 UA |
| 33 | 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 | 43 | * @param userAgent 用户 UA |
| 44 | 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 | 53 | * @param userAgent 用户 UA |
| 54 | 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 | 59 | * 社交绑定,使用 code 授权码 |
| ... | ... | @@ -61,18 +61,19 @@ public interface SysAuthService extends SecurityAuthFrameworkService { |
| 61 | 61 | * @param userId 用户编号 |
| 62 | 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 | 68 | * @param userId 用户id |
| 69 | 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 | 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 | 2 | |
| 3 | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | 4 | import cn.hutool.core.lang.Assert; |
| 5 | -import cn.iocoder.yudao.coreservice.modules.member.dal.dataobject.user.MbrUserDO; | |
| 6 | 5 | import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.social.SysSocialUserDO; |
| 7 | 6 | import cn.iocoder.yudao.coreservice.modules.system.enums.logger.SysLoginLogTypeEnum; |
| 8 | 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 | 11 | import cn.iocoder.yudao.coreservice.modules.system.service.social.SysSocialCoreService; |
| 13 | 12 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 14 | 13 | import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; |
| 15 | -import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil; | |
| 16 | 14 | import cn.iocoder.yudao.framework.common.util.monitor.TracerUtils; |
| 17 | 15 | import cn.iocoder.yudao.framework.common.util.servlet.ServletUtils; |
| 18 | 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 | 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 | 24 | import com.google.common.annotations.VisibleForTesting; |
| 27 | 25 | import lombok.extern.slf4j.Slf4j; |
| 28 | 26 | import me.zhyd.oauth.model.AuthUser; |
| 29 | 27 | import org.springframework.context.annotation.Lazy; |
| 30 | -import org.springframework.data.redis.core.StringRedisTemplate; | |
| 31 | 28 | import org.springframework.security.authentication.AuthenticationManager; |
| 32 | 29 | import org.springframework.security.authentication.BadCredentialsException; |
| 33 | 30 | import org.springframework.security.authentication.DisabledException; |
| ... | ... | @@ -46,25 +43,23 @@ import java.util.Objects; |
| 46 | 43 | |
| 47 | 44 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 48 | 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 | 51 | * @author 芋道源码 |
| 55 | 52 | */ |
| 56 | 53 | @Service |
| 57 | 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 | 57 | @Resource |
| 63 | 58 | @Lazy // 延迟加载,因为存在相互依赖的问题 |
| 64 | 59 | private AuthenticationManager authenticationManager; |
| 65 | 60 | |
| 66 | 61 | @Resource |
| 67 | - private MbrUserService userService; | |
| 62 | + private UserService userService; | |
| 68 | 63 | @Resource |
| 69 | 64 | private SysSmsCodeService smsCodeService; |
| 70 | 65 | @Resource |
| ... | ... | @@ -75,27 +70,23 @@ public class SysAuthServiceImpl implements SysAuthService { |
| 75 | 70 | private SysSocialCoreService socialService; |
| 76 | 71 | |
| 77 | 72 | @Resource |
| 78 | - private StringRedisTemplate stringRedisTemplate; | |
| 79 | - @Resource | |
| 80 | 73 | private PasswordEncoder passwordEncoder; |
| 81 | 74 | @Resource |
| 82 | - private MbrUserMapper userMapper; | |
| 83 | - | |
| 84 | - private static final UserTypeEnum userTypeEnum = UserTypeEnum.MEMBER; | |
| 75 | + private UserMapper userMapper; | |
| 85 | 76 | |
| 86 | 77 | @Override |
| 87 | 78 | public UserDetails loadUserByUsername(String mobile) throws UsernameNotFoundException { |
| 88 | 79 | // 获取 username 对应的 SysUserDO |
| 89 | - MbrUserDO user = userService.getUserByMobile(mobile); | |
| 80 | + UserDO user = userService.getUserByMobile(mobile); | |
| 90 | 81 | if (user == null) { |
| 91 | 82 | throw new UsernameNotFoundException(mobile); |
| 92 | 83 | } |
| 93 | 84 | // 创建 LoginUser 对象 |
| 94 | - return SysAuthConvert.INSTANCE.convert(user); | |
| 85 | + return AuthConvert.INSTANCE.convert(user); | |
| 95 | 86 | } |
| 96 | 87 | |
| 97 | 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 | 91 | LoginUser loginUser = this.login0(reqVO.getMobile(), reqVO.getPassword()); |
| 101 | 92 | |
| ... | ... | @@ -105,80 +96,77 @@ public class SysAuthServiceImpl implements SysAuthService { |
| 105 | 96 | |
| 106 | 97 | @Override |
| 107 | 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 | 101 | smsCodeService.useSmsCode(reqVO.getMobile(), SysSmsSceneEnum.LOGIN_BY_SMS.getScene(), |
| 111 | 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 | 106 | Assert.notNull(user, "获取用户失败,结果为空"); |
| 116 | 107 | |
| 117 | 108 | // 执行登陆 |
| 118 | 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 | 112 | // 缓存登录用户到 Redis 中,返回 sessionId 编号 |
| 122 | 113 | return userSessionCoreService.createUserSession(loginUser, userIp, userAgent); |
| 123 | 114 | } |
| 124 | 115 | |
| 125 | 116 | @Override |
| 126 | - public String socialLogin(MbrAuthSocialLoginReqVO reqVO, String userIp, String userAgent) { | |
| 117 | + public String socialLogin(AppAuthSocialLoginReqVO reqVO, String userIp, String userAgent) { | |
| 127 | 118 | // 使用 code 授权码,进行登录 |
| 128 | 119 | AuthUser authUser = socialService.getAuthUser(reqVO.getType(), reqVO.getCode(), reqVO.getState()); |
| 129 | 120 | org.springframework.util.Assert.notNull(authUser, "授权用户不为空"); |
| 130 | 121 | |
| 131 | 122 | // 如果未绑定 SysSocialUserDO 用户,则无法自动登录,进行报错 |
| 132 | 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 | 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 | 131 | if (user == null) { |
| 141 | - throw ServiceExceptionUtil.exception(SysErrorCodeConstants.USER_NOT_EXISTS); | |
| 132 | + throw exception(USER_NOT_EXISTS); | |
| 142 | 133 | } |
| 143 | 134 | this.createLoginLog(user.getMobile(), SysLoginLogTypeEnum.LOGIN_SOCIAL, SysLoginResultEnum.SUCCESS); |
| 144 | 135 | |
| 145 | 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 | 142 | // 缓存登录用户到 Redis 中,返回 sessionId 编号 |
| 152 | 143 | return userSessionCoreService.createUserSession(loginUser, userIp, userAgent); |
| 153 | 144 | } |
| 154 | 145 | |
| 155 | 146 | @Override |
| 156 | - public String socialLogin2(MbrAuthSocialLogin2ReqVO reqVO, String userIp, String userAgent) { | |
| 147 | + public String socialLogin2(AppAuthSocialLogin2ReqVO reqVO, String userIp, String userAgent) { | |
| 157 | 148 | AuthUser authUser = socialService.getAuthUser(reqVO.getType(), reqVO.getCode(), reqVO.getState()); |
| 158 | 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 | 154 | String sessionId = this.smsLogin(loginReqVO, userIp, userAgent); |
| 167 | 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 | 159 | return sessionId; |
| 172 | 160 | } |
| 173 | 161 | |
| 174 | 162 | @Override |
| 175 | - public void socialBind(Long userId, MbrAuthSocialBindReqVO reqVO) { | |
| 163 | + public void socialBind(Long userId, AppAuthSocialBindReqVO reqVO) { | |
| 176 | 164 | // 使用 code 授权码,进行登录 |
| 177 | 165 | AuthUser authUser = socialService.getAuthUser(reqVO.getType(), reqVO.getCode(), reqVO.getState()); |
| 178 | 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 | 172 | private LoginUser login0(String username, String password) { |
| ... | ... | @@ -191,14 +179,14 @@ public class SysAuthServiceImpl implements SysAuthService { |
| 191 | 179 | authentication = authenticationManager.authenticate(new UsernamePasswordAuthenticationToken(username, password)); |
| 192 | 180 | } catch (BadCredentialsException badCredentialsException) { |
| 193 | 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 | 183 | } catch (DisabledException disabledException) { |
| 196 | 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 | 186 | } catch (AuthenticationException authenticationException) { |
| 199 | 187 | log.error("[login0][username({}) 发生未知异常]", username, authenticationException); |
| 200 | 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 | 192 | Assert.notNull(authentication.getPrincipal(), "Principal 不会为空"); |
| ... | ... | @@ -208,7 +196,7 @@ public class SysAuthServiceImpl implements SysAuthService { |
| 208 | 196 | |
| 209 | 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 | 201 | SysLoginLogCreateReqDTO reqDTO = new SysLoginLogCreateReqDTO(); |
| 214 | 202 | reqDTO.setLogType(logTypeEnum.getType()); |
| ... | ... | @@ -246,10 +234,11 @@ public class SysAuthServiceImpl implements SysAuthService { |
| 246 | 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 | 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 | 244 | // 刷新 LoginUser 缓存 |
| ... | ... | @@ -258,8 +247,8 @@ public class SysAuthServiceImpl implements SysAuthService { |
| 258 | 247 | |
| 259 | 248 | @Override |
| 260 | 249 | public LoginUser mockLogin(Long userId) { |
| 261 | - // 获取用户编号对应的 MbrUserDO | |
| 262 | - MbrUserDO user = userService.getUser(userId); | |
| 250 | + // 获取用户编号对应的 UserDO | |
| 251 | + UserDO user = userService.getUser(userId); | |
| 263 | 252 | if (user == null) { |
| 264 | 253 | throw new UsernameNotFoundException(String.valueOf(userId)); |
| 265 | 254 | } |
| ... | ... | @@ -268,7 +257,7 @@ public class SysAuthServiceImpl implements SysAuthService { |
| 268 | 257 | this.createLoginLog(user.getMobile(), SysLoginLogTypeEnum.LOGIN_MOCK, SysLoginResultEnum.SUCCESS); |
| 269 | 258 | |
| 270 | 259 | // 创建 LoginUser 对象 |
| 271 | - return SysAuthConvert.INSTANCE.convert(user); | |
| 260 | + return AuthConvert.INSTANCE.convert(user); | |
| 272 | 261 | } |
| 273 | 262 | |
| 274 | 263 | @Override |
| ... | ... | @@ -285,27 +274,32 @@ public class SysAuthServiceImpl implements SysAuthService { |
| 285 | 274 | } |
| 286 | 275 | |
| 287 | 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 | 289 | userMapper.updateById(mbrUserDO); |
| 297 | 290 | } |
| 298 | 291 | |
| 299 | 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 | 303 | mbrUserDO.setId(userDO.getId()); |
| 310 | 304 | mbrUserDO.setPassword(passwordEncoder.encode(reqVO.getPassword())); |
| 311 | 305 | userMapper.updateById(mbrUserDO); |
| ... | ... | @@ -316,36 +310,35 @@ public class SysAuthServiceImpl implements SysAuthService { |
| 316 | 310 | * |
| 317 | 311 | * @param id 用户 id |
| 318 | 312 | * @param oldPassword 旧密码 |
| 319 | - * @return MbrUserDO 用户实体 | |
| 313 | + * @return MemberUserDO 用户实体 | |
| 320 | 314 | */ |
| 321 | 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 | 318 | if (user == null) { |
| 325 | - throw ServiceExceptionUtil.exception(SysErrorCodeConstants.USER_NOT_EXISTS); | |
| 319 | + throw exception(USER_NOT_EXISTS); | |
| 326 | 320 | } |
| 327 | 321 | // 参数:未加密密码,编码后的密码 |
| 328 | 322 | if (!passwordEncoder.matches(oldPassword,user.getPassword())) { |
| 329 | - throw ServiceExceptionUtil.exception(SysErrorCodeConstants.USER_PASSWORD_FAILED); | |
| 323 | + throw exception(USER_PASSWORD_FAILED); | |
| 330 | 324 | } |
| 331 | 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 | 330 | if (user == null) { |
| 337 | - throw ServiceExceptionUtil.exception(SysErrorCodeConstants.USER_NOT_EXISTS); | |
| 331 | + throw exception(USER_NOT_EXISTS); | |
| 338 | 332 | } |
| 339 | 333 | return user; |
| 340 | 334 | } |
| 341 | 335 | |
| 342 | - | |
| 343 | 336 | private void createLogoutLog(Long userId, String username) { |
| 344 | 337 | SysLoginLogCreateReqDTO reqDTO = new SysLoginLogCreateReqDTO(); |
| 345 | 338 | reqDTO.setLogType(SysLoginLogTypeEnum.LOGOUT_SELF.getType()); |
| 346 | 339 | reqDTO.setTraceId(TracerUtils.getTraceId()); |
| 347 | 340 | reqDTO.setUserId(userId); |
| 348 | - reqDTO.setUserType(USER_TYPE_ENUM.getValue()); | |
| 341 | + reqDTO.setUserType(getUserType().getValue()); | |
| 349 | 342 | reqDTO.setUsername(username); |
| 350 | 343 | reqDTO.setUserAgent(ServletUtils.getUserAgent()); |
| 351 | 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 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.framework.common.exception.ServiceException; |
| 4 | 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 | 9 | * 短信验证码 Service 接口 |
| ... | ... | @@ -40,7 +40,6 @@ public interface SysSmsCodeService { |
| 40 | 40 | */ |
| 41 | 41 | void sendSmsCodeLogin(Long userId); |
| 42 | 42 | |
| 43 | - | |
| 44 | 43 | /** |
| 45 | 44 | * 检查验证码是否有效 |
| 46 | 45 | * @param mobile 手机 | ... | ... |
yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/service/sms/SysSmsCodeServiceImpl.java
| 1 | 1 | package cn.iocoder.yudao.module.member.service.sms; |
| 2 | 2 | |
| 3 | 3 | import cn.hutool.core.map.MapUtil; |
| 4 | -import cn.iocoder.yudao.coreservice.modules.member.dal.dataobject.user.MbrUserDO; | |
| 5 | 4 | import cn.iocoder.yudao.coreservice.modules.system.service.sms.SysSmsCoreService; |
| 6 | 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 | 12 | import org.springframework.stereotype.Service; |
| 14 | 13 | import org.springframework.validation.annotation.Validated; |
| 15 | 14 | |
| ... | ... | @@ -17,9 +16,8 @@ import javax.annotation.Resource; |
| 17 | 16 | import java.util.Date; |
| 18 | 17 | |
| 19 | 18 | import static cn.hutool.core.util.RandomUtil.randomInt; |
| 20 | -import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | |
| 21 | 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 | 23 | * 短信验证码 Service 实现类 |
| ... | ... | @@ -37,7 +35,7 @@ public class SysSmsCodeServiceImpl implements SysSmsCodeService { |
| 37 | 35 | private SysSmsCodeMapper smsCodeMapper; |
| 38 | 36 | |
| 39 | 37 | @Resource |
| 40 | - private MbrUserService mbrUserService; | |
| 38 | + private UserService userService; | |
| 41 | 39 | |
| 42 | 40 | @Resource |
| 43 | 41 | private SysSmsCoreService smsCoreService; |
| ... | ... | @@ -62,9 +60,9 @@ public class SysSmsCodeServiceImpl implements SysSmsCodeService { |
| 62 | 60 | |
| 63 | 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 | 74 | SysSmsCodeDO lastSmsCode = smsCodeMapper.selectLastByMobile(mobile, null,null); |
| 77 | 75 | if (lastSmsCode != null) { |
| 78 | 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 | 79 | if (System.currentTimeMillis() - lastSmsCode.getCreateTime().getTime() |
| 82 | 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 | 83 | // TODO 芋艿:提升,每个 IP 每天可发送数量 |
| 86 | 84 | // TODO 芋艿:提升,每个 IP 每小时可发送数量 |
| ... | ... | @@ -97,13 +95,12 @@ public class SysSmsCodeServiceImpl implements SysSmsCodeService { |
| 97 | 95 | |
| 98 | 96 | @Override |
| 99 | 97 | public void useSmsCode(String mobile, Integer scene, String code, String usedIp) { |
| 100 | - | |
| 101 | 98 | // 检测验证码是否有效 |
| 102 | 99 | SysSmsCodeDO lastSmsCode = this.checkCodeIsExpired(mobile, code, scene); |
| 103 | 100 | |
| 104 | 101 | // 判断验证码是否已被使用 |
| 105 | 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 | 110 | |
| 114 | 111 | @Override |
| 115 | 112 | public void sendSmsCodeLogin(Long userId) { |
| 116 | - MbrUserDO user = mbrUserService.getUser(userId); | |
| 113 | + UserDO user = userService.getUser(userId); | |
| 117 | 114 | if (user == null){ |
| 118 | - throw ServiceExceptionUtil.exception(SysErrorCodeConstants.USER_NOT_EXISTS); | |
| 115 | + throw ServiceExceptionUtil.exception(USER_NOT_EXISTS); | |
| 119 | 116 | } |
| 120 | 117 | // 发送验证码 |
| 121 | 118 | this.sendSmsCode(user.getMobile(),SysSmsSceneEnum.CHANGE_MOBILE_BY_SMS.getScene(), getClientIP()); |
| ... | ... | @@ -128,15 +125,13 @@ public class SysSmsCodeServiceImpl implements SysSmsCodeService { |
| 128 | 125 | |
| 129 | 126 | // 若验证码不存在,抛出异常 |
| 130 | 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 | 130 | if (System.currentTimeMillis() - lastSmsCode.getCreateTime().getTime() |
| 134 | 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 | 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 | 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 | 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 | 8 | import java.io.InputStream; |
| 9 | 9 | |
| 10 | 10 | /** |
| 11 | - * 前台用户 Service 接口 | |
| 11 | + * 会员用户 Service 接口 | |
| 12 | 12 | * |
| 13 | 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 | 20 | * @param mobile 手机 |
| 21 | 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 | 30 | * @param registerIp 注册 IP |
| 31 | 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 | 46 | * @param id 用户ID |
| 47 | 47 | * @return 用户对象信息 |
| 48 | 48 | */ |
| 49 | - MbrUserDO getUser(Long id); | |
| 49 | + UserDO getUser(Long id); | |
| 50 | 50 | |
| 51 | 51 | /** |
| 52 | 52 | * 修改用户昵称 |
| 53 | 53 | * @param userId 用户id |
| 54 | 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 | 61 | * @param inputStream 头像文件 |
| 62 | 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 | 68 | * @param userId 用户id |
| 77 | 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 | 3 | import cn.hutool.core.io.IoUtil; |
| 4 | 4 | import cn.hutool.core.util.IdUtil; |
| 5 | 5 | import cn.iocoder.yudao.coreservice.modules.infra.service.file.InfFileCoreService; |
| 6 | -import cn.iocoder.yudao.coreservice.modules.member.dal.dataobject.user.MbrUserDO; | |
| 7 | 6 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 8 | 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 | 15 | import com.google.common.annotations.VisibleForTesting; |
| 18 | 16 | import lombok.extern.slf4j.Slf4j; |
| 19 | 17 | import org.springframework.security.crypto.password.PasswordEncoder; |
| ... | ... | @@ -27,41 +25,38 @@ import java.util.Date; |
| 27 | 25 | |
| 28 | 26 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 29 | 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 | 33 | * @author 芋道源码 |
| 37 | 34 | */ |
| 38 | 35 | @Service |
| 39 | 36 | @Valid |
| 40 | 37 | @Slf4j |
| 41 | -public class MbrUserServiceImpl implements MbrUserService { | |
| 38 | +public class UserServiceImpl implements UserService { | |
| 42 | 39 | |
| 43 | 40 | @Resource |
| 44 | - private MbrUserMapper userMapper; | |
| 41 | + private UserMapper memberUserMapper; | |
| 45 | 42 | |
| 46 | 43 | @Resource |
| 47 | 44 | private InfFileCoreService fileCoreService; |
| 48 | - | |
| 49 | - @Resource | |
| 50 | - private PasswordEncoder passwordEncoder; | |
| 51 | - | |
| 52 | 45 | @Resource |
| 53 | 46 | private SysSmsCodeService smsCodeService; |
| 54 | 47 | |
| 48 | + @Resource | |
| 49 | + private PasswordEncoder passwordEncoder; | |
| 55 | 50 | |
| 56 | 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 | 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 | 60 | if (user != null) { |
| 66 | 61 | return user; |
| 67 | 62 | } |
| ... | ... | @@ -69,94 +64,84 @@ public class MbrUserServiceImpl implements MbrUserService { |
| 69 | 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 | 69 | String password = IdUtil.fastSimpleUUID(); |
| 75 | 70 | // 插入用户 |
| 76 | - MbrUserDO user = new MbrUserDO(); | |
| 71 | + UserDO user = new UserDO(); | |
| 77 | 72 | user.setMobile(mobile); |
| 78 | 73 | user.setStatus(CommonStatusEnum.ENABLE.getStatus()); // 默认开启 |
| 79 | 74 | user.setPassword(passwordEncoder.encode(password)); // 加密密码 |
| 80 | 75 | user.setRegisterIp(registerIp); |
| 81 | - userMapper.insert(user); | |
| 76 | + memberUserMapper.insert(user); | |
| 82 | 77 | return user; |
| 83 | 78 | } |
| 84 | 79 | |
| 85 | 80 | @Override |
| 86 | 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 | 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 | 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 | 95 | if (nickname.equals(user.getNickname())){ |
| 100 | 96 | return; |
| 101 | 97 | } |
| 102 | - MbrUserDO userDO = new MbrUserDO(); | |
| 98 | + UserDO userDO = new UserDO(); | |
| 103 | 99 | userDO.setId(user.getId()); |
| 104 | 100 | userDO.setNickname(nickname); |
| 105 | - userMapper.updateById(userDO); | |
| 101 | + memberUserMapper.updateById(userDO); | |
| 106 | 102 | } |
| 107 | 103 | |
| 108 | 104 | @Override |
| 109 | - public String updateAvatar(Long userId, InputStream avatarFile) { | |
| 105 | + public String updateUserAvatar(Long userId, InputStream avatarFile) { | |
| 110 | 106 | this.checkUserExists(userId); |
| 111 | 107 | // 创建文件 |
| 112 | 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 | 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 | 114 | @Transactional(rollbackFor = Exception.class) |
| 131 | - public void updateMobile(Long userId, MbrUserUpdateMobileReqVO reqVO) { | |
| 115 | + public void updateUserMobile(Long userId, AppUserUpdateMobileReqVO reqVO) { | |
| 132 | 116 | // 检测用户是否存在 |
| 133 | 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 | 123 | if (Boolean.FALSE.equals(sysSmsCodeDO.getUsed())){ |
| 139 | 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 | 135 | @VisibleForTesting |
| 151 | - public MbrUserDO checkUserExists(Long id) { | |
| 136 | + public UserDO checkUserExists(Long id) { | |
| 152 | 137 | if (id == null) { |
| 153 | 138 | return null; |
| 154 | 139 | } |
| 155 | - MbrUserDO user = userMapper.selectById(id); | |
| 140 | + UserDO user = memberUserMapper.selectById(id); | |
| 156 | 141 | if (user == null) { |
| 157 | 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 | 1 | package cn.iocoder.yudao.module.member.service.auth; |
| 2 | 2 | |
| 3 | -import cn.iocoder.yudao.coreservice.modules.member.dal.dataobject.user.MbrUserDO; | |
| 4 | 3 | import cn.iocoder.yudao.coreservice.modules.system.service.auth.SysUserSessionCoreService; |
| 5 | 4 | import cn.iocoder.yudao.coreservice.modules.system.service.logger.SysLoginLogCoreService; |
| 6 | 5 | import cn.iocoder.yudao.coreservice.modules.system.service.social.SysSocialCoreService; |
| 7 | 6 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 8 | 7 | import cn.iocoder.yudao.framework.common.util.collection.ArrayUtils; |
| 9 | 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 | 16 | import org.junit.jupiter.api.Test; |
| 19 | 17 | import org.springframework.boot.test.mock.mockito.MockBean; |
| 20 | 18 | import org.springframework.context.annotation.Import; |
| ... | ... | @@ -34,17 +32,17 @@ import static org.mockito.Mockito.when; |
| 34 | 32 | |
| 35 | 33 | // TODO @芋艿:单测的 review,等逻辑都达成一致后 |
| 36 | 34 | /** |
| 37 | - * {@link SysAuthService} 的单元测试类 | |
| 35 | + * {@link AuthService} 的单元测试类 | |
| 38 | 36 | * |
| 39 | 37 | * @author 宋天 |
| 40 | 38 | */ |
| 41 | -@Import({SysAuthServiceImpl.class, YudaoRedisAutoConfiguration.class}) | |
| 39 | +@Import({AuthServiceImpl.class, YudaoRedisAutoConfiguration.class}) | |
| 42 | 40 | public class SysAuthServiceTest extends BaseDbAndRedisUnitTest { |
| 43 | 41 | |
| 44 | 42 | @MockBean |
| 45 | 43 | private AuthenticationManager authenticationManager; |
| 46 | 44 | @MockBean |
| 47 | - private MbrUserService userService; | |
| 45 | + private UserService userService; | |
| 48 | 46 | @MockBean |
| 49 | 47 | private SysSmsCodeService smsCodeService; |
| 50 | 48 | @MockBean |
| ... | ... | @@ -58,21 +56,21 @@ public class SysAuthServiceTest extends BaseDbAndRedisUnitTest { |
| 58 | 56 | @MockBean |
| 59 | 57 | private PasswordEncoder passwordEncoder; |
| 60 | 58 | @Resource |
| 61 | - private MbrUserMapper mbrUserMapper; | |
| 59 | + private UserMapper mbrUserMapper; | |
| 62 | 60 | @Resource |
| 63 | - private SysAuthServiceImpl authService; | |
| 61 | + private AuthServiceImpl authService; | |
| 64 | 62 | |
| 65 | 63 | @Test |
| 66 | 64 | public void testUpdatePassword_success(){ |
| 67 | 65 | // 准备参数 |
| 68 | - MbrUserDO userDO = randomMbrUserDO(); | |
| 66 | + UserDO userDO = randomUserDO(); | |
| 69 | 67 | mbrUserMapper.insert(userDO); |
| 70 | 68 | |
| 71 | 69 | // 新密码 |
| 72 | 70 | String newPassword = randomString(); |
| 73 | 71 | |
| 74 | 72 | // 请求实体 |
| 75 | - MbrAuthUpdatePasswordReqVO reqVO = MbrAuthUpdatePasswordReqVO.builder() | |
| 73 | + AppAuthUpdatePasswordReqVO reqVO = AppAuthUpdatePasswordReqVO.builder() | |
| 76 | 74 | .oldPassword(userDO.getPassword()) |
| 77 | 75 | .password(newPassword) |
| 78 | 76 | .build(); |
| ... | ... | @@ -83,14 +81,14 @@ public class SysAuthServiceTest extends BaseDbAndRedisUnitTest { |
| 83 | 81 | when(passwordEncoder.encode(newPassword)).thenReturn(newPassword); |
| 84 | 82 | |
| 85 | 83 | // 更新用户密码 |
| 86 | - authService.updatePassword(userDO.getId(),reqVO); | |
| 84 | + authService.updatePassword(userDO.getId(), reqVO); | |
| 87 | 85 | assertEquals(mbrUserMapper.selectById(userDO.getId()).getPassword(),newPassword); |
| 88 | 86 | } |
| 89 | 87 | |
| 90 | 88 | @Test |
| 91 | 89 | public void testResetPassword_success(){ |
| 92 | 90 | // 准备参数 |
| 93 | - MbrUserDO userDO = randomMbrUserDO(); | |
| 91 | + UserDO userDO = randomUserDO(); | |
| 94 | 92 | mbrUserMapper.insert(userDO); |
| 95 | 93 | |
| 96 | 94 | // 随机密码 |
| ... | ... | @@ -102,7 +100,7 @@ public class SysAuthServiceTest extends BaseDbAndRedisUnitTest { |
| 102 | 100 | when(passwordEncoder.encode(password)).thenReturn(password); |
| 103 | 101 | |
| 104 | 102 | // 更新用户密码 |
| 105 | - MbrAuthResetPasswordReqVO reqVO = new MbrAuthResetPasswordReqVO(); | |
| 103 | + AppAuthResetPasswordReqVO reqVO = new AppAuthResetPasswordReqVO(); | |
| 106 | 104 | reqVO.setMobile(userDO.getMobile()); |
| 107 | 105 | reqVO.setPassword(password); |
| 108 | 106 | reqVO.setCode(code); |
| ... | ... | @@ -115,12 +113,12 @@ public class SysAuthServiceTest extends BaseDbAndRedisUnitTest { |
| 115 | 113 | // ========== 随机对象 ========== |
| 116 | 114 | |
| 117 | 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 | 118 | o.setStatus(randomEle(CommonStatusEnum.values()).getStatus()); // 保证 status 的范围 |
| 121 | 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 | 2 | |
| 3 | 3 | import cn.hutool.core.util.RandomUtil; |
| 4 | 4 | import cn.iocoder.yudao.coreservice.modules.infra.service.file.InfFileCoreService; |
| 5 | -import cn.iocoder.yudao.coreservice.modules.member.dal.dataobject.user.MbrUserDO; | |
| 6 | 5 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 7 | 6 | import cn.iocoder.yudao.framework.common.util.collection.ArrayUtils; |
| 8 | 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 | 16 | import org.junit.jupiter.api.Test; |
| 18 | 17 | import org.springframework.boot.test.mock.mockito.MockBean; |
| 19 | 18 | import org.springframework.context.annotation.Import; |
| ... | ... | @@ -27,30 +26,29 @@ import java.util.function.Consumer; |
| 27 | 26 | import static cn.hutool.core.util.RandomUtil.*; |
| 28 | 27 | import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo; |
| 29 | 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 | 29 | import static org.junit.jupiter.api.Assertions.assertEquals; |
| 32 | 30 | import static org.mockito.Mockito.*; |
| 33 | 31 | |
| 34 | 32 | // TODO @芋艿:单测的 review,等逻辑都达成一致后 |
| 35 | 33 | /** |
| 36 | - * {@link MbrUserServiceImpl} 的单元测试类 | |
| 34 | + * {@link UserServiceImpl} 的单元测试类 | |
| 37 | 35 | * |
| 38 | 36 | * @author 宋天 |
| 39 | 37 | */ |
| 40 | -@Import({MbrUserServiceImpl.class, YudaoRedisAutoConfiguration.class}) | |
| 38 | +@Import({UserServiceImpl.class, YudaoRedisAutoConfiguration.class}) | |
| 41 | 39 | public class MbrUserServiceImplTest extends BaseDbAndRedisUnitTest { |
| 42 | 40 | |
| 43 | 41 | @Resource |
| 44 | - private MbrUserServiceImpl mbrUserService; | |
| 42 | + private UserServiceImpl mbrUserService; | |
| 45 | 43 | |
| 46 | 44 | @Resource |
| 47 | 45 | private StringRedisTemplate stringRedisTemplate; |
| 48 | 46 | |
| 49 | 47 | @Resource |
| 50 | - private MbrUserMapper userMapper; | |
| 48 | + private UserMapper userMapper; | |
| 51 | 49 | |
| 52 | 50 | @MockBean |
| 53 | - private SysAuthServiceImpl authService; | |
| 51 | + private AuthServiceImpl authService; | |
| 54 | 52 | |
| 55 | 53 | @MockBean |
| 56 | 54 | private InfFileCoreService fileCoreService; |
| ... | ... | @@ -64,14 +62,14 @@ public class MbrUserServiceImplTest extends BaseDbAndRedisUnitTest { |
| 64 | 62 | @Test |
| 65 | 63 | public void testUpdateNickName_success(){ |
| 66 | 64 | // mock 数据 |
| 67 | - MbrUserDO userDO = randomMbrUserDO(); | |
| 65 | + UserDO userDO = randomUserDO(); | |
| 68 | 66 | userMapper.insert(userDO); |
| 69 | 67 | |
| 70 | 68 | // 随机昵称 |
| 71 | 69 | String newNickName = randomString(); |
| 72 | 70 | |
| 73 | 71 | // 调用接口修改昵称 |
| 74 | - mbrUserService.updateNickname(userDO.getId(),newNickName); | |
| 72 | + mbrUserService.updateUserNickname(userDO.getId(),newNickName); | |
| 75 | 73 | // 查询新修改后的昵称 |
| 76 | 74 | String nickname = mbrUserService.getUser(userDO.getId()).getNickname(); |
| 77 | 75 | // 断言 |
| ... | ... | @@ -79,20 +77,9 @@ public class MbrUserServiceImplTest extends BaseDbAndRedisUnitTest { |
| 79 | 77 | } |
| 80 | 78 | |
| 81 | 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 | 80 | public void testUpdateAvatar_success(){ |
| 94 | 81 | // mock 数据 |
| 95 | - MbrUserDO dbUser = randomMbrUserDO(); | |
| 82 | + UserDO dbUser = randomUserDO(); | |
| 96 | 83 | userMapper.insert(dbUser); |
| 97 | 84 | |
| 98 | 85 | // 准备参数 |
| ... | ... | @@ -103,7 +90,7 @@ public class MbrUserServiceImplTest extends BaseDbAndRedisUnitTest { |
| 103 | 90 | String avatar = randomString(); |
| 104 | 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 | 95 | assertEquals(avatar, str); |
| 109 | 96 | } |
| ... | ... | @@ -112,11 +99,10 @@ public class MbrUserServiceImplTest extends BaseDbAndRedisUnitTest { |
| 112 | 99 | public void updateMobile_success(){ |
| 113 | 100 | // mock数据 |
| 114 | 101 | String oldMobile = randomNumbers(11); |
| 115 | - MbrUserDO userDO = randomMbrUserDO(); | |
| 102 | + UserDO userDO = randomUserDO(); | |
| 116 | 103 | userDO.setMobile(oldMobile); |
| 117 | 104 | userMapper.insert(userDO); |
| 118 | 105 | |
| 119 | - | |
| 120 | 106 | // 旧手机和旧验证码 |
| 121 | 107 | SysSmsCodeDO codeDO = new SysSmsCodeDO(); |
| 122 | 108 | String oldCode = RandomUtil.randomString(4); |
| ... | ... | @@ -129,12 +115,12 @@ public class MbrUserServiceImplTest extends BaseDbAndRedisUnitTest { |
| 129 | 115 | // 更新手机号 |
| 130 | 116 | String newMobile = randomNumbers(11); |
| 131 | 117 | String newCode = randomNumbers(4); |
| 132 | - MbrUserUpdateMobileReqVO reqVO = new MbrUserUpdateMobileReqVO(); | |
| 118 | + AppUserUpdateMobileReqVO reqVO = new AppUserUpdateMobileReqVO(); | |
| 133 | 119 | reqVO.setMobile(newMobile); |
| 134 | 120 | reqVO.setCode(newCode); |
| 135 | 121 | reqVO.setOldMobile(oldMobile); |
| 136 | 122 | reqVO.setOldCode(oldCode); |
| 137 | - mbrUserService.updateMobile(userDO.getId(),reqVO); | |
| 123 | + mbrUserService.updateUserMobile(userDO.getId(),reqVO); | |
| 138 | 124 | |
| 139 | 125 | assertEquals(mbrUserService.getUser(userDO.getId()).getMobile(),newMobile); |
| 140 | 126 | } |
| ... | ... | @@ -142,11 +128,11 @@ public class MbrUserServiceImplTest extends BaseDbAndRedisUnitTest { |
| 142 | 128 | // ========== 随机对象 ========== |
| 143 | 129 | |
| 144 | 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 | 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 | 3 | import cn.iocoder.yudao.framework.datasource.config.YudaoDataSourceAutoConfiguration; |
| 4 | 4 | import cn.iocoder.yudao.framework.mybatis.config.YudaoMybatisAutoConfiguration; |
| 5 | 5 | import cn.iocoder.yudao.framework.redis.config.YudaoRedisAutoConfiguration; |
| 6 | -import cn.iocoder.yudao.userserver.config.RedisTestConfiguration; | |
| 7 | 6 | import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure; |
| 8 | 7 | import com.baomidou.mybatisplus.autoconfigure.MybatisPlusAutoConfiguration; |
| 9 | 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 | 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 | 124 | file: |
| 125 | 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 | 66 | constants-class-list: |
| 67 | 67 | - cn.iocoder.yudao.userserver.modules.member.enums.MbrErrorCodeConstants |
| 68 | 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 | 71 | debug: false | ... | ... |