mirror of
				https://gitee.com/hhyykk/ipms-sjy.git
				synced 2025-11-04 20:28:44 +08:00 
			
		
		
		
	✨ Member:修复社交登录时,自动创建 user 后,未进行绑定的问题
This commit is contained in:
		@@ -100,21 +100,27 @@ public class MemberAuthServiceImpl implements MemberAuthService {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    @Transactional
 | 
			
		||||
    public AppAuthLoginRespVO socialLogin(AppAuthSocialLoginReqVO reqVO) {
 | 
			
		||||
        // 使用 code 授权码,进行登录。然后,获得到绑定的用户编号
 | 
			
		||||
        SocialUserRespDTO socialUser = socialUserApi.getSocialUser(UserTypeEnum.MEMBER.getValue(), reqVO.getType(),
 | 
			
		||||
                reqVO.getCode(), reqVO.getState());
 | 
			
		||||
        if (socialUser == null) {
 | 
			
		||||
            throw exception(AUTH_THIRD_LOGIN_NOT_BIND);
 | 
			
		||||
            throw exception(AUTH_SOCIAL_USER_NOT_FOUND);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // 情况一:已绑定,自动登录
 | 
			
		||||
        MemberUserDO user = userService.getUser(socialUser.getUserId());
 | 
			
		||||
        // 情况一:已绑定,直接读取用户信息
 | 
			
		||||
        MemberUserDO user;
 | 
			
		||||
        if (socialUser.getUserId() != null) {
 | 
			
		||||
            user = userService.getUser(socialUser.getUserId());
 | 
			
		||||
        // 情况二:未绑定,注册用户 + 绑定用户
 | 
			
		||||
        } else {
 | 
			
		||||
            user = userService.createUser(socialUser.getNickname(), socialUser.getAvatar(), getClientIP(), getTerminal());
 | 
			
		||||
            socialUserApi.bindSocialUser(new SocialUserBindReqDTO(user.getId(), getUserType().getValue(),
 | 
			
		||||
                    reqVO.getType(), reqVO.getCode(), reqVO.getState()));
 | 
			
		||||
        }
 | 
			
		||||
        if (user == null) {
 | 
			
		||||
            throw exception(USER_NOT_EXISTS);
 | 
			
		||||
        // 情况二:未绑定,注册登录
 | 
			
		||||
        } else {
 | 
			
		||||
            user = userService.createUser(user.getNickname(), user.getAvatar(), getClientIP(), getTerminal());
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // 创建 Token 令牌,记录登录日志
 | 
			
		||||
 
 | 
			
		||||
@@ -2,9 +2,7 @@ package cn.iocoder.yudao.module.member.service.user;
 | 
			
		||||
 | 
			
		||||
import cn.hutool.core.collection.CollUtil;
 | 
			
		||||
import cn.hutool.core.collection.ListUtil;
 | 
			
		||||
import cn.hutool.core.util.IdUtil;
 | 
			
		||||
import cn.hutool.core.util.ObjectUtil;
 | 
			
		||||
import cn.hutool.core.util.StrUtil;
 | 
			
		||||
import cn.hutool.core.util.*;
 | 
			
		||||
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
 | 
			
		||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
 | 
			
		||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
 | 
			
		||||
@@ -101,6 +99,10 @@ public class MemberUserServiceImpl implements MemberUserService {
 | 
			
		||||
        user.setPassword(encodePassword(password)); // 加密密码
 | 
			
		||||
        user.setRegisterIp(registerIp).setRegisterTerminal(terminal);
 | 
			
		||||
        user.setNickname(nickname).setAvatar(avtar); // 基础信息
 | 
			
		||||
        if (StrUtil.isEmpty(nickname)) {
 | 
			
		||||
            // 昵称为空时,随机一个名字,避免一些依赖 nickname 的逻辑报错,或者有点丑。例如说,短信发送有昵称时~
 | 
			
		||||
            user.setNickname("用户" + RandomUtil.randomNumbers(6));
 | 
			
		||||
        }
 | 
			
		||||
        memberUserMapper.insert(user);
 | 
			
		||||
 | 
			
		||||
        // 发送 MQ 消息:用户创建
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user