Commit a55c0cfca59ad723e5b5661e59cad707ff4d6a2b
Merge branch 'master' of https://gitee.com/zhijiantianya/ruoyi-vue-pro
Conflicts: yudao-core-service/pom.xml yudao-dependencies/pom.xml yudao-framework/pom.xml
Showing
32 changed files
with
425 additions
and
149 deletions
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/auth/SysAuthController.java
| ... | ... | @@ -9,7 +9,7 @@ import cn.iocoder.yudao.adminserver.modules.system.service.auth.SysAuthService; |
| 9 | 9 | import cn.iocoder.yudao.adminserver.modules.system.service.permission.SysPermissionService; |
| 10 | 10 | import cn.iocoder.yudao.adminserver.modules.system.service.permission.SysRoleService; |
| 11 | 11 | import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.user.SysUserDO; |
| 12 | -import cn.iocoder.yudao.coreservice.modules.system.service.social.SysSocialService; | |
| 12 | +import cn.iocoder.yudao.coreservice.modules.system.service.social.SysSocialCoreService; | |
| 13 | 13 | import cn.iocoder.yudao.coreservice.modules.system.service.user.SysUserCoreService; |
| 14 | 14 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 15 | 15 | import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; |
| ... | ... | @@ -50,7 +50,7 @@ public class SysAuthController { |
| 50 | 50 | @Resource |
| 51 | 51 | private SysPermissionService permissionService; |
| 52 | 52 | @Resource |
| 53 | - private SysSocialService socialService; | |
| 53 | + private SysSocialCoreService socialCoreService; | |
| 54 | 54 | |
| 55 | 55 | @PostMapping("/login") |
| 56 | 56 | @ApiOperation("使用账号密码登录") |
| ... | ... | @@ -102,7 +102,7 @@ public class SysAuthController { |
| 102 | 102 | }) |
| 103 | 103 | public CommonResult<String> socialAuthRedirect(@RequestParam("type") Integer type, |
| 104 | 104 | @RequestParam("redirectUri") String redirectUri) { |
| 105 | - return CommonResult.success(socialService.getAuthorizeUrl(type, redirectUri)); | |
| 105 | + return CommonResult.success(socialCoreService.getAuthorizeUrl(type, redirectUri)); | |
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | @PostMapping("/social-login") |
| ... | ... | @@ -133,7 +133,7 @@ public class SysAuthController { |
| 133 | 133 | @DeleteMapping("/social-unbind") |
| 134 | 134 | @ApiOperation("取消社交绑定") |
| 135 | 135 | public CommonResult<Boolean> socialUnbind(@RequestBody SysAuthSocialUnbindReqVO reqVO) { |
| 136 | - socialService.unbindSocialUser(getLoginUserId(), reqVO.getType(), reqVO.getUnionId(), UserTypeEnum.ADMIN); | |
| 136 | + socialCoreService.unbindSocialUser(getLoginUserId(), reqVO.getType(), reqVO.getUnionId(), UserTypeEnum.ADMIN); | |
| 137 | 137 | return CommonResult.success(true); |
| 138 | 138 | } |
| 139 | 139 | ... | ... |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/user/SysUserProfileController.java
| ... | ... | @@ -15,7 +15,7 @@ import cn.iocoder.yudao.adminserver.modules.system.service.permission.SysRoleSer |
| 15 | 15 | import cn.iocoder.yudao.adminserver.modules.system.service.user.SysUserService; |
| 16 | 16 | import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.social.SysSocialUserDO; |
| 17 | 17 | import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.user.SysUserDO; |
| 18 | -import cn.iocoder.yudao.coreservice.modules.system.service.social.SysSocialService; | |
| 18 | +import cn.iocoder.yudao.coreservice.modules.system.service.social.SysSocialCoreService; | |
| 19 | 19 | import cn.iocoder.yudao.coreservice.modules.system.service.user.SysUserCoreService; |
| 20 | 20 | import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; |
| 21 | 21 | import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil; |
| ... | ... | @@ -56,7 +56,7 @@ public class SysUserProfileController { |
| 56 | 56 | @Resource |
| 57 | 57 | private SysRoleService roleService; |
| 58 | 58 | @Resource |
| 59 | - private SysSocialService socialService; | |
| 59 | + private SysSocialCoreService socialService; | |
| 60 | 60 | |
| 61 | 61 | @GetMapping("/get") |
| 62 | 62 | @ApiOperation("获得登录用户信息") | ... | ... |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/auth/impl/SysAuthServiceImpl.java
| ... | ... | @@ -19,7 +19,7 @@ import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.user.SysUserDO |
| 19 | 19 | import cn.iocoder.yudao.coreservice.modules.system.service.auth.SysUserSessionCoreService; |
| 20 | 20 | import cn.iocoder.yudao.coreservice.modules.system.service.logger.SysLoginLogCoreService; |
| 21 | 21 | import cn.iocoder.yudao.coreservice.modules.system.service.logger.dto.SysLoginLogCreateReqDTO; |
| 22 | -import cn.iocoder.yudao.coreservice.modules.system.service.social.SysSocialService; | |
| 22 | +import cn.iocoder.yudao.coreservice.modules.system.service.social.SysSocialCoreService; | |
| 23 | 23 | import cn.iocoder.yudao.coreservice.modules.system.service.user.SysUserCoreService; |
| 24 | 24 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 25 | 25 | import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; |
| ... | ... | @@ -60,6 +60,8 @@ 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 | + | |
| 63 | 65 | @Resource |
| 64 | 66 | @Lazy // 延迟加载,因为存在相互依赖的问题 |
| 65 | 67 | private AuthenticationManager authenticationManager; |
| ... | ... | @@ -79,10 +81,8 @@ public class SysAuthServiceImpl implements SysAuthService { |
| 79 | 81 | @Resource |
| 80 | 82 | private SysPostService postService; |
| 81 | 83 | @Resource |
| 82 | - private SysSocialService socialService; | |
| 84 | + private SysSocialCoreService socialService; | |
| 83 | 85 | |
| 84 | - // TODO @timfruit:静态枚举类,需要都大写,例如说 USER_TYPE_ENUM;静态变量,放在普通变量前面;这个实践不错哈。 | |
| 85 | - private static final UserTypeEnum userTypeEnum = UserTypeEnum.ADMIN; | |
| 86 | 86 | |
| 87 | 87 | @Override |
| 88 | 88 | public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { |
| ... | ... | @@ -216,7 +216,7 @@ public class SysAuthServiceImpl implements SysAuthService { |
| 216 | 216 | |
| 217 | 217 | // 如果未绑定 SysSocialUserDO 用户,则无法自动登录,进行报错 |
| 218 | 218 | String unionId = socialService.getAuthUserUnionId(authUser); |
| 219 | - List<SysSocialUserDO> socialUsers = socialService.getAllSocialUserList(reqVO.getType(), unionId, userTypeEnum); | |
| 219 | + List<SysSocialUserDO> socialUsers = socialService.getAllSocialUserList(reqVO.getType(), unionId, USER_TYPE_ENUM); | |
| 220 | 220 | if (CollUtil.isEmpty(socialUsers)) { |
| 221 | 221 | throw exception(AUTH_THIRD_LOGIN_NOT_BIND); |
| 222 | 222 | } |
| ... | ... | @@ -232,7 +232,7 @@ public class SysAuthServiceImpl implements SysAuthService { |
| 232 | 232 | LoginUser loginUser = this.buildLoginUser(user); |
| 233 | 233 | |
| 234 | 234 | // 绑定社交用户(更新) |
| 235 | - socialService.bindSocialUser(loginUser.getId(), reqVO.getType(), authUser, userTypeEnum); | |
| 235 | + socialService.bindSocialUser(loginUser.getId(), reqVO.getType(), authUser, USER_TYPE_ENUM); | |
| 236 | 236 | |
| 237 | 237 | // 缓存登录用户到 Redis 中,返回 sessionId 编号 |
| 238 | 238 | return userSessionCoreService.createUserSession(loginUser, userIp, userAgent); |
| ... | ... | @@ -248,7 +248,7 @@ public class SysAuthServiceImpl implements SysAuthService { |
| 248 | 248 | LoginUser loginUser = this.login0(reqVO.getUsername(), reqVO.getPassword()); |
| 249 | 249 | |
| 250 | 250 | // 绑定社交用户(新增) |
| 251 | - socialService.bindSocialUser(loginUser.getId(), reqVO.getType(), authUser, userTypeEnum); | |
| 251 | + socialService.bindSocialUser(loginUser.getId(), reqVO.getType(), authUser, USER_TYPE_ENUM); | |
| 252 | 252 | |
| 253 | 253 | // 缓存登录用户到 Redis 中,返回 sessionId 编号 |
| 254 | 254 | return userSessionCoreService.createUserSession(loginUser, userIp, userAgent); |
| ... | ... | @@ -261,7 +261,7 @@ public class SysAuthServiceImpl implements SysAuthService { |
| 261 | 261 | Assert.notNull(authUser, "授权用户不为空"); |
| 262 | 262 | |
| 263 | 263 | // 绑定社交用户(新增) |
| 264 | - socialService.bindSocialUser(userId, reqVO.getType(), authUser, userTypeEnum); | |
| 264 | + socialService.bindSocialUser(userId, reqVO.getType(), authUser, USER_TYPE_ENUM); | |
| 265 | 265 | } |
| 266 | 266 | |
| 267 | 267 | @Override |
| ... | ... | @@ -282,7 +282,7 @@ public class SysAuthServiceImpl implements SysAuthService { |
| 282 | 282 | reqDTO.setLogType(SysLoginLogTypeEnum.LOGOUT_SELF.getType()); |
| 283 | 283 | reqDTO.setTraceId(TracerUtils.getTraceId()); |
| 284 | 284 | reqDTO.setUserId(userId); |
| 285 | - reqDTO.setUserType(userTypeEnum.getValue()); | |
| 285 | + reqDTO.setUserType(USER_TYPE_ENUM.getValue()); | |
| 286 | 286 | reqDTO.setUsername(username); |
| 287 | 287 | reqDTO.setUserAgent(ServletUtils.getUserAgent()); |
| 288 | 288 | reqDTO.setUserIp(ServletUtils.getClientIP()); | ... | ... |
yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/modules/system/service/auth/SysAuthServiceImplTest.java
| ... | ... | @@ -12,7 +12,7 @@ import cn.iocoder.yudao.adminserver.modules.system.service.user.SysUserService; |
| 12 | 12 | import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.user.SysUserDO; |
| 13 | 13 | import cn.iocoder.yudao.coreservice.modules.system.service.auth.SysUserSessionCoreService; |
| 14 | 14 | import cn.iocoder.yudao.coreservice.modules.system.service.logger.SysLoginLogCoreService; |
| 15 | -import cn.iocoder.yudao.coreservice.modules.system.service.social.SysSocialService; | |
| 15 | +import cn.iocoder.yudao.coreservice.modules.system.service.social.SysSocialCoreService; | |
| 16 | 16 | import cn.iocoder.yudao.coreservice.modules.system.service.user.SysUserCoreService; |
| 17 | 17 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 18 | 18 | import cn.iocoder.yudao.framework.security.core.LoginUser; |
| ... | ... | @@ -68,7 +68,7 @@ public class SysAuthServiceImplTest extends BaseDbUnitTest { |
| 68 | 68 | @MockBean |
| 69 | 69 | private SysUserSessionCoreService userSessionCoreService; |
| 70 | 70 | @MockBean |
| 71 | - private SysSocialService socialService; | |
| 71 | + private SysSocialCoreService socialService; | |
| 72 | 72 | @MockBean |
| 73 | 73 | private SysPostService postService; |
| 74 | 74 | ... | ... |
yudao-core-service/pom.xml
| ... | ... | @@ -101,12 +101,6 @@ |
| 101 | 101 | <artifactId>guava</artifactId> |
| 102 | 102 | </dependency> |
| 103 | 103 | |
| 104 | - <!-- 三方云服务相关 --> | |
| 105 | - <dependency> | |
| 106 | - <groupId>com.xkcoding.justauth</groupId> | |
| 107 | - <artifactId>justauth-spring-boot-starter</artifactId> | |
| 108 | - </dependency> | |
| 109 | - | |
| 110 | 104 | </dependencies> |
| 111 | 105 | |
| 112 | 106 | </project> | ... | ... |
yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/dal/mysql/social/SysSocialUserMapper.java renamed to yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/dal/mysql/social/SysSocialUserCoreMapper.java
| ... | ... | @@ -8,9 +8,8 @@ import org.apache.ibatis.annotations.Mapper; |
| 8 | 8 | import java.util.Collection; |
| 9 | 9 | import java.util.List; |
| 10 | 10 | |
| 11 | -// TODO @timfruit:SysSocialUserCoreMapper 改名,方便区分 | |
| 12 | 11 | @Mapper |
| 13 | -public interface SysSocialUserMapper extends BaseMapperX<SysSocialUserDO> { | |
| 12 | +public interface SysSocialUserCoreMapper extends BaseMapperX<SysSocialUserDO> { | |
| 14 | 13 | |
| 15 | 14 | default List<SysSocialUserDO> selectListByTypeAndUnionId(Integer userType, Collection<Integer> types, String unionId) { |
| 16 | 15 | return selectList(new QueryWrapper<SysSocialUserDO>().eq("user_type", userType) | ... | ... |
yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/dal/redis/social/SysSocialAuthUserRedisDAO.java
| ... | ... | @@ -10,9 +10,8 @@ import javax.annotation.Resource; |
| 10 | 10 | |
| 11 | 11 | import static cn.iocoder.yudao.coreservice.modules.system.dal.redis.SysRedisKeyCoreConstants.SOCIAL_AUTH_USER; |
| 12 | 12 | |
| 13 | -// TODO @timfruit,这里的 AuthUser 还是保留全路径,主要想体现出来,不是自己定义的 | |
| 14 | 13 | /** |
| 15 | - * 社交 {@link AuthUser} 的 RedisDAO | |
| 14 | + * 社交 {@link me.zhyd.oauth.model.AuthUser} 的 RedisDAO | |
| 16 | 15 | * |
| 17 | 16 | * @author 芋道源码 |
| 18 | 17 | */ | ... | ... |
yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/service/social/SysSocialService.java renamed to yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/service/social/SysSocialCoreService.java
| ... | ... | @@ -15,8 +15,7 @@ import java.util.List; |
| 15 | 15 | * |
| 16 | 16 | * @author 芋道源码 |
| 17 | 17 | */ |
| 18 | -// TODO @timfruit:SysSocialCoreService 改名,方便区分 | |
| 19 | -public interface SysSocialService { | |
| 18 | +public interface SysSocialCoreService { | |
| 20 | 19 | |
| 21 | 20 | /** |
| 22 | 21 | * 获得社交平台的授权 URL |
| ... | ... | @@ -50,6 +49,7 @@ public interface SysSocialService { |
| 50 | 49 | * @param type 社交平台的类型 {@link SysSocialTypeEnum} |
| 51 | 50 | * @param unionId 社交平台的 unionId |
| 52 | 51 | * @return 社交用户列表 |
| 52 | + * @param userTypeEnum 全局用户类型 | |
| 53 | 53 | */ |
| 54 | 54 | List<SysSocialUserDO> getAllSocialUserList(Integer type, String unionId, UserTypeEnum userTypeEnum); |
| 55 | 55 | |
| ... | ... | @@ -58,6 +58,7 @@ public interface SysSocialService { |
| 58 | 58 | * |
| 59 | 59 | * @param userId 用户编号 |
| 60 | 60 | * @return 社交用户列表 |
| 61 | + * @param userTypeEnum 全局用户类型 | |
| 61 | 62 | */ |
| 62 | 63 | List<SysSocialUserDO> getSocialUserList(Long userId, UserTypeEnum userTypeEnum); |
| 63 | 64 | |
| ... | ... | @@ -67,6 +68,7 @@ public interface SysSocialService { |
| 67 | 68 | * @param userId 用户编号 |
| 68 | 69 | * @param type 社交平台的类型 {@link SysSocialTypeEnum} |
| 69 | 70 | * @param authUser 授权用户 |
| 71 | + * @param userTypeEnum 全局用户类型 | |
| 70 | 72 | */ |
| 71 | 73 | void bindSocialUser(Long userId, Integer type, AuthUser authUser, UserTypeEnum userTypeEnum); |
| 72 | 74 | |
| ... | ... | @@ -76,8 +78,8 @@ public interface SysSocialService { |
| 76 | 78 | * @param userId 用户编号 |
| 77 | 79 | * @param type 社交平台的类型 {@link SysSocialTypeEnum} |
| 78 | 80 | * @param unionId 社交平台的 unionId |
| 81 | + * @param userTypeEnum 全局用户类型 | |
| 79 | 82 | */ |
| 80 | - void unbindSocialUser(Long userId, Integer type, String unionId,UserTypeEnum userTypeEnum); | |
| 81 | - // TODO @timfruit:逗号后面要有空格;缺少了 @userTypeEnum 的注释,都补充下哈。 | |
| 83 | + void unbindSocialUser(Long userId, Integer type, String unionId, UserTypeEnum userTypeEnum); | |
| 82 | 84 | |
| 83 | 85 | } | ... | ... |
yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/service/social/impl/SysSocialServiceImpl.java renamed to yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/service/social/impl/SysSocialCoreServiceImpl.java
| ... | ... | @@ -2,10 +2,10 @@ package cn.iocoder.yudao.coreservice.modules.system.service.social.impl; |
| 2 | 2 | |
| 3 | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | 4 | import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.social.SysSocialUserDO; |
| 5 | -import cn.iocoder.yudao.coreservice.modules.system.dal.mysql.social.SysSocialUserMapper; | |
| 5 | +import cn.iocoder.yudao.coreservice.modules.system.dal.mysql.social.SysSocialUserCoreMapper; | |
| 6 | 6 | import cn.iocoder.yudao.coreservice.modules.system.dal.redis.social.SysSocialAuthUserRedisDAO; |
| 7 | 7 | import cn.iocoder.yudao.coreservice.modules.system.enums.social.SysSocialTypeEnum; |
| 8 | -import cn.iocoder.yudao.coreservice.modules.system.service.social.SysSocialService; | |
| 8 | +import cn.iocoder.yudao.coreservice.modules.system.service.social.SysSocialCoreService; | |
| 9 | 9 | import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; |
| 10 | 10 | import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; |
| 11 | 11 | import cn.iocoder.yudao.framework.common.util.http.HttpUtils; |
| ... | ... | @@ -38,7 +38,7 @@ import static cn.iocoder.yudao.framework.common.util.json.JsonUtils.toJsonString |
| 38 | 38 | @Service |
| 39 | 39 | @Validated |
| 40 | 40 | @Slf4j |
| 41 | -public class SysSocialServiceImpl implements SysSocialService { | |
| 41 | +public class SysSocialCoreServiceImpl implements SysSocialCoreService { | |
| 42 | 42 | |
| 43 | 43 | @Resource |
| 44 | 44 | private AuthRequestFactory authRequestFactory; |
| ... | ... | @@ -47,7 +47,7 @@ public class SysSocialServiceImpl implements SysSocialService { |
| 47 | 47 | private SysSocialAuthUserRedisDAO authSocialUserRedisDAO; |
| 48 | 48 | |
| 49 | 49 | @Resource |
| 50 | - private SysSocialUserMapper socialUserMapper; | |
| 50 | + private SysSocialUserCoreMapper socialUserMapper; | |
| 51 | 51 | |
| 52 | 52 | @Override |
| 53 | 53 | public String getAuthorizeUrl(Integer type, String redirectUri) { | ... | ... |
yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/modules/system/service/social/SysSocialServiceTest.java renamed to yudao-core-service/src/test/java/cn/iocoder/yudao/coreservice/modules/system/service/social/SysSocialCoreServiceTest.java
| 1 | -package cn.iocoder.yudao.adminserver.modules.system.service.social; | |
| 1 | +package cn.iocoder.yudao.coreservice.modules.system.service.social; | |
| 2 | 2 | |
| 3 | -import cn.iocoder.yudao.adminserver.BaseDbAndRedisUnitTest; | |
| 3 | +import cn.iocoder.yudao.coreservice.BaseDbAndRedisUnitTest; | |
| 4 | 4 | import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.social.SysSocialUserDO; |
| 5 | -import cn.iocoder.yudao.coreservice.modules.system.dal.mysql.social.SysSocialUserMapper; | |
| 5 | +import cn.iocoder.yudao.coreservice.modules.system.dal.mysql.social.SysSocialUserCoreMapper; | |
| 6 | 6 | import cn.iocoder.yudao.coreservice.modules.system.dal.redis.social.SysSocialAuthUserRedisDAO; |
| 7 | 7 | import cn.iocoder.yudao.coreservice.modules.system.enums.social.SysSocialTypeEnum; |
| 8 | -import cn.iocoder.yudao.coreservice.modules.system.service.social.impl.SysSocialServiceImpl; | |
| 8 | +import cn.iocoder.yudao.coreservice.modules.system.service.social.impl.SysSocialCoreServiceImpl; | |
| 9 | 9 | import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; |
| 10 | 10 | import com.xkcoding.justauth.AuthRequestFactory; |
| 11 | 11 | import me.zhyd.oauth.model.AuthUser; |
| ... | ... | @@ -23,20 +23,19 @@ import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomLongId |
| 23 | 23 | import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo; |
| 24 | 24 | import static org.junit.jupiter.api.Assertions.assertEquals; |
| 25 | 25 | |
| 26 | -// TODO @timfruit:这个单元测试,挪到 yudao-core-service | |
| 27 | 26 | /** |
| 28 | - * {@link SysSocialServiceImpl} 的单元测试类 | |
| 27 | + * {@link SysSocialCoreServiceImpl} 的单元测试类 | |
| 29 | 28 | * |
| 30 | 29 | * @author 芋道源码 |
| 31 | 30 | */ |
| 32 | -@Import({SysSocialServiceImpl.class, SysSocialAuthUserRedisDAO.class}) | |
| 33 | -public class SysSocialServiceTest extends BaseDbAndRedisUnitTest { | |
| 31 | +@Import({SysSocialCoreServiceImpl.class, SysSocialAuthUserRedisDAO.class}) | |
| 32 | +public class SysSocialCoreServiceTest extends BaseDbAndRedisUnitTest { | |
| 34 | 33 | |
| 35 | 34 | @Resource |
| 36 | - private SysSocialServiceImpl socialService; | |
| 35 | + private SysSocialCoreServiceImpl socialService; | |
| 37 | 36 | |
| 38 | 37 | @Resource |
| 39 | - private SysSocialUserMapper socialUserMapper; | |
| 38 | + private SysSocialUserCoreMapper socialUserMapper; | |
| 40 | 39 | |
| 41 | 40 | @MockBean |
| 42 | 41 | private AuthRequestFactory authRequestFactory; | ... | ... |
yudao-core-service/src/test/resources/sql/clean.sql
yudao-core-service/src/test/resources/sql/create_tables.sql
| ... | ... | @@ -177,3 +177,23 @@ CREATE TABLE IF NOT EXISTS `sys_login_log` ( |
| 177 | 177 | "tenant_id" bigint not null default '0', |
| 178 | 178 | PRIMARY KEY (`id`) |
| 179 | 179 | ) COMMENT ='系统访问记录'; |
| 180 | + | |
| 181 | +CREATE TABLE IF NOT EXISTS "sys_social_user" ( | |
| 182 | + "id" number NOT NULL GENERATED BY DEFAULT AS IDENTITY, | |
| 183 | + "user_id" bigint NOT NULL, | |
| 184 | + "user_type" tinyint NOT NULL DEFAULT '0', | |
| 185 | + "type" tinyint NOT NULL, | |
| 186 | + "openid" varchar(32) NOT NULL, | |
| 187 | + "token" varchar(256) DEFAULT NULL, | |
| 188 | + "union_id" varchar(32) NOT NULL, | |
| 189 | + "raw_token_info" varchar(1024) NOT NULL, | |
| 190 | + "nickname" varchar(32) NOT NULL, | |
| 191 | + "avatar" varchar(255) DEFAULT NULL, | |
| 192 | + "raw_user_info" varchar(1024) NOT NULL, | |
| 193 | + "creator" varchar(64) DEFAULT '', | |
| 194 | + "create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, | |
| 195 | + "updater" varchar(64) DEFAULT '', | |
| 196 | + "update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, | |
| 197 | + "deleted" bit NOT NULL DEFAULT FALSE, | |
| 198 | + PRIMARY KEY ("id") | |
| 199 | +) COMMENT '社交用户'; | ... | ... |
yudao-framework/yudao-spring-boot-starter-biz-social/pom.xml
0 → 100644
| 1 | +<?xml version="1.0" encoding="UTF-8"?> | |
| 2 | +<project xmlns="http://maven.apache.org/POM/4.0.0" | |
| 3 | + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
| 4 | + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
| 5 | + <parent> | |
| 6 | + <groupId>cn.iocoder.boot</groupId> | |
| 7 | + <artifactId>yudao-framework</artifactId> | |
| 8 | + <version>${revision}</version> | |
| 9 | + </parent> | |
| 10 | + <packaging>jar</packaging> | |
| 11 | + <modelVersion>4.0.0</modelVersion> | |
| 12 | + | |
| 13 | + <artifactId>yudao-spring-boot-starter-biz-social</artifactId> | |
| 14 | + <name>${artifactId}</name> | |
| 15 | + | |
| 16 | + <dependencies> | |
| 17 | + <dependency> | |
| 18 | + <groupId>cn.iocoder.boot</groupId> | |
| 19 | + <artifactId>yudao-common</artifactId> | |
| 20 | + </dependency> | |
| 21 | + <!-- Spring 核心 --> | |
| 22 | + <dependency> | |
| 23 | + <groupId>org.springframework.boot</groupId> | |
| 24 | + <artifactId>spring-boot-starter-aop</artifactId> | |
| 25 | + </dependency> | |
| 26 | + <!-- Web 相关 --> | |
| 27 | + <dependency> | |
| 28 | + <groupId>cn.iocoder.boot</groupId> | |
| 29 | + <artifactId>yudao-spring-boot-starter-web</artifactId> | |
| 30 | + </dependency> | |
| 31 | + <!-- spring boot 配置所需依赖 --> | |
| 32 | + <dependency> | |
| 33 | + <groupId>org.springframework.boot</groupId> | |
| 34 | + <artifactId>spring-boot-configuration-processor</artifactId> | |
| 35 | + <optional>true</optional> | |
| 36 | + </dependency> | |
| 37 | + <!-- 三方云服务相关 --> | |
| 38 | + <dependency> | |
| 39 | + <groupId>com.xkcoding.justauth</groupId> | |
| 40 | + <artifactId>justauth-spring-boot-starter</artifactId> | |
| 41 | + </dependency> | |
| 42 | + <dependency> | |
| 43 | + <groupId>cn.iocoder.boot</groupId> | |
| 44 | + <artifactId>yudao-spring-boot-starter-redis</artifactId> | |
| 45 | + </dependency> | |
| 46 | + | |
| 47 | + </dependencies> | |
| 48 | + | |
| 49 | + | |
| 50 | +</project> | |
| 0 | 51 | \ No newline at end of file | ... | ... |
yudao-framework/yudao-spring-boot-starter-biz-social/src/main/java/cn/iocoder/yudao/framework/social/config/YudaoSocialAutoConfiguration.java
0 → 100644
| 1 | +package cn.iocoder.yudao.framework.social.config; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.social.core.YudaoAuthRequestFactory; | |
| 4 | +import com.xkcoding.justauth.autoconfigure.JustAuthProperties; | |
| 5 | +import lombok.extern.slf4j.Slf4j; | |
| 6 | +import me.zhyd.oauth.cache.AuthStateCache; | |
| 7 | +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | |
| 8 | +import org.springframework.boot.context.properties.EnableConfigurationProperties; | |
| 9 | +import org.springframework.context.annotation.Bean; | |
| 10 | +import org.springframework.context.annotation.Configuration; | |
| 11 | + | |
| 12 | +/** | |
| 13 | + * 社交自动装配类 | |
| 14 | + * | |
| 15 | + * @author timfruit | |
| 16 | + * @date 2021-10-30 | |
| 17 | + */ | |
| 18 | +@Slf4j | |
| 19 | +@Configuration | |
| 20 | +@EnableConfigurationProperties(JustAuthProperties.class) | |
| 21 | +public class YudaoSocialAutoConfiguration { | |
| 22 | + | |
| 23 | + @Bean | |
| 24 | + @ConditionalOnProperty(prefix = "justauth", value = "enabled", havingValue = "true", matchIfMissing = true) | |
| 25 | + public YudaoAuthRequestFactory yudaoAuthRequestFactory(JustAuthProperties properties, AuthStateCache authStateCache) { | |
| 26 | + return new YudaoAuthRequestFactory(properties, authStateCache); | |
| 27 | + } | |
| 28 | + | |
| 29 | +} | ... | ... |
yudao-framework/yudao-spring-boot-starter-biz-social/src/main/java/cn/iocoder/yudao/framework/social/core/YudaoAuthRequestFactory.java
0 → 100644
| 1 | +package cn.iocoder.yudao.framework.social.core; | |
| 2 | + | |
| 3 | +import cn.hutool.core.util.EnumUtil; | |
| 4 | +import cn.hutool.core.util.ReflectUtil; | |
| 5 | +import cn.iocoder.yudao.framework.social.core.enums.AuthExtendSource; | |
| 6 | +import cn.iocoder.yudao.framework.social.core.request.AuthWeChatMiniProgramRequest; | |
| 7 | +import com.xkcoding.justauth.AuthRequestFactory; | |
| 8 | +import com.xkcoding.justauth.autoconfigure.JustAuthProperties; | |
| 9 | +import me.zhyd.oauth.cache.AuthStateCache; | |
| 10 | +import me.zhyd.oauth.config.AuthConfig; | |
| 11 | +import me.zhyd.oauth.config.AuthSource; | |
| 12 | +import me.zhyd.oauth.request.AuthRequest; | |
| 13 | + | |
| 14 | +import java.lang.reflect.Method; | |
| 15 | + | |
| 16 | +/** | |
| 17 | + * 第三方授权拓展 request 工厂类 | |
| 18 | + * 为使得拓展配置 {@link AuthConfig} 和默认配置齐平,所以自定义本工厂类 | |
| 19 | + * | |
| 20 | + * @author timfruit | |
| 21 | + * @date 2021-10-31 | |
| 22 | + */ | |
| 23 | +// TODO @timfruit:单测 | |
| 24 | +public class YudaoAuthRequestFactory extends AuthRequestFactory { | |
| 25 | + | |
| 26 | + protected JustAuthProperties properties; | |
| 27 | + protected AuthStateCache authStateCache; | |
| 28 | + | |
| 29 | + /** | |
| 30 | + * 由于父类 configureHttpConfig 方法是 private 修饰,所以获取后,进行反射调用 | |
| 31 | + */ | |
| 32 | + private final Method configureHttpConfigMethod = ReflectUtil.getMethod(AuthRequestFactory.class, | |
| 33 | + "configureHttpConfig", String.class, AuthConfig.class, JustAuthProperties.JustAuthHttpConfig.class); | |
| 34 | + | |
| 35 | + public YudaoAuthRequestFactory(JustAuthProperties properties, AuthStateCache authStateCache) { | |
| 36 | + super(properties, authStateCache); | |
| 37 | + this.properties = properties; | |
| 38 | + this.authStateCache = authStateCache; | |
| 39 | + } | |
| 40 | + | |
| 41 | + /** | |
| 42 | + * 返回 AuthRequest 对象 | |
| 43 | + * | |
| 44 | + * @param source {@link AuthSource} | |
| 45 | + * @return {@link AuthRequest} | |
| 46 | + */ | |
| 47 | + public AuthRequest get(String source) { | |
| 48 | + // 先尝试获取自定义扩展的 | |
| 49 | + AuthRequest authRequest = getExtendRequest(source); | |
| 50 | + // 找不到,使用默认拓展 | |
| 51 | + if (authRequest == null) { | |
| 52 | + authRequest = super.get(source); | |
| 53 | + } | |
| 54 | + return authRequest; | |
| 55 | + } | |
| 56 | + | |
| 57 | + protected AuthRequest getExtendRequest(String source) { | |
| 58 | + AuthExtendSource authExtendSource; | |
| 59 | + try { | |
| 60 | + authExtendSource = EnumUtil.fromString(AuthExtendSource.class, source.toUpperCase()); | |
| 61 | + } catch (IllegalArgumentException e) { | |
| 62 | + // 无自定义匹配 | |
| 63 | + return null; | |
| 64 | + } | |
| 65 | + | |
| 66 | + // 拓展配置和默认配置齐平,properties 放在一起 | |
| 67 | + AuthConfig config = properties.getType().get(authExtendSource.name()); | |
| 68 | + // 找不到对应关系,直接返回空 | |
| 69 | + if (config == null) { | |
| 70 | + return null; | |
| 71 | + } | |
| 72 | + // 配置 http config | |
| 73 | + ReflectUtil.invoke(this, configureHttpConfigMethod, | |
| 74 | + authExtendSource.name(), config, properties.getHttpConfig()); | |
| 75 | + | |
| 76 | + // 获得拓展的 Request | |
| 77 | + // noinspection SwitchStatementWithTooFewBranches | |
| 78 | + switch (authExtendSource) { | |
| 79 | + case WECHAT_MINI_PROGRAM: | |
| 80 | + return new AuthWeChatMiniProgramRequest(config, authStateCache); | |
| 81 | + default: | |
| 82 | + return null; | |
| 83 | + } | |
| 84 | + } | |
| 85 | + | |
| 86 | +} | ... | ... |
yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/compent/justauth/AuthExtendSource.java renamed to yudao-framework/yudao-spring-boot-starter-biz-social/src/main/java/cn/iocoder/yudao/framework/social/core/enums/AuthExtendSource.java
| 1 | -package cn.iocoder.yudao.coreservice.modules.system.compent.justauth; | |
| 1 | +package cn.iocoder.yudao.framework.social.core.enums; | |
| 2 | 2 | |
| 3 | 3 | import me.zhyd.oauth.config.AuthSource; |
| 4 | 4 | |
| 5 | +/** | |
| 6 | + * 拓展JustAuth各api需要的url, 用枚举类分平台类型管理 | |
| 7 | + * | |
| 8 | + * 默认配置 {@link me.zhyd.oauth.config.AuthDefaultSource} | |
| 9 | + * | |
| 10 | + * @author timfruit | |
| 11 | + */ | |
| 5 | 12 | public enum AuthExtendSource implements AuthSource { |
| 6 | 13 | |
| 7 | 14 | /** |
| 8 | 15 | * 微信小程序授权登录 |
| 9 | 16 | */ |
| 10 | - WECHAT_MINI_PROGRAM{ | |
| 17 | + WECHAT_MINI_PROGRAM { | |
| 18 | + | |
| 11 | 19 | @Override |
| 12 | 20 | public String authorize() { |
| 13 | 21 | // https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/login.html |
| ... | ... | @@ -28,6 +36,4 @@ public enum AuthExtendSource implements AuthSource { |
| 28 | 36 | } |
| 29 | 37 | } |
| 30 | 38 | |
| 31 | - ; | |
| 32 | - | |
| 33 | 39 | } | ... | ... |
yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/compent/justauth/AuthExtendToken.java renamed to yudao-framework/yudao-spring-boot-starter-biz-social/src/main/java/cn/iocoder/yudao/framework/social/core/model/AuthExtendToken.java
| 1 | -package cn.iocoder.yudao.coreservice.modules.system.compent.justauth; | |
| 1 | +package cn.iocoder.yudao.framework.social.core.model; | |
| 2 | 2 | |
| 3 | 3 | import lombok.*; |
| 4 | 4 | import me.zhyd.oauth.model.AuthToken; |
| 5 | 5 | |
| 6 | 6 | /** |
| 7 | - * TODO @timfruit:类注释 | |
| 7 | + * 授权所需的 token 拓展类 | |
| 8 | + * | |
| 8 | 9 | * @author timfruit |
| 9 | 10 | * @date 2021-10-29 |
| 10 | 11 | */ |
| ... | ... | @@ -15,7 +16,7 @@ import me.zhyd.oauth.model.AuthToken; |
| 15 | 16 | public class AuthExtendToken extends AuthToken { |
| 16 | 17 | |
| 17 | 18 | /** |
| 18 | - * 微信小程序 会话密钥 | |
| 19 | + * 微信小程序 - 会话密钥 | |
| 19 | 20 | */ |
| 20 | 21 | private String miniSessionKey; |
| 21 | 22 | ... | ... |
yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/compent/justauth/AuthWeChatMiniProgramRequest.java renamed to yudao-framework/yudao-spring-boot-starter-biz-social/src/main/java/cn/iocoder/yudao/framework/social/core/request/AuthWeChatMiniProgramRequest.java
| 1 | -package cn.iocoder.yudao.coreservice.modules.system.compent.justauth; | |
| 1 | +package cn.iocoder.yudao.framework.social.core.request; | |
| 2 | 2 | |
| 3 | -import com.alibaba.fastjson.JSONObject; | |
| 3 | +import cn.iocoder.yudao.framework.common.util.json.JsonUtils; | |
| 4 | +import cn.iocoder.yudao.framework.social.core.enums.AuthExtendSource; | |
| 5 | +import cn.iocoder.yudao.framework.social.core.model.AuthExtendToken; | |
| 6 | +import com.fasterxml.jackson.annotation.JsonProperty; | |
| 7 | +import lombok.Data; | |
| 4 | 8 | import me.zhyd.oauth.cache.AuthStateCache; |
| 5 | 9 | import me.zhyd.oauth.config.AuthConfig; |
| 6 | 10 | import me.zhyd.oauth.exception.AuthException; |
| ... | ... | @@ -11,9 +15,6 @@ import me.zhyd.oauth.request.AuthDefaultRequest; |
| 11 | 15 | import me.zhyd.oauth.utils.HttpUtils; |
| 12 | 16 | import me.zhyd.oauth.utils.UrlBuilder; |
| 13 | 17 | |
| 14 | -// TODO @timfruit:新建一个 yudao-spring-boot-starter-biz-social 包,把这个拓展拿进去哈。另外,可以思考下。 | |
| 15 | -// 1. application-local.yaml 的配置里,justauth.extend.enum-class 能否不配置,而是自动配置好 | |
| 16 | -// 2. application-local.yaml 的配置里,justauth.extend.extend.config.WECHAT_MINI_PROGRAM 有办法和 justauth.type.WECHAT_MP 持平 | |
| 17 | 18 | /** |
| 18 | 19 | * 微信小程序登陆 |
| 19 | 20 | * |
| ... | ... | @@ -34,14 +35,14 @@ public class AuthWeChatMiniProgramRequest extends AuthDefaultRequest { |
| 34 | 35 | protected AuthToken getAccessToken(AuthCallback authCallback) { |
| 35 | 36 | // https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/login/auth.code2Session.html |
| 36 | 37 | String response = new HttpUtils(config.getHttpConfig()).get(accessTokenUrl(authCallback.getCode())); |
| 37 | - JSONObject accessTokenObject = JSONObject.parseObject(response); // TODO @timfruit:使用 JsonUtils,项目尽量避免直接使用某个 json 库 | |
| 38 | + CodeSessionResponse accessTokenObject = JsonUtils.parseObject(response, CodeSessionResponse.class); | |
| 38 | 39 | |
| 39 | 40 | this.checkResponse(accessTokenObject); |
| 40 | 41 | |
| 41 | 42 | AuthExtendToken token = new AuthExtendToken(); |
| 42 | - token.setMiniSessionKey(accessTokenObject.getString("session_key")); | |
| 43 | - token.setOpenId(accessTokenObject.getString("openid")); | |
| 44 | - token.setUnionId(accessTokenObject.getString("unionid")); | |
| 43 | + token.setMiniSessionKey(accessTokenObject.sessionKey); | |
| 44 | + token.setOpenId(accessTokenObject.openid); | |
| 45 | + token.setUnionId(accessTokenObject.unionid); | |
| 45 | 46 | return token; |
| 46 | 47 | } |
| 47 | 48 | |
| ... | ... | @@ -64,10 +65,9 @@ public class AuthWeChatMiniProgramRequest extends AuthDefaultRequest { |
| 64 | 65 | * |
| 65 | 66 | * @param object 请求响应内容 |
| 66 | 67 | */ |
| 67 | - private void checkResponse(JSONObject object) { | |
| 68 | - int code = object.getIntValue("errcode"); | |
| 69 | - if(code != 0){ // TODO @timfruit:if (code != 0) { ,注意空格 | |
| 70 | - throw new AuthException(object.getIntValue("errcode"), object.getString("errmsg")); | |
| 68 | + private void checkResponse(CodeSessionResponse object) { | |
| 69 | + if (object.errcode != 0) { | |
| 70 | + throw new AuthException(object.errcode, object.errmsg); | |
| 71 | 71 | } |
| 72 | 72 | } |
| 73 | 73 | |
| ... | ... | @@ -87,4 +87,14 @@ public class AuthWeChatMiniProgramRequest extends AuthDefaultRequest { |
| 87 | 87 | .build(); |
| 88 | 88 | } |
| 89 | 89 | |
| 90 | + @Data | |
| 91 | + private static class CodeSessionResponse { | |
| 92 | + private int errcode; | |
| 93 | + private String errmsg; | |
| 94 | + @JsonProperty("session_key") | |
| 95 | + private String sessionKey; | |
| 96 | + private String openid; | |
| 97 | + private String unionid; | |
| 98 | + } | |
| 99 | + | |
| 90 | 100 | } | ... | ... |
yudao-framework/yudao-spring-boot-starter-biz-social/src/main/resources/META-INF/spring.factories
0 → 100644
yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/controller/auth/SysAuthController.java
| 1 | 1 | package cn.iocoder.yudao.userserver.modules.system.controller.auth; |
| 2 | 2 | |
| 3 | -import cn.iocoder.yudao.coreservice.modules.system.service.social.SysSocialService; | |
| 3 | +import cn.iocoder.yudao.coreservice.modules.system.service.social.SysSocialCoreService; | |
| 4 | 4 | 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; |
| ... | ... | @@ -38,7 +38,7 @@ public class SysAuthController { |
| 38 | 38 | @Resource |
| 39 | 39 | private SysSmsCodeService smsCodeService; |
| 40 | 40 | @Resource |
| 41 | - private SysSocialService socialService; | |
| 41 | + private SysSocialCoreService socialService; | |
| 42 | 42 | |
| 43 | 43 | @PostMapping("/login") |
| 44 | 44 | @ApiOperation("使用手机 + 密码登录") |
| ... | ... | @@ -115,19 +115,6 @@ public class SysAuthController { |
| 115 | 115 | return CommonResult.success(socialService.getAuthorizeUrl(type, redirectUri)); |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | - // TODO @timfruit:这个接口,是要删除的么? | |
| 119 | - @GetMapping("/social-login-get") | |
| 120 | - @ApiOperation("微信公众号授权回调地址,输出social-login2的必要参数用于测试,使用 code 授权码") | |
| 121 | - @ResponseBody | |
| 122 | - @Deprecated | |
| 123 | - public CommonResult<MbrAuthSocialLoginReqVO> socialLoginGet(HttpServletRequest request,String code,String state) { | |
| 124 | - // 返回结果 | |
| 125 | - MbrAuthSocialLoginReqVO reqVO = MbrAuthSocialLoginReqVO.builder().state(state).code(code).build(); | |
| 126 | - reqVO.setType(12); | |
| 127 | - //输出social-login2的必要参数用于测试 | |
| 128 | - System.out.println(JSON.toJSON(reqVO)); | |
| 129 | - return success(reqVO); | |
| 130 | - } | |
| 131 | 118 | |
| 132 | 119 | @PostMapping("/social-login") |
| 133 | 120 | @ApiOperation("社交登录,使用 code 授权码") |
| ... | ... | @@ -136,10 +123,9 @@ public class SysAuthController { |
| 136 | 123 | return success(SysAuthLoginRespVO.builder().token(token).build()); |
| 137 | 124 | } |
| 138 | 125 | |
| 139 | - // TODO @timfruit:社交登陆时,使用手机验证码来验证哈。这块我当时没设计好,改改,嘿嘿。 | |
| 140 | 126 | |
| 141 | 127 | @PostMapping("/social-login2") |
| 142 | - @ApiOperation("社交登录,使用 code 授权码 + 账号密码") | |
| 128 | + @ApiOperation("社交登录,使用 手机号 + 手机验证码") | |
| 143 | 129 | public CommonResult<SysAuthLoginRespVO> socialLogin2(@RequestBody @Valid MbrAuthSocialLogin2ReqVO reqVO) { |
| 144 | 130 | String token = authService.socialLogin2(reqVO, getClientIP(), getUserAgent()); |
| 145 | 131 | return success(SysAuthLoginRespVO.builder().token(token).build()); | ... | ... |
yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/controller/auth/vo/MbrAuthSocialLogin2ReqVO.java
| ... | ... | @@ -34,15 +34,16 @@ public class MbrAuthSocialLogin2ReqVO { |
| 34 | 34 | @NotEmpty(message = "state 不能为空") |
| 35 | 35 | private String state; |
| 36 | 36 | |
| 37 | - @ApiModelProperty(value = "账号", required = true, example = "yudaoyuanma") | |
| 38 | - @NotEmpty(message = "登录账号不能为空") | |
| 39 | - @Length(min = 4, max = 16, message = "账号长度为 4-16 位") | |
| 40 | - @Pattern(regexp = "^[A-Za-z0-9]+$", message = "账号格式为数字以及字母") | |
| 41 | - private String username; | |
| 42 | - | |
| 43 | - @ApiModelProperty(value = "密码", required = true, example = "buzhidao") | |
| 44 | - @NotEmpty(message = "密码不能为空") | |
| 45 | - @Length(min = 4, max = 16, message = "密码长度为 4-16 位") | |
| 46 | - private String password; | |
| 37 | + @ApiModelProperty(value = "手机号", required = true, example = "15119100000") | |
| 38 | + @NotEmpty(message = "手机号不能为空") | |
| 39 | + @Length(min = 11, max = 11, message = "手机号是11位数字") | |
| 40 | + private String mobile; | |
| 41 | + | |
| 42 | + @ApiModelProperty(value = "手机验证码", required = true, example = "1024") | |
| 43 | + @NotEmpty(message = "手机验证码不能为空") | |
| 44 | + @Length(min = 4, max = 6, message = "手机验证码长度为 4-6 位") | |
| 45 | + @Pattern(regexp = "^[0-9]+$", message = "手机验证码必须都是数字") | |
| 46 | + private String smsCode; | |
| 47 | + | |
| 47 | 48 | |
| 48 | 49 | } | ... | ... |
yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/service/auth/SysAuthService.java
| ... | ... | @@ -46,7 +46,7 @@ public interface SysAuthService extends SecurityAuthFrameworkService { |
| 46 | 46 | String socialLogin(@Valid MbrAuthSocialLoginReqVO reqVO, String userIp, String userAgent); |
| 47 | 47 | |
| 48 | 48 | /** |
| 49 | - * 社交登录,使用 code 授权码 + 账号密码 | |
| 49 | + * 社交登录,使用 手机号 + 手机验证码 | |
| 50 | 50 | * |
| 51 | 51 | * @param reqVO 登录信息 |
| 52 | 52 | * @param userIp 用户 IP | ... | ... |
yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/service/auth/impl/SysAuthServiceImpl.java
| ... | ... | @@ -9,7 +9,7 @@ import cn.iocoder.yudao.coreservice.modules.system.enums.logger.SysLoginResultEn |
| 9 | 9 | import cn.iocoder.yudao.coreservice.modules.system.service.auth.SysUserSessionCoreService; |
| 10 | 10 | import cn.iocoder.yudao.coreservice.modules.system.service.logger.SysLoginLogCoreService; |
| 11 | 11 | import cn.iocoder.yudao.coreservice.modules.system.service.logger.dto.SysLoginLogCreateReqDTO; |
| 12 | -import cn.iocoder.yudao.coreservice.modules.system.service.social.SysSocialService; | |
| 12 | +import cn.iocoder.yudao.coreservice.modules.system.service.social.SysSocialCoreService; | |
| 13 | 13 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 14 | 14 | import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; |
| 15 | 15 | import cn.iocoder.yudao.framework.common.util.monitor.TracerUtils; |
| ... | ... | @@ -57,6 +57,8 @@ import static cn.iocoder.yudao.userserver.modules.system.enums.SysErrorCodeConst |
| 57 | 57 | @Slf4j |
| 58 | 58 | public class SysAuthServiceImpl implements SysAuthService { |
| 59 | 59 | |
| 60 | + private static final UserTypeEnum USER_TYPE_ENUM = UserTypeEnum.MEMBER; | |
| 61 | + | |
| 60 | 62 | @Resource |
| 61 | 63 | @Lazy // 延迟加载,因为存在相互依赖的问题 |
| 62 | 64 | private AuthenticationManager authenticationManager; |
| ... | ... | @@ -70,7 +72,8 @@ public class SysAuthServiceImpl implements SysAuthService { |
| 70 | 72 | @Resource |
| 71 | 73 | private SysUserSessionCoreService userSessionCoreService; |
| 72 | 74 | @Resource |
| 73 | - private SysSocialService socialService; | |
| 75 | + private SysSocialCoreService socialService; | |
| 76 | + | |
| 74 | 77 | @Resource |
| 75 | 78 | private StringRedisTemplate stringRedisTemplate; |
| 76 | 79 | @Resource |
| ... | ... | @@ -127,7 +130,7 @@ public class SysAuthServiceImpl implements SysAuthService { |
| 127 | 130 | |
| 128 | 131 | // 如果未绑定 SysSocialUserDO 用户,则无法自动登录,进行报错 |
| 129 | 132 | String unionId = socialService.getAuthUserUnionId(authUser); |
| 130 | - List<SysSocialUserDO> socialUsers = socialService.getAllSocialUserList(reqVO.getType(), unionId, userTypeEnum); | |
| 133 | + List<SysSocialUserDO> socialUsers = socialService.getAllSocialUserList(reqVO.getType(), unionId, USER_TYPE_ENUM); | |
| 131 | 134 | if (CollUtil.isEmpty(socialUsers)) { |
| 132 | 135 | throw exception(AUTH_THIRD_LOGIN_NOT_BIND); |
| 133 | 136 | } |
| ... | ... | @@ -143,7 +146,7 @@ public class SysAuthServiceImpl implements SysAuthService { |
| 143 | 146 | LoginUser loginUser = SysAuthConvert.INSTANCE.convert(user); |
| 144 | 147 | |
| 145 | 148 | // 绑定社交用户(更新) |
| 146 | - socialService.bindSocialUser(loginUser.getId(), reqVO.getType(), authUser, userTypeEnum); | |
| 149 | + socialService.bindSocialUser(loginUser.getId(), reqVO.getType(), authUser, USER_TYPE_ENUM); | |
| 147 | 150 | |
| 148 | 151 | // 缓存登录用户到 Redis 中,返回 sessionId 编号 |
| 149 | 152 | return userSessionCoreService.createUserSession(loginUser, userIp, userAgent); |
| ... | ... | @@ -151,19 +154,21 @@ public class SysAuthServiceImpl implements SysAuthService { |
| 151 | 154 | |
| 152 | 155 | @Override |
| 153 | 156 | public String socialLogin2(MbrAuthSocialLogin2ReqVO reqVO, String userIp, String userAgent) { |
| 154 | - // 使用 code 授权码,进行登录 | |
| 155 | 157 | AuthUser authUser = socialService.getAuthUser(reqVO.getType(), reqVO.getCode(), reqVO.getState()); |
| 156 | 158 | org.springframework.util.Assert.notNull(authUser, "授权用户不为空"); |
| 157 | 159 | |
| 158 | - // 使用账号密码,进行登录。 | |
| 159 | - LoginUser loginUser = this.login0(reqVO.getUsername(), reqVO.getPassword()); | |
| 160 | -// loginUser.setRoleIds(this.getUserRoleIds(loginUser.getId())); // 获取用户角色列表 | |
| 160 | + // 使用手机号、手机验证码登录 | |
| 161 | + SysAuthSmsLoginReqVO loginReqVO = SysAuthSmsLoginReqVO | |
| 162 | + .builder() | |
| 163 | + .mobile(reqVO.getMobile()) | |
| 164 | + .code(reqVO.getSmsCode()) | |
| 165 | + .build(); | |
| 166 | + String sessionId = this.smsLogin(loginReqVO, userIp, userAgent); | |
| 167 | + LoginUser loginUser = userSessionCoreService.getLoginUser(sessionId); | |
| 161 | 168 | |
| 162 | 169 | // 绑定社交用户(新增) |
| 163 | - socialService.bindSocialUser(loginUser.getId(), reqVO.getType(), authUser, userTypeEnum); | |
| 164 | - | |
| 165 | - // 缓存登录用户到 Redis 中,返回 sessionId 编号 | |
| 166 | - return userSessionCoreService.createUserSession(loginUser, userIp, userAgent); | |
| 170 | + socialService.bindSocialUser(loginUser.getId(), reqVO.getType(), authUser, USER_TYPE_ENUM); | |
| 171 | + return sessionId; | |
| 167 | 172 | } |
| 168 | 173 | |
| 169 | 174 | @Override |
| ... | ... | @@ -173,7 +178,7 @@ public class SysAuthServiceImpl implements SysAuthService { |
| 173 | 178 | org.springframework.util.Assert.notNull(authUser, "授权用户不为空"); |
| 174 | 179 | |
| 175 | 180 | // 绑定社交用户(新增) |
| 176 | - socialService.bindSocialUser(userId, reqVO.getType(), authUser, userTypeEnum); | |
| 181 | + socialService.bindSocialUser(userId, reqVO.getType(), authUser, USER_TYPE_ENUM); | |
| 177 | 182 | } |
| 178 | 183 | |
| 179 | 184 | private LoginUser login0(String username, String password) { |
| ... | ... | @@ -347,7 +352,7 @@ public class SysAuthServiceImpl implements SysAuthService { |
| 347 | 352 | reqDTO.setLogType(SysLoginLogTypeEnum.LOGOUT_SELF.getType()); |
| 348 | 353 | reqDTO.setTraceId(TracerUtils.getTraceId()); |
| 349 | 354 | reqDTO.setUserId(userId); |
| 350 | - reqDTO.setUserType(userTypeEnum.getValue()); | |
| 355 | + reqDTO.setUserType(USER_TYPE_ENUM.getValue()); | |
| 351 | 356 | reqDTO.setUsername(username); |
| 352 | 357 | reqDTO.setUserAgent(ServletUtils.getUserAgent()); |
| 353 | 358 | reqDTO.setUserIp(getClientIP()); | ... | ... |
yudao-user-server/src/main/resources/application-dev.yaml
| ... | ... | @@ -150,24 +150,16 @@ yudao: |
| 150 | 150 | |
| 151 | 151 | justauth: |
| 152 | 152 | enabled: true |
| 153 | - type: # TODO @timfruit:GITEE、DINGTALK、WECHAT_ENTERPRISE 这个几个,对于用户端是不需要的哈,可以删除噢 | |
| 154 | - GITEE: # Gitee | |
| 155 | - client-id: ee61f0374a4c6c404a8717094caa7a410d76950e45ff60348015830c519ba5c1 | |
| 156 | - client-secret: 7c044a5671be3b051414db0cf2cec6ad702dd298d2416ba24ceaf608e6fa26f9 | |
| 157 | - ignore-check-redirect-uri: true | |
| 158 | - DINGTALK: # 钉钉 | |
| 159 | - client-id: dingvrnreaje3yqvzhxg | |
| 160 | - client-secret: i8E6iZyDvZj51JIb0tYsYfVQYOks9Cq1lgryEjFRqC79P3iJcrxEwT6Qk2QvLrLI | |
| 161 | - ignore-check-redirect-uri: true | |
| 162 | - WECHAT_ENTERPRISE: # 企业微信 | |
| 163 | - client-id: wwd411c69a39ad2e54 | |
| 164 | - client-secret: 1wTb7hYxnpT2TUbIeHGXGo7T0odav1ic10mLdyyATOw | |
| 165 | - agent-id: 1000004 | |
| 166 | - ignore-check-redirect-uri: true | |
| 167 | - WECHAT_MP: # 微信公众平台 - H5 https://mp.weixin.qq.com/debug/cgi-bin/sandboxinfo?action=showinfo&t=sandbox/index | |
| 153 | + type: | |
| 154 | + WECHAT_MP: # 微信公众平台 - 移动端 H5 https://www.yuque.com/docs/share/a795bef6-ee8a-494a-8dc4-2ef41927743b?#%20%E3%80%8A%E5%BE%AE%E4%BF%A1%E5%85%AC%E4%BC%97%E5%8F%B7%E6%B5%8B%E8%AF%95%E3%80%8B | |
| 168 | 155 | client-id: wxa5a05b85ac361f96 |
| 169 | 156 | client-secret: 247073c7cebb67f27f0e769195c2a57e |
| 170 | 157 | ignore-check-redirect-uri: true |
| 158 | + WECHAT_MINI_PROGRAM: # 微信小程序 https://www.yuque.com/docs/share/88e3d30a-6830-45fc-8c25-dae485aef3aa?#%20%E3%80%8A%E5%B0%8F%E7%A8%8B%E5%BA%8F%E6%8E%88%E6%9D%83%E7%99%BB%E5%BD%95%E3%80%8B | |
| 159 | + client-id: wx44d047d87e6284d8 | |
| 160 | + client-secret: 21c3b7a8a51ee1b8f5cf875848ed4466 | |
| 161 | + ignore-check-redirect-uri: true | |
| 162 | + ignore-check-state: true | |
| 171 | 163 | cache: |
| 172 | 164 | type: REDIS |
| 173 | 165 | prefix: 'social_auth_state:' # 缓存前缀,目前只对 Redis 缓存生效,默认 JUSTAUTH::STATE:: | ... | ... |
yudao-user-server/src/main/resources/application-local.yaml
| ... | ... | @@ -170,17 +170,13 @@ justauth: |
| 170 | 170 | # client-id: wx5b23ba7a5589ecbb # TODO 芋艿:自己的测试,后续可以删除 |
| 171 | 171 | # client-secret: 2a7b3b20c537e52e74afd395eb85f61f |
| 172 | 172 | ignore-check-redirect-uri: true |
| 173 | - extend: | |
| 174 | - enum-class: cn.iocoder.yudao.coreservice.modules.system.compent.justauth.AuthExtendSource | |
| 175 | - config: | |
| 176 | - WECHAT_MINI_PROGRAM: # 微信小程序 https://www.yuque.com/docs/share/88e3d30a-6830-45fc-8c25-dae485aef3aa?#%20%E3%80%8A%E5%B0%8F%E7%A8%8B%E5%BA%8F%E6%8E%88%E6%9D%83%E7%99%BB%E5%BD%95%E3%80%8B | |
| 177 | - request-class: cn.iocoder.yudao.coreservice.modules.system.compent.justauth.AuthWeChatMiniProgramRequest | |
| 178 | - client-id: wx44d047d87e6284d8 | |
| 179 | - client-secret: 21c3b7a8a51ee1b8f5cf875848ed4466 | |
| 180 | -# client-id: wx63c280fe3248a3e7 # TODO 芋艿:自己的测试,后续可以删除 | |
| 181 | -# client-secret: 6f270509224a7ae1296bbf1c8cb97aed | |
| 182 | - ignore-check-redirect-uri: true | |
| 183 | - ignore-check-state: true | |
| 173 | + WECHAT_MINI_PROGRAM: # 微信小程序 https://www.yuque.com/docs/share/88e3d30a-6830-45fc-8c25-dae485aef3aa?#%20%E3%80%8A%E5%B0%8F%E7%A8%8B%E5%BA%8F%E6%8E%88%E6%9D%83%E7%99%BB%E5%BD%95%E3%80%8B | |
| 174 | + client-id: wx44d047d87e6284d8 | |
| 175 | + client-secret: 21c3b7a8a51ee1b8f5cf875848ed4466 | |
| 176 | + # client-id: wx63c280fe3248a3e7 # TODO 芋艿:自己的测试,后续可以删除 | |
| 177 | + # client-secret: 6f270509224a7ae1296bbf1c8cb97aed | |
| 178 | + ignore-check-redirect-uri: true | |
| 179 | + ignore-check-state: true | |
| 184 | 180 | cache: |
| 185 | 181 | type: REDIS |
| 186 | 182 | prefix: 'social_auth_state:' # 缓存前缀,目前只对 Redis 缓存生效,默认 JUSTAUTH::STATE:: | ... | ... |
yudao-user-server/src/main/resources/static/READMD.md
0 → 100644
| 1 | +## 微信公众号 | |
| 2 | + | |
| 3 | +参考文章:https://www.yuque.com/docs/share/0e2966dd-89f8-4b69-980d-b876168725df | |
| 4 | + | |
| 5 | +① 访问 social-login.html 选择【微信公众号】 | |
| 6 | + | |
| 7 | +② 微信公众号授权完成后,跳转回 social-login2.html,输入手机号 + 密码,进行绑定 | |
| 8 | + | |
| 9 | +## 微信小程序 | |
| 10 | + | |
| 11 | +参考文章:https://www.yuque.com/docs/share/88e3d30a-6830-45fc-8c25-dae485aef3aa | |
| 12 | + | |
| 13 | +① 暂时使用 mini-program-test 项目 | ... | ... |
yudao-user-server/src/main/resources/static/social-login.html
| ... | ... | @@ -13,14 +13,16 @@ |
| 13 | 13 | </div> |
| 14 | 14 | </body> |
| 15 | 15 | <script> |
| 16 | - let server = 'http://127.0.0.1:28080'; | |
| 16 | + // let server = 'http://127.0.0.1:28080'; | |
| 17 | + let server = 'http://192.168.1.2:28080'; | |
| 18 | + | |
| 17 | 19 | |
| 18 | 20 | // 微信公众号 |
| 19 | 21 | $( "#wx_pub").on( "click", function() { |
| 20 | 22 | // 获得授权链接 |
| 21 | 23 | $.ajax({ |
| 22 | 24 | url: server + "/api/social-auth-redirect?type=31&redirectUri=" + |
| 23 | - encodeURIComponent(server + '/api/social-login-get'), | |
| 25 | + encodeURIComponent(server + '/static/social-login2.html'), //重定向地址 | |
| 24 | 26 | method: 'GET', |
| 25 | 27 | success: function( result ) { |
| 26 | 28 | if (result.code !== 0) { | ... | ... |
yudao-user-server/src/main/resources/static/social-login2.html
0 → 100644
| 1 | +<!DOCTYPE html> | |
| 2 | +<html> | |
| 3 | +<head> | |
| 4 | + <meta charset="UTF-8"> | |
| 5 | + <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no"/> | |
| 6 | + <title>社交登陆测试页</title> | |
| 7 | + <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.js"></script> | |
| 8 | +</head> | |
| 9 | +<body> | |
| 10 | +<div>点击如下按钮,授权登录</div> | |
| 11 | +<div> | |
| 12 | + 手机号<input id="mobile" value="15601691300"><br> | |
| 13 | + 手机验证码<input id="smsCode"> | |
| 14 | + <button id="send_sms_code">发送手机验证码</button> | |
| 15 | + <br> | |
| 16 | + <button id="wx_pub">微信公众号授权登录</button> | |
| 17 | +</div> | |
| 18 | +</body> | |
| 19 | +<script> | |
| 20 | + // let server = 'http://127.0.0.1:28080'; | |
| 21 | + let server = 'http://192.168.1.2:28080'; | |
| 22 | + | |
| 23 | + let type = 31; //登录类型 微信公众号 | |
| 24 | + | |
| 25 | + // 微信公众号 | |
| 26 | + $("#wx_pub").on("click", function () { | |
| 27 | + let code = getUrlParam("code"); // 访问授权连接后,会回调本页面地址,参数在本页面url后面 | |
| 28 | + let state = getUrlParam("state"); | |
| 29 | + console.log("获取code: " + code + ", state: " + state) | |
| 30 | + | |
| 31 | + let data = { | |
| 32 | + 'mobile': $('#mobile').val(), | |
| 33 | + 'smsCode': $('#smsCode').val(), | |
| 34 | + 'code': code, | |
| 35 | + 'state': state, | |
| 36 | + 'type': type | |
| 37 | + } | |
| 38 | + | |
| 39 | + // 调用授权登录接口 | |
| 40 | + $.ajax({ | |
| 41 | + url: server + "/api/social-login2", | |
| 42 | + method: 'POST', | |
| 43 | + data: JSON.stringify(data), | |
| 44 | + contentType: "application/json;charset=utf-8", | |
| 45 | + dataType: "json", | |
| 46 | + success: function( result ) { | |
| 47 | + if (result.code !== 0) { | |
| 48 | + alert('调用授权登录接口失败,原因:' + result.msg) | |
| 49 | + return; | |
| 50 | + } | |
| 51 | + alert("授权登录成功, token: "+result.data.token) | |
| 52 | + } | |
| 53 | + }) | |
| 54 | + }); | |
| 55 | + | |
| 56 | + // 发送手机验证码 | |
| 57 | + $("#send_sms_code").on("click", function () { | |
| 58 | + let data = { | |
| 59 | + 'mobile': $('#mobile').val(), | |
| 60 | + 'scene': 1 // 手机号登陆 类型 | |
| 61 | + } | |
| 62 | + $.ajax({ | |
| 63 | + url: server + "/api/send-sms-code", | |
| 64 | + method: 'POST', | |
| 65 | + data: JSON.stringify(data), | |
| 66 | + contentType: "application/json;charset=utf-8", | |
| 67 | + dataType: "json", | |
| 68 | + success: function (result) { | |
| 69 | + if (result.code !== 0) { | |
| 70 | + alert('发送手机验证码失败,原因:' + result.msg) | |
| 71 | + return; | |
| 72 | + } | |
| 73 | + alert("发送成功, 请查看日志"); | |
| 74 | + } | |
| 75 | + }) | |
| 76 | + }) | |
| 77 | + | |
| 78 | + | |
| 79 | + //获取url中的参数 | |
| 80 | + function getUrlParam(name) { | |
| 81 | + var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象 | |
| 82 | + var r = window.location.search.substr(1).match(reg); //匹配目标参数 | |
| 83 | + if (r != null) return unescape(r[2]); | |
| 84 | + return null; //返回参数值 | |
| 85 | + } | |
| 86 | +</script> | |
| 87 | +</html> | ... | ... |
yudao-user-server/src/test/java/cn/iocoder/yudao/userserver/modules/member/controller/SysUserProfileControllerTest.java
| ... | ... | @@ -4,6 +4,7 @@ import cn.iocoder.yudao.userserver.modules.member.controller.user.SysUserProfile |
| 4 | 4 | import cn.iocoder.yudao.userserver.modules.member.service.user.MbrUserService; |
| 5 | 5 | import cn.iocoder.yudao.userserver.modules.system.service.sms.SysSmsCodeService; |
| 6 | 6 | import org.junit.Before; |
| 7 | +import org.junit.Ignore; | |
| 7 | 8 | import org.junit.Test; |
| 8 | 9 | import org.mockito.InjectMocks; |
| 9 | 10 | import org.mockito.Mock; |
| ... | ... | @@ -46,6 +47,7 @@ public class SysUserProfileControllerTest { |
| 46 | 47 | } |
| 47 | 48 | |
| 48 | 49 | @Test |
| 50 | + @Ignore | |
| 49 | 51 | public void testUpdateMobile_success() throws Exception { |
| 50 | 52 | //模拟接口调用 |
| 51 | 53 | this.mockMvc.perform(post("/system/user/profile/update-mobile") | ... | ... |
yudao-user-server/src/test/java/cn/iocoder/yudao/userserver/modules/system/controller/SysAuthControllerTest.java
| 1 | 1 | package cn.iocoder.yudao.userserver.modules.system.controller; |
| 2 | 2 | |
| 3 | -import cn.iocoder.yudao.coreservice.modules.system.service.social.SysSocialService; | |
| 3 | +import cn.iocoder.yudao.coreservice.modules.system.service.social.SysSocialCoreService; | |
| 4 | 4 | import cn.iocoder.yudao.userserver.modules.system.controller.auth.SysAuthController; |
| 5 | 5 | import cn.iocoder.yudao.userserver.modules.system.service.auth.SysAuthService; |
| 6 | 6 | import cn.iocoder.yudao.userserver.modules.system.service.sms.SysSmsCodeService; |
| ... | ... | @@ -14,9 +14,7 @@ import org.springframework.test.web.servlet.MockMvc; |
| 14 | 14 | import org.springframework.test.web.servlet.result.MockMvcResultHandlers; |
| 15 | 15 | import org.springframework.test.web.servlet.setup.MockMvcBuilders; |
| 16 | 16 | |
| 17 | -import static org.springframework.http.HttpHeaders.AUTHORIZATION; | |
| 18 | -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; | |
| 19 | -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; | |
| 17 | +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; | |
| 20 | 18 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; |
| 21 | 19 | |
| 22 | 20 | /** |
| ... | ... | @@ -36,8 +34,7 @@ public class SysAuthControllerTest { |
| 36 | 34 | @Mock |
| 37 | 35 | private SysSmsCodeService smsCodeService; |
| 38 | 36 | @Mock |
| 39 | - private SysSocialService socialService; | |
| 40 | - | |
| 37 | + private SysSocialCoreService socialService; | |
| 41 | 38 | |
| 42 | 39 | @Before |
| 43 | 40 | public void setup() { |
| ... | ... | @@ -50,26 +47,22 @@ public class SysAuthControllerTest { |
| 50 | 47 | |
| 51 | 48 | @Test |
| 52 | 49 | public void testResetPassword_success() throws Exception { |
| 53 | - //模拟接口调用 | |
| 50 | + // 模拟接口调用 | |
| 54 | 51 | this.mockMvc.perform(post("/reset-password") |
| 55 | 52 | .contentType(MediaType.APPLICATION_JSON) |
| 56 | 53 | .content("{\"password\":\"1123\",\"code\":\"123456\"}}")) |
| 57 | 54 | .andExpect(status().isOk()) |
| 58 | 55 | .andDo(MockMvcResultHandlers.print()); |
| 59 | - | |
| 60 | 56 | } |
| 61 | 57 | |
| 62 | 58 | @Test |
| 63 | 59 | public void testUpdatePassword_success() throws Exception { |
| 64 | - //模拟接口调用 | |
| 60 | + // 模拟接口调用 | |
| 65 | 61 | this.mockMvc.perform(post("/update-password") |
| 66 | 62 | .contentType(MediaType.APPLICATION_JSON) |
| 67 | 63 | .content("{\"password\":\"1123\",\"code\":\"123456\",\"oldPassword\":\"1123\"}}")) |
| 68 | 64 | .andExpect(status().isOk()) |
| 69 | 65 | .andDo(MockMvcResultHandlers.print()); |
| 70 | - | |
| 71 | 66 | } |
| 72 | 67 | |
| 73 | - | |
| 74 | - | |
| 75 | 68 | } | ... | ... |
yudao-user-server/src/test/java/cn/iocoder/yudao/userserver/modules/system/service/SysAuthServiceTest.java
| ... | ... | @@ -3,7 +3,7 @@ package cn.iocoder.yudao.userserver.modules.system.service; |
| 3 | 3 | import cn.iocoder.yudao.coreservice.modules.member.dal.dataobject.user.MbrUserDO; |
| 4 | 4 | import cn.iocoder.yudao.coreservice.modules.system.service.auth.SysUserSessionCoreService; |
| 5 | 5 | import cn.iocoder.yudao.coreservice.modules.system.service.logger.SysLoginLogCoreService; |
| 6 | -import cn.iocoder.yudao.coreservice.modules.system.service.social.SysSocialService; | |
| 6 | +import cn.iocoder.yudao.coreservice.modules.system.service.social.SysSocialCoreService; | |
| 7 | 7 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 8 | 8 | import cn.iocoder.yudao.framework.common.util.collection.ArrayUtils; |
| 9 | 9 | import cn.iocoder.yudao.framework.redis.config.YudaoRedisAutoConfiguration; |
| ... | ... | @@ -53,7 +53,7 @@ public class SysAuthServiceTest extends BaseDbAndRedisUnitTest { |
| 53 | 53 | @MockBean |
| 54 | 54 | private SysUserSessionCoreService userSessionCoreService; |
| 55 | 55 | @MockBean |
| 56 | - private SysSocialService socialService; | |
| 56 | + private SysSocialCoreService socialService; | |
| 57 | 57 | @Resource |
| 58 | 58 | private StringRedisTemplate stringRedisTemplate; |
| 59 | 59 | @MockBean | ... | ... |
yudao-user-server/src/test/resources/sql/create_tables.sql
| ... | ... | @@ -14,6 +14,7 @@ CREATE TABLE IF NOT EXISTS "mbr_user" ( |
| 14 | 14 | "updater" varchar(64) NULL DEFAULT '' COMMENT '更新者', |
| 15 | 15 | "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', |
| 16 | 16 | "deleted" bit(1) NOT NULL DEFAULT '0' COMMENT '是否删除', |
| 17 | + "tenant_id" bigint not null default '0', | |
| 17 | 18 | PRIMARY KEY ("id") |
| 18 | 19 | ) COMMENT '会员表'; |
| 19 | 20 | ... | ... |