code review 用户前台的社交登陆

This commit is contained in:
YunaiV 2021-10-28 08:46:51 +08:00
parent 30ad7c43b8
commit 55e5ca4644
11 changed files with 20 additions and 12 deletions

View File

@ -75,6 +75,7 @@ public class SysAuthServiceImpl implements SysAuthService {
@Resource @Resource
private SysSocialService socialService; private SysSocialService socialService;
// TODO @timfruit静态枚举类需要都大写例如说 USER_TYPE_ENUM静态变量放在普通变量前面这个实践不错哈
private static final UserTypeEnum userTypeEnum = UserTypeEnum.ADMIN; private static final UserTypeEnum userTypeEnum = UserTypeEnum.ADMIN;
@Override @Override
@ -214,7 +215,6 @@ public class SysAuthServiceImpl implements SysAuthService {
// 创建 LoginUser 对象 // 创建 LoginUser 对象
LoginUser loginUser = SysAuthConvert.INSTANCE.convert(user); LoginUser loginUser = SysAuthConvert.INSTANCE.convert(user);
// TODO 芋艿需要改造下增加各种登录方式
loginUser.setRoleIds(this.getUserRoleIds(loginUser.getId())); // 获取用户角色列表 loginUser.setRoleIds(this.getUserRoleIds(loginUser.getId())); // 获取用户角色列表
// 绑定社交用户更新 // 绑定社交用户更新

View File

@ -86,11 +86,12 @@
<artifactId>guava</artifactId> <artifactId>guava</artifactId>
</dependency> </dependency>
<!-- 三方云服务相关 -->
<dependency> <dependency>
<groupId>com.xkcoding.justauth</groupId> <groupId>com.xkcoding.justauth</groupId>
<artifactId>justauth-spring-boot-starter</artifactId> <artifactId>justauth-spring-boot-starter</artifactId>
<version>1.4.0</version>
</dependency> </dependency>
</dependencies> </dependencies>
</project> </project>

View File

@ -8,6 +8,7 @@ import org.apache.ibatis.annotations.Mapper;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
// TODO @timfruitSysSocialUserCoreMapper 改名方便区分
@Mapper @Mapper
public interface SysSocialUserMapper extends BaseMapperX<SysSocialUserDO> { public interface SysSocialUserMapper extends BaseMapperX<SysSocialUserDO> {

View File

@ -19,11 +19,11 @@ public interface SysRedisKeyCoreConstants {
"login_user:%s", // 参数为 sessionId "login_user:%s", // 参数为 sessionId
STRING, LoginUser.class, RedisKeyDefine.TimeoutTypeEnum.DYNAMIC); STRING, LoginUser.class, RedisKeyDefine.TimeoutTypeEnum.DYNAMIC);
RedisKeyDefine SOCIAL_AUTH_USER = new RedisKeyDefine("社交的授权用户", RedisKeyDefine SOCIAL_AUTH_USER = new RedisKeyDefine("社交登陆的授权用户",
"social_auth_user:%d:%s", // 参数为 typecode "social_auth_user:%d:%s", // 参数为 typecode
STRING, AuthUser.class, Duration.ofDays(1)); STRING, AuthUser.class, Duration.ofDays(1));
RedisKeyDefine SOCIAL_AUTH_STATE = new RedisKeyDefine("社交的 state", RedisKeyDefine SOCIAL_AUTH_STATE = new RedisKeyDefine("社交登陆的 state",
"social_auth_state:%s", // 参数为 state "social_auth_state:%s", // 参数为 state
STRING, String.class, Duration.ofHours(24)); // 值为 state STRING, String.class, Duration.ofHours(24)); // 值为 state
} }

View File

@ -10,7 +10,7 @@ import javax.annotation.Resource;
import static cn.iocoder.yudao.coreservice.modules.system.dal.redis.SysRedisKeyCoreConstants.SOCIAL_AUTH_USER; import static cn.iocoder.yudao.coreservice.modules.system.dal.redis.SysRedisKeyCoreConstants.SOCIAL_AUTH_USER;
// TODO @timfruit这里的 AuthUser 还是保留全路径主要想体现出来不是自己定义的
/** /**
* 社交 {@link AuthUser} RedisDAO * 社交 {@link AuthUser} RedisDAO
* *

View File

@ -21,6 +21,7 @@ public enum SysSocialTypeEnum implements IntArrayValuable {
GITEE(10, "GITEE"), // https://gitee.com/api/v5/oauth_doc#/ GITEE(10, "GITEE"), // https://gitee.com/api/v5/oauth_doc#/
DINGTALK(20, "DINGTALK"), // https://developers.dingtalk.com/document/app/obtain-identity-credentials DINGTALK(20, "DINGTALK"), // https://developers.dingtalk.com/document/app/obtain-identity-credentials
WECHAT_ENTERPRISE(30, "WECHAT_ENTERPRISE"), // https://xkcoding.com/2019/08/06/use-justauth-integration-wechat-enterprise.html WECHAT_ENTERPRISE(30, "WECHAT_ENTERPRISE"), // https://xkcoding.com/2019/08/06/use-justauth-integration-wechat-enterprise.html
// TODO @timfruit微信平台 30 开始递增哈另外尽量不要出现 12然后 11有序嘿嘿
/** /**
* 微信公众平台 - H5 * 微信公众平台 - H5
*/ */

View File

@ -15,6 +15,7 @@ import java.util.List;
* *
* @author 芋道源码 * @author 芋道源码
*/ */
// TODO @timfruitSysSocialCoreService 改名方便区分
public interface SysSocialService { public interface SysSocialService {
/** /**
@ -77,5 +78,6 @@ public interface SysSocialService {
* @param unionId 社交平台的 unionId * @param unionId 社交平台的 unionId
*/ */
void unbindSocialUser(Long userId, Integer type, String unionId,UserTypeEnum userTypeEnum); void unbindSocialUser(Long userId, Integer type, String unionId,UserTypeEnum userTypeEnum);
// TODO @timfruit逗号后面要有空格缺少了 @userTypeEnum 的注释都补充下哈
} }

View File

@ -52,6 +52,7 @@
<aliyun-java-sdk-core.version>4.5.25</aliyun-java-sdk-core.version> <aliyun-java-sdk-core.version>4.5.25</aliyun-java-sdk-core.version>
<aliyun-java-sdk-dysmsapi.version>2.1.0</aliyun-java-sdk-dysmsapi.version> <aliyun-java-sdk-dysmsapi.version>2.1.0</aliyun-java-sdk-dysmsapi.version>
<yunpian-java-sdk.version>1.2.7</yunpian-java-sdk.version> <yunpian-java-sdk.version>1.2.7</yunpian-java-sdk.version>
<justauth.version>1.4.0</justauth.version>
</properties> </properties>
<dependencyManagement> <dependencyManagement>
@ -399,7 +400,6 @@
<artifactId>yunpian-java-sdk</artifactId> <artifactId>yunpian-java-sdk</artifactId>
<version>${yunpian-java-sdk.version}</version> <version>${yunpian-java-sdk.version}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.aliyun</groupId> <groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-core</artifactId> <artifactId>aliyun-java-sdk-core</artifactId>
@ -421,6 +421,13 @@
<version>${aliyun-java-sdk-dysmsapi.version}</version> <version>${aliyun-java-sdk-dysmsapi.version}</version>
</dependency> </dependency>
<!-- SMS SDK end --> <!-- SMS SDK end -->
<dependency>
<groupId>com.xkcoding.justauth</groupId>
<artifactId>justauth-spring-boot-starter</artifactId> <!-- 社交登陆(例如说,个人微信、企业微信等等) -->
<version>${justauth.version}</version>
</dependency>
</dependencies> </dependencies>
</dependencyManagement> </dependencyManagement>

View File

@ -3,7 +3,6 @@ package cn.iocoder.yudao.userserver.modules.system.controller.auth;
import cn.iocoder.yudao.coreservice.modules.system.service.social.SysSocialService; import cn.iocoder.yudao.coreservice.modules.system.service.social.SysSocialService;
import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;
import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
import cn.iocoder.yudao.userserver.modules.system.controller.auth.vo.*; import cn.iocoder.yudao.userserver.modules.system.controller.auth.vo.*;
import cn.iocoder.yudao.userserver.modules.system.service.auth.SysAuthService; import cn.iocoder.yudao.userserver.modules.system.service.auth.SysAuthService;
import cn.iocoder.yudao.userserver.modules.system.service.sms.SysSmsCodeService; import cn.iocoder.yudao.userserver.modules.system.service.sms.SysSmsCodeService;
@ -82,6 +81,7 @@ public class SysAuthController {
return CommonResult.success(socialService.getAuthorizeUrl(type, redirectUri)); return CommonResult.success(socialService.getAuthorizeUrl(type, redirectUri));
} }
// TODO @timfruit这个接口是要删除的么
@GetMapping("/social-login-get") @GetMapping("/social-login-get")
@ApiOperation("微信公众号授权回调地址输出social-login2的必要参数用于测试使用 code 授权码") @ApiOperation("微信公众号授权回调地址输出social-login2的必要参数用于测试使用 code 授权码")
@ResponseBody @ResponseBody

View File

@ -4,7 +4,6 @@ import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.lang.Assert; import cn.hutool.core.lang.Assert;
import cn.iocoder.yudao.coreservice.modules.member.dal.dataobject.user.MbrUserDO; import cn.iocoder.yudao.coreservice.modules.member.dal.dataobject.user.MbrUserDO;
import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.social.SysSocialUserDO; import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.social.SysSocialUserDO;
import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.user.SysUserDO;
import cn.iocoder.yudao.coreservice.modules.system.enums.logger.SysLoginLogTypeEnum; import cn.iocoder.yudao.coreservice.modules.system.enums.logger.SysLoginLogTypeEnum;
import cn.iocoder.yudao.coreservice.modules.system.enums.logger.SysLoginResultEnum; import cn.iocoder.yudao.coreservice.modules.system.enums.logger.SysLoginResultEnum;
import cn.iocoder.yudao.coreservice.modules.system.service.auth.SysUserSessionCoreService; import cn.iocoder.yudao.coreservice.modules.system.service.auth.SysUserSessionCoreService;
@ -37,7 +36,6 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
@ -130,8 +128,6 @@ public class SysAuthServiceImpl implements SysAuthService {
// 创建 LoginUser 对象 // 创建 LoginUser 对象
LoginUser loginUser = SysAuthConvert.INSTANCE.convert(user); LoginUser loginUser = SysAuthConvert.INSTANCE.convert(user);
// TODO 芋艿需要改造下增加各种登录方式
// loginUser.setRoleIds(this.getUserRoleIds(loginUser.getId())); // 获取用户角色列表
// 绑定社交用户更新 // 绑定社交用户更新
socialService.bindSocialUser(loginUser.getId(), reqVO.getType(), authUser, userTypeEnum); socialService.bindSocialUser(loginUser.getId(), reqVO.getType(), authUser, userTypeEnum);

View File

@ -142,7 +142,7 @@ yudao:
justauth: justauth:
enabled: true enabled: true
type: type: # TODO @timfruitGITEE、DINGTALK、WECHAT_ENTERPRISE 这个几个,对于用户端是不需要的哈,可以删除噢
GITEE: # Gitee GITEE: # Gitee
client-id: ee61f0374a4c6c404a8717094caa7a410d76950e45ff60348015830c519ba5c1 client-id: ee61f0374a4c6c404a8717094caa7a410d76950e45ff60348015830c519ba5c1
client-secret: 7c044a5671be3b051414db0cf2cec6ad702dd298d2416ba24ceaf608e6fa26f9 client-secret: 7c044a5671be3b051414db0cf2cec6ad702dd298d2416ba24ceaf608e6fa26f9