|
@@ -2,7 +2,7 @@ package com.citu.module.menduner.system.service.auth;
|
|
|
|
|
|
import cn.hutool.core.lang.Assert;
|
|
import cn.hutool.core.lang.Assert;
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
-import com.citu.module.menduner.system.enums.MendunerStatusEnum;
|
|
|
|
|
|
+import com.baomidou.dynamic.datasource.annotation.DSTransactional;
|
|
import com.citu.framework.common.enums.TerminalEnum;
|
|
import com.citu.framework.common.enums.TerminalEnum;
|
|
import com.citu.framework.common.enums.UserTypeEnum;
|
|
import com.citu.framework.common.enums.UserTypeEnum;
|
|
import com.citu.framework.common.util.monitor.TracerUtils;
|
|
import com.citu.framework.common.util.monitor.TracerUtils;
|
|
@@ -11,6 +11,7 @@ import com.citu.framework.common.util.validation.ValidationUtils;
|
|
import com.citu.module.menduner.system.controller.app.auth.vo.*;
|
|
import com.citu.module.menduner.system.controller.app.auth.vo.*;
|
|
import com.citu.module.menduner.system.convert.MdeAuthConvert;
|
|
import com.citu.module.menduner.system.convert.MdeAuthConvert;
|
|
import com.citu.module.menduner.system.dal.dataobject.user.MdeUserDO;
|
|
import com.citu.module.menduner.system.dal.dataobject.user.MdeUserDO;
|
|
|
|
+import com.citu.module.menduner.system.enums.MendunerStatusEnum;
|
|
import com.citu.module.menduner.system.service.user.MdeUserService;
|
|
import com.citu.module.menduner.system.service.user.MdeUserService;
|
|
import com.citu.module.system.api.logger.LoginLogApi;
|
|
import com.citu.module.system.api.logger.LoginLogApi;
|
|
import com.citu.module.system.api.logger.dto.LoginLogCreateReqDTO;
|
|
import com.citu.module.system.api.logger.dto.LoginLogCreateReqDTO;
|
|
@@ -34,7 +35,6 @@ import com.xingyuv.captcha.service.CaptchaService;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
-import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
import javax.validation.Validator;
|
|
import javax.validation.Validator;
|
|
@@ -55,31 +55,31 @@ import static com.citu.module.menduner.system.enums.ErrorCodeConstants.*;
|
|
public class MdeAuthServiceImpl implements MdeAuthService {
|
|
public class MdeAuthServiceImpl implements MdeAuthService {
|
|
|
|
|
|
@Resource
|
|
@Resource
|
|
- private MdeUserService userService;
|
|
|
|
|
|
+ protected MdeUserService userService;
|
|
@Resource
|
|
@Resource
|
|
- private SmsCodeApi smsCodeApi;
|
|
|
|
|
|
+ protected SmsCodeApi smsCodeApi;
|
|
@Resource
|
|
@Resource
|
|
- private LoginLogApi loginLogApi;
|
|
|
|
|
|
+ protected LoginLogApi loginLogApi;
|
|
@Resource
|
|
@Resource
|
|
- private SocialUserApi socialUserApi;
|
|
|
|
|
|
+ protected SocialUserApi socialUserApi;
|
|
@Resource
|
|
@Resource
|
|
- private SocialClientApi socialClientApi;
|
|
|
|
|
|
+ protected SocialClientApi socialClientApi;
|
|
@Resource
|
|
@Resource
|
|
- private OAuth2TokenApi oauth2TokenApi;
|
|
|
|
|
|
+ protected OAuth2TokenApi oauth2TokenApi;
|
|
|
|
|
|
/**
|
|
/**
|
|
* 验证码的开关,默认为 true
|
|
* 验证码的开关,默认为 true
|
|
*/
|
|
*/
|
|
@Value("${citu.captcha.enable:true}")
|
|
@Value("${citu.captcha.enable:true}")
|
|
- private Boolean captchaEnable;
|
|
|
|
|
|
+ protected Boolean captchaEnable;
|
|
@Resource
|
|
@Resource
|
|
- private Validator validator;
|
|
|
|
|
|
+ protected Validator validator;
|
|
|
|
|
|
@Resource
|
|
@Resource
|
|
- private CaptchaService captchaService;
|
|
|
|
|
|
+ protected CaptchaService captchaService;
|
|
|
|
|
|
@VisibleForTesting
|
|
@VisibleForTesting
|
|
- void validateCaptcha(AppMdeAuthLoginReqVO reqVO) {
|
|
|
|
|
|
+ protected void validateCaptcha(AppMdeAuthLoginReqVO reqVO) {
|
|
// 如果验证码关闭,则不进行校验
|
|
// 如果验证码关闭,则不进行校验
|
|
if (!captchaEnable) {
|
|
if (!captchaEnable) {
|
|
return;
|
|
return;
|
|
@@ -115,7 +115,7 @@ public class MdeAuthServiceImpl implements MdeAuthService {
|
|
return createTokenAfterLoginSuccess(user, reqVO.getPhone(), LoginLogTypeEnum.LOGIN_MOBILE, openid);
|
|
return createTokenAfterLoginSuccess(user, reqVO.getPhone(), LoginLogTypeEnum.LOGIN_MOBILE, openid);
|
|
}
|
|
}
|
|
|
|
|
|
- private MdeUserDO check(String mobile, String password) {
|
|
|
|
|
|
+ protected MdeUserDO check(String mobile, String password) {
|
|
final LoginLogTypeEnum logTypeEnum = LoginLogTypeEnum.LOGIN_MOBILE;
|
|
final LoginLogTypeEnum logTypeEnum = LoginLogTypeEnum.LOGIN_MOBILE;
|
|
// 校验账号是否存在
|
|
// 校验账号是否存在
|
|
MdeUserDO user = userService.getUserByPhone(mobile);
|
|
MdeUserDO user = userService.getUserByPhone(mobile);
|
|
@@ -160,7 +160,7 @@ public class MdeAuthServiceImpl implements MdeAuthService {
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- @Transactional
|
|
|
|
|
|
+ @DSTransactional
|
|
public AppMdeAuthLoginRespVO smsLogin(AppMdeAuthSmsLoginReqVO reqVO) {
|
|
public AppMdeAuthLoginRespVO smsLogin(AppMdeAuthSmsLoginReqVO reqVO) {
|
|
// 校验验证码
|
|
// 校验验证码
|
|
String userIp = getClientIP();
|
|
String userIp = getClientIP();
|
|
@@ -182,7 +182,7 @@ public class MdeAuthServiceImpl implements MdeAuthService {
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- @Transactional
|
|
|
|
|
|
+ @DSTransactional
|
|
public AppMdeAuthLoginRespVO socialLogin(AppMdeAuthSocialLoginReqVO reqVO) {
|
|
public AppMdeAuthLoginRespVO socialLogin(AppMdeAuthSocialLoginReqVO reqVO) {
|
|
// 使用 code 授权码,进行登录。然后,获得到绑定的用户编号
|
|
// 使用 code 授权码,进行登录。然后,获得到绑定的用户编号
|
|
SocialUserRespDTO socialUser = socialUserApi.getSocialUserByCode(UserTypeEnum.MEMBER.getValue(), reqVO.getType(),
|
|
SocialUserRespDTO socialUser = socialUserApi.getSocialUserByCode(UserTypeEnum.MEMBER.getValue(), reqVO.getType(),
|
|
@@ -210,7 +210,7 @@ public class MdeAuthServiceImpl implements MdeAuthService {
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- @Transactional
|
|
|
|
|
|
+ @DSTransactional
|
|
public AppMdeAuthLoginRespVO weixinMiniAppLogin(AppMdeAuthWeixinMiniAppLoginReqVO reqVO) {
|
|
public AppMdeAuthLoginRespVO weixinMiniAppLogin(AppMdeAuthWeixinMiniAppLoginReqVO reqVO) {
|
|
// 获得对应的手机号信息
|
|
// 获得对应的手机号信息
|
|
SocialWxPhoneNumberInfoRespDTO phoneNumberInfo = socialClientApi.getWxMaPhoneNumberInfo(
|
|
SocialWxPhoneNumberInfoRespDTO phoneNumberInfo = socialClientApi.getWxMaPhoneNumberInfo(
|
|
@@ -274,7 +274,7 @@ public class MdeAuthServiceImpl implements MdeAuthService {
|
|
return MdeAuthConvert.INSTANCE.convert(accessTokenDO, null);
|
|
return MdeAuthConvert.INSTANCE.convert(accessTokenDO, null);
|
|
}
|
|
}
|
|
|
|
|
|
- private String getPhone(Long userId) {
|
|
|
|
|
|
+ protected String getPhone(Long userId) {
|
|
if (userId == null) {
|
|
if (userId == null) {
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
@@ -282,7 +282,7 @@ public class MdeAuthServiceImpl implements MdeAuthService {
|
|
return user != null ? user.getPhone() : null;
|
|
return user != null ? user.getPhone() : null;
|
|
}
|
|
}
|
|
|
|
|
|
- private void createLoginLog(Long userId, String mobile, LoginLogTypeEnum logType, LoginResultEnum loginResult) {
|
|
|
|
|
|
+ protected void createLoginLog(Long userId, String mobile, LoginLogTypeEnum logType, LoginResultEnum loginResult) {
|
|
// 插入登录日志
|
|
// 插入登录日志
|
|
LoginLogCreateReqDTO reqDTO = new LoginLogCreateReqDTO();
|
|
LoginLogCreateReqDTO reqDTO = new LoginLogCreateReqDTO();
|
|
reqDTO.setLogType(logType.getType());
|
|
reqDTO.setLogType(logType.getType());
|
|
@@ -300,12 +300,12 @@ public class MdeAuthServiceImpl implements MdeAuthService {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- private UserTypeEnum getUserType() {
|
|
|
|
|
|
+ protected UserTypeEnum getUserType() {
|
|
return UserTypeEnum.MEMBER;
|
|
return UserTypeEnum.MEMBER;
|
|
}
|
|
}
|
|
|
|
|
|
- private AppMdeAuthLoginRespVO createTokenAfterLoginSuccess(MdeUserDO user, String phone,
|
|
|
|
- LoginLogTypeEnum logType, String openid) {
|
|
|
|
|
|
+ protected AppMdeAuthLoginRespVO createTokenAfterLoginSuccess(MdeUserDO user, String phone,
|
|
|
|
+ LoginLogTypeEnum logType, String openid) {
|
|
// 插入登陆日志
|
|
// 插入登陆日志
|
|
createLoginLog(user.getId(), phone, logType, LoginResultEnum.SUCCESS);
|
|
createLoginLog(user.getId(), phone, logType, LoginResultEnum.SUCCESS);
|
|
// 创建 Token 令牌
|
|
// 创建 Token 令牌
|