重构社交登录的时候,增加独立的社交绑定表
parent
6e40469735
commit
705a5ff645
@ -0,0 +1,45 @@
|
|||||||
|
package cn.iocoder.yudao.module.system.dal.dataobject.social;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;
|
||||||
|
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
||||||
|
import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import lombok.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 社交用户的绑定
|
||||||
|
* 即 {@link SocialUserDO} 与 UserDO 的关联表
|
||||||
|
*
|
||||||
|
* @author 芋道源码
|
||||||
|
*/
|
||||||
|
@TableName(value = "system_social_user_bind", autoResultMap = true)
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class SocialUserBindDO extends BaseDO {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 关联的用户编号
|
||||||
|
*/
|
||||||
|
private Long userId;
|
||||||
|
/**
|
||||||
|
* 用户类型
|
||||||
|
*
|
||||||
|
* 枚举 {@link UserTypeEnum}
|
||||||
|
*/
|
||||||
|
private Integer userType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 社交平台
|
||||||
|
*
|
||||||
|
* 枚举 {@link SocialTypeEnum#getPlatform()}
|
||||||
|
*/
|
||||||
|
private Integer platform;
|
||||||
|
/**
|
||||||
|
* 社交的全局编号
|
||||||
|
*/
|
||||||
|
private String unionId;
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,28 @@
|
|||||||
|
package cn.iocoder.yudao.module.system.dal.mysql.social;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||||
|
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||||
|
import cn.iocoder.yudao.module.system.dal.dataobject.social.SocialUserBindDO;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface SocialUserBindMapper extends BaseMapperX<SocialUserBindDO> {
|
||||||
|
|
||||||
|
default void deleteByUserTypeAndUserIdAndPlatformAndUnionId(Integer userType, Long userId,
|
||||||
|
Integer platform, String unionId) {
|
||||||
|
delete(new LambdaQueryWrapperX<SocialUserBindDO>()
|
||||||
|
.eq(SocialUserBindDO::getUserType, userType)
|
||||||
|
.eq(SocialUserBindDO::getUserId, userId)
|
||||||
|
.eq(SocialUserBindDO::getPlatform, platform)
|
||||||
|
.eq(SocialUserBindDO::getUnionId, unionId));
|
||||||
|
}
|
||||||
|
|
||||||
|
default SocialUserBindDO selectByUserTypeAndPlatformAndUnionId(Integer userType,
|
||||||
|
Integer platform, String unionId) {
|
||||||
|
return selectOne(new LambdaQueryWrapperX<SocialUserBindDO>()
|
||||||
|
.eq(SocialUserBindDO::getUserType, userType)
|
||||||
|
.eq(SocialUserBindDO::getPlatform, platform)
|
||||||
|
.eq(SocialUserBindDO::getUnionId, unionId));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -1,39 +0,0 @@
|
|||||||
package cn.iocoder.yudao.module.system.dal.redis.social;
|
|
||||||
|
|
||||||
import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
|
|
||||||
import me.zhyd.oauth.model.AuthCallback;
|
|
||||||
import me.zhyd.oauth.model.AuthUser;
|
|
||||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
|
||||||
import org.springframework.stereotype.Repository;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
|
|
||||||
import static cn.iocoder.yudao.module.system.dal.redis.RedisKeyConstants.SOCIAL_AUTH_USER;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 社交 {@link me.zhyd.oauth.model.AuthUser} 的 RedisDAO
|
|
||||||
*
|
|
||||||
* @author 芋道源码
|
|
||||||
*/
|
|
||||||
@Repository
|
|
||||||
public class SocialAuthUserRedisDAO {
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
private StringRedisTemplate stringRedisTemplate;
|
|
||||||
|
|
||||||
public AuthUser get(Integer type, AuthCallback authCallback) {
|
|
||||||
String redisKey = formatKey(type, authCallback.getCode());
|
|
||||||
return JsonUtils.parseObject(stringRedisTemplate.opsForValue().get(redisKey), AuthUser.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void set(Integer type, AuthCallback authCallback, AuthUser authUser) {
|
|
||||||
String redisKey = formatKey(type, authCallback.getCode());
|
|
||||||
stringRedisTemplate.opsForValue().set(redisKey, JsonUtils.toJsonString(authUser), SOCIAL_AUTH_USER.getTimeout());
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String formatKey(Integer type, String code) {
|
|
||||||
return String.format(SOCIAL_AUTH_USER.getKeyTemplate(), type, code);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue