|
@@ -18,6 +18,7 @@ import cn.iocoder.yudao.module.system.api.logger.LoginLogApi;
|
|
|
import cn.iocoder.yudao.module.system.api.logger.dto.LoginLogCreateReqDTO;
|
|
|
import cn.iocoder.yudao.module.system.api.sms.SmsCodeApi;
|
|
|
import cn.iocoder.yudao.module.system.api.social.SocialUserApi;
|
|
|
+import cn.iocoder.yudao.module.system.api.social.dto.SocialUserBindReqDTO;
|
|
|
import cn.iocoder.yudao.module.system.enums.auth.OAuth2ClientConstants;
|
|
|
import cn.iocoder.yudao.module.system.enums.logger.LoginLogTypeEnum;
|
|
|
import cn.iocoder.yudao.module.system.enums.logger.LoginResultEnum;
|
|
@@ -65,6 +66,12 @@ public class MemberAuthServiceImpl implements MemberAuthService {
|
|
|
// 使用手机 + 密码,进行登录。
|
|
|
MemberUserDO user = login0(reqVO.getMobile(), reqVO.getPassword());
|
|
|
|
|
|
+ // 如果 socialType 非空,说明需要绑定社交用户
|
|
|
+ if (reqVO.getSocialType() != null) {
|
|
|
+ socialUserApi.bindSocialUser(new SocialUserBindReqDTO(user.getId(), getUserType().getValue(),
|
|
|
+ reqVO.getSocialType(), reqVO.getSocialCode(), reqVO.getSocialState()));
|
|
|
+ }
|
|
|
+
|
|
|
// 创建 Token 令牌,记录登录日志
|
|
|
return createTokenAfterLoginSuccess(user, reqVO.getMobile(), LoginLogTypeEnum.LOGIN_MOBILE);
|
|
|
}
|
|
@@ -80,12 +87,18 @@ public class MemberAuthServiceImpl implements MemberAuthService {
|
|
|
MemberUserDO user = userService.createUserIfAbsent(reqVO.getMobile(), userIp);
|
|
|
Assert.notNull(user, "获取用户失败,结果为空");
|
|
|
|
|
|
+ // 如果 socialType 非空,说明需要绑定社交用户
|
|
|
+ if (reqVO.getSocialType() != null) {
|
|
|
+ socialUserApi.bindSocialUser(new SocialUserBindReqDTO(user.getId(), getUserType().getValue(),
|
|
|
+ reqVO.getSocialType(), reqVO.getSocialCode(), reqVO.getSocialState()));
|
|
|
+ }
|
|
|
+
|
|
|
// 创建 Token 令牌,记录登录日志
|
|
|
return createTokenAfterLoginSuccess(user, reqVO.getMobile(), LoginLogTypeEnum.LOGIN_SMS);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public AppAuthLoginRespVO socialQuickLogin(AppAuthSocialQuickLoginReqVO reqVO) {
|
|
|
+ public AppAuthLoginRespVO socialLogin(AppAuthSocialLoginReqVO reqVO) {
|
|
|
// 使用 code 授权码,进行登录。然后,获得到绑定的用户编号
|
|
|
Long userId = socialUserApi.getBindUserId(UserTypeEnum.MEMBER.getValue(), reqVO.getType(),
|
|
|
reqVO.getCode(), reqVO.getState());
|
|
@@ -103,18 +116,6 @@ public class MemberAuthServiceImpl implements MemberAuthService {
|
|
|
return createTokenAfterLoginSuccess(user, user.getMobile(), LoginLogTypeEnum.LOGIN_SOCIAL);
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public AppAuthLoginRespVO socialBindLogin(AppAuthSocialBindLoginReqVO reqVO) {
|
|
|
- // 使用手机号、手机验证码登录
|
|
|
- AppAuthSmsLoginReqVO loginReqVO = AppAuthSmsLoginReqVO.builder()
|
|
|
- .mobile(reqVO.getMobile()).code(reqVO.getSmsCode()).build();
|
|
|
- AppAuthLoginRespVO token = smsLogin(loginReqVO);
|
|
|
-
|
|
|
- // 绑定社交用户
|
|
|
- socialUserApi.bindSocialUser(AuthConvert.INSTANCE.convert(token.getUserId(), getUserType().getValue(), reqVO));
|
|
|
- return token;
|
|
|
- }
|
|
|
-
|
|
|
private AppAuthLoginRespVO createTokenAfterLoginSuccess(MemberUserDO user, String mobile, LoginLogTypeEnum logType) {
|
|
|
// 插入登陆日志
|
|
|
createLoginLog(user.getId(), mobile, logType, LoginResultEnum.SUCCESS);
|