code review 用户前台的社交登陆
This commit is contained in:
parent
30ad7c43b8
commit
55e5ca4644
@ -75,6 +75,7 @@ public class SysAuthServiceImpl implements SysAuthService {
|
||||
@Resource
|
||||
private SysSocialService socialService;
|
||||
|
||||
// TODO @timfruit:静态枚举类,需要都大写,例如说 USER_TYPE_ENUM;静态变量,放在普通变量前面;这个实践不错哈。
|
||||
private static final UserTypeEnum userTypeEnum = UserTypeEnum.ADMIN;
|
||||
|
||||
@Override
|
||||
@ -214,7 +215,6 @@ public class SysAuthServiceImpl implements SysAuthService {
|
||||
|
||||
// 创建 LoginUser 对象
|
||||
LoginUser loginUser = SysAuthConvert.INSTANCE.convert(user);
|
||||
// TODO 芋艿:需要改造下,增加各种登录方式
|
||||
loginUser.setRoleIds(this.getUserRoleIds(loginUser.getId())); // 获取用户角色列表
|
||||
|
||||
// 绑定社交用户(更新)
|
||||
|
@ -86,11 +86,12 @@
|
||||
<artifactId>guava</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- 三方云服务相关 -->
|
||||
<dependency>
|
||||
<groupId>com.xkcoding.justauth</groupId>
|
||||
<artifactId>justauth-spring-boot-starter</artifactId>
|
||||
<version>1.4.0</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
@ -8,6 +8,7 @@ import org.apache.ibatis.annotations.Mapper;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
// TODO @timfruit:SysSocialUserCoreMapper 改名,方便区分
|
||||
@Mapper
|
||||
public interface SysSocialUserMapper extends BaseMapperX<SysSocialUserDO> {
|
||||
|
||||
|
@ -19,11 +19,11 @@ public interface SysRedisKeyCoreConstants {
|
||||
"login_user:%s", // 参数为 sessionId
|
||||
STRING, LoginUser.class, RedisKeyDefine.TimeoutTypeEnum.DYNAMIC);
|
||||
|
||||
RedisKeyDefine SOCIAL_AUTH_USER = new RedisKeyDefine("社交的授权用户",
|
||||
RedisKeyDefine SOCIAL_AUTH_USER = new RedisKeyDefine("社交登陆的授权用户",
|
||||
"social_auth_user:%d:%s", // 参数为 type,code
|
||||
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
|
||||
STRING, String.class, Duration.ofHours(24)); // 值为 state
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ import javax.annotation.Resource;
|
||||
|
||||
import static cn.iocoder.yudao.coreservice.modules.system.dal.redis.SysRedisKeyCoreConstants.SOCIAL_AUTH_USER;
|
||||
|
||||
|
||||
// TODO @timfruit,这里的 AuthUser 还是保留全路径,主要想体现出来,不是自己定义的
|
||||
/**
|
||||
* 社交 {@link AuthUser} 的 RedisDAO
|
||||
*
|
||||
|
@ -21,6 +21,7 @@ public enum SysSocialTypeEnum implements IntArrayValuable {
|
||||
GITEE(10, "GITEE"), // https://gitee.com/api/v5/oauth_doc#/
|
||||
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
|
||||
// TODO @timfruit:微信平台,从 30 开始递增哈。另外,尽量不要出现,先 12,然后 11,有序,嘿嘿。
|
||||
/**
|
||||
* 微信公众平台 - H5
|
||||
*/
|
||||
|
@ -15,6 +15,7 @@ import java.util.List;
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
// TODO @timfruit:SysSocialCoreService 改名,方便区分
|
||||
public interface SysSocialService {
|
||||
|
||||
/**
|
||||
@ -77,5 +78,6 @@ public interface SysSocialService {
|
||||
* @param unionId 社交平台的 unionId
|
||||
*/
|
||||
void unbindSocialUser(Long userId, Integer type, String unionId,UserTypeEnum userTypeEnum);
|
||||
// TODO @timfruit:逗号后面要有空格;缺少了 @userTypeEnum 的注释,都补充下哈。
|
||||
|
||||
}
|
||||
|
@ -52,6 +52,7 @@
|
||||
<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>
|
||||
<yunpian-java-sdk.version>1.2.7</yunpian-java-sdk.version>
|
||||
<justauth.version>1.4.0</justauth.version>
|
||||
</properties>
|
||||
|
||||
<dependencyManagement>
|
||||
@ -399,7 +400,6 @@
|
||||
<artifactId>yunpian-java-sdk</artifactId>
|
||||
<version>${yunpian-java-sdk.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.aliyun</groupId>
|
||||
<artifactId>aliyun-java-sdk-core</artifactId>
|
||||
@ -421,6 +421,13 @@
|
||||
<version>${aliyun-java-sdk-dysmsapi.version}</version>
|
||||
</dependency>
|
||||
<!-- SMS SDK end -->
|
||||
|
||||
<dependency>
|
||||
<groupId>com.xkcoding.justauth</groupId>
|
||||
<artifactId>justauth-spring-boot-starter</artifactId> <!-- 社交登陆(例如说,个人微信、企业微信等等) -->
|
||||
<version>${justauth.version}</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
|
@ -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.framework.common.enums.UserTypeEnum;
|
||||
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.service.auth.SysAuthService;
|
||||
import cn.iocoder.yudao.userserver.modules.system.service.sms.SysSmsCodeService;
|
||||
@ -82,6 +81,7 @@ public class SysAuthController {
|
||||
return CommonResult.success(socialService.getAuthorizeUrl(type, redirectUri));
|
||||
}
|
||||
|
||||
// TODO @timfruit:这个接口,是要删除的么?
|
||||
@GetMapping("/social-login-get")
|
||||
@ApiOperation("微信公众号授权回调地址,输出social-login2的必要参数用于测试,使用 code 授权码")
|
||||
@ResponseBody
|
||||
|
@ -4,7 +4,6 @@ import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.lang.Assert;
|
||||
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.user.SysUserDO;
|
||||
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.service.auth.SysUserSessionCoreService;
|
||||
@ -37,7 +36,6 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.validation.Valid;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
@ -130,8 +128,6 @@ public class SysAuthServiceImpl implements SysAuthService {
|
||||
|
||||
// 创建 LoginUser 对象
|
||||
LoginUser loginUser = SysAuthConvert.INSTANCE.convert(user);
|
||||
// TODO 芋艿:需要改造下,增加各种登录方式
|
||||
// loginUser.setRoleIds(this.getUserRoleIds(loginUser.getId())); // 获取用户角色列表
|
||||
|
||||
// 绑定社交用户(更新)
|
||||
socialService.bindSocialUser(loginUser.getId(), reqVO.getType(), authUser, userTypeEnum);
|
||||
|
@ -142,7 +142,7 @@ yudao:
|
||||
|
||||
justauth:
|
||||
enabled: true
|
||||
type:
|
||||
type: # TODO @timfruit:GITEE、DINGTALK、WECHAT_ENTERPRISE 这个几个,对于用户端是不需要的哈,可以删除噢
|
||||
GITEE: # Gitee
|
||||
client-id: ee61f0374a4c6c404a8717094caa7a410d76950e45ff60348015830c519ba5c1
|
||||
client-secret: 7c044a5671be3b051414db0cf2cec6ad702dd298d2416ba24ceaf608e6fa26f9
|
||||
|
Loading…
Reference in New Issue
Block a user