|
@@ -16,8 +16,8 @@ import com.citu.module.menduner.system.controller.app.auth.vo.enterprise.AppEnte
|
|
|
import com.citu.module.menduner.system.convert.MdeAuthConvert;
|
|
|
import com.citu.module.menduner.system.dal.dataobject.enterprise.EnterpriseUserBindDO;
|
|
|
import com.citu.module.menduner.system.dal.dataobject.user.MdeUserDO;
|
|
|
-import com.citu.module.menduner.system.dal.mysql.enterprise.EnterpriseUserBindMapper;
|
|
|
import com.citu.module.menduner.system.enums.MendunerStatusEnum;
|
|
|
+import com.citu.module.menduner.system.service.enterprise.bind.EnterpriseUserBindService;
|
|
|
import com.citu.module.menduner.system.service.user.MdeUserService;
|
|
|
import com.citu.module.system.api.logger.LoginLogApi;
|
|
|
import com.citu.module.system.api.logger.dto.LoginLogCreateReqDTO;
|
|
@@ -74,7 +74,7 @@ public class MdeEnterpriseAuthServiceImpl implements MdeEnterpriseAuthService {
|
|
|
@Resource
|
|
|
protected CaptchaService captchaService;
|
|
|
@Resource
|
|
|
- private EnterpriseUserBindMapper userBindMapper;
|
|
|
+ private EnterpriseUserBindService userBindService;
|
|
|
|
|
|
@VisibleForTesting
|
|
|
protected void validateCaptcha(AppMdeAuthLoginReqVO reqVO) {
|
|
@@ -101,7 +101,9 @@ public class MdeEnterpriseAuthServiceImpl implements MdeEnterpriseAuthService {
|
|
|
// 校验验证码
|
|
|
validateCaptcha(reqVO);
|
|
|
// 使用手机 + 密码,进行登录。
|
|
|
- MdeUserDO user = check(reqVO.getEnterpriseId(),reqVO.getPhone(), reqVO.getPassword());
|
|
|
+ MdeUserDO user = check(reqVO.getPhone(), reqVO.getPassword());
|
|
|
+ EnterpriseUserBindDO bindUser = check2(reqVO.getEnterpriseId(), user.getId(), reqVO.getPhone(),
|
|
|
+ LoginLogTypeEnum.LOGIN_MOBILE);
|
|
|
|
|
|
// 如果 socialType 非空,说明需要绑定社交用户
|
|
|
String openid = null;
|
|
@@ -111,7 +113,14 @@ public class MdeEnterpriseAuthServiceImpl implements MdeEnterpriseAuthService {
|
|
|
}
|
|
|
|
|
|
// 创建 Token 令牌,记录登录日志
|
|
|
- return createTokenAfterLoginSuccess(user, reqVO.getPhone(), LoginLogTypeEnum.LOGIN_MOBILE, openid, reqVO.getEnterpriseId());
|
|
|
+ return createTokenAfterLoginSuccess(
|
|
|
+ bindUser,
|
|
|
+ user,
|
|
|
+ reqVO.getPhone(),
|
|
|
+ LoginLogTypeEnum.LOGIN_MOBILE,
|
|
|
+ openid,
|
|
|
+ reqVO.getEnterpriseId()
|
|
|
+ );
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -124,6 +133,9 @@ public class MdeEnterpriseAuthServiceImpl implements MdeEnterpriseAuthService {
|
|
|
// 获得获得注册用户
|
|
|
MdeUserDO user = userService.createUserIfAbsent(reqVO.getPhone(), userIp, getTerminal().toString());
|
|
|
Assert.notNull(user, "获取用户失败,结果为空");
|
|
|
+ EnterpriseUserBindDO bindUser = check2(reqVO.getEnterpriseId(), user.getId(),
|
|
|
+ null, LoginLogTypeEnum.LOGIN_SMS);
|
|
|
+
|
|
|
|
|
|
// 如果 socialType 非空,说明需要绑定社交用户
|
|
|
String openid = null;
|
|
@@ -133,11 +145,12 @@ public class MdeEnterpriseAuthServiceImpl implements MdeEnterpriseAuthService {
|
|
|
}
|
|
|
|
|
|
// 创建 Token 令牌,记录登录日志
|
|
|
- return createTokenAfterLoginSuccess(user, reqVO.getPhone(), LoginLogTypeEnum.LOGIN_SMS, openid, reqVO.getEnterpriseId());
|
|
|
+ return createTokenAfterLoginSuccess(bindUser, user, reqVO.getPhone(),
|
|
|
+ LoginLogTypeEnum.LOGIN_SMS, openid, reqVO.getEnterpriseId());
|
|
|
}
|
|
|
|
|
|
|
|
|
- protected MdeUserDO check(Long enterpriseId, String mobile, String password) {
|
|
|
+ protected MdeUserDO check(String mobile, String password) {
|
|
|
final LoginLogTypeEnum logTypeEnum = LoginLogTypeEnum.LOGIN_MOBILE;
|
|
|
// 校验账号是否存在
|
|
|
MdeUserDO user = userService.getUserByPhone(mobile);
|
|
@@ -149,21 +162,29 @@ public class MdeEnterpriseAuthServiceImpl implements MdeEnterpriseAuthService {
|
|
|
createLoginLog(user.getId(), mobile, logTypeEnum, LoginResultEnum.BAD_CREDENTIALS);
|
|
|
throw exception(MDE_AUTH_LOGIN_BAD_CREDENTIALS);
|
|
|
}
|
|
|
+
|
|
|
+ return user;
|
|
|
+ }
|
|
|
+
|
|
|
+ protected EnterpriseUserBindDO check2(Long enterpriseId,
|
|
|
+ Long userId,
|
|
|
+ String mobile,
|
|
|
+ LoginLogTypeEnum logTypeEnum) {
|
|
|
// 查询绑定用户
|
|
|
- EnterpriseUserBindDO bind = userBindMapper.selectByEnterpriseIdAndUserId(
|
|
|
+ EnterpriseUserBindDO bind = userBindService.selectByEnterpriseIdAndUserId(
|
|
|
enterpriseId,
|
|
|
- user.getId()
|
|
|
+ userId
|
|
|
);
|
|
|
if (null == bind) {
|
|
|
- createLoginLog(user.getId(), mobile, logTypeEnum, LoginResultEnum.BAD_CREDENTIALS);
|
|
|
+ createLoginLog(bind.getId(), mobile, logTypeEnum, LoginResultEnum.BAD_CREDENTIALS);
|
|
|
throw exception(MDE_USER_ENTERPRISE_NOT_USER_NULL);
|
|
|
}
|
|
|
// 校验是否禁用
|
|
|
if (ObjectUtil.notEqual(bind.getStatus(), MendunerStatusEnum.ENABLE.getStatus())) {
|
|
|
- createLoginLog(user.getId(), mobile, logTypeEnum, LoginResultEnum.USER_DISABLED);
|
|
|
+ createLoginLog(bind.getId(), mobile, logTypeEnum, LoginResultEnum.USER_DISABLED);
|
|
|
throw exception(MDE_AUTH_LOGIN_USER_DISABLED);
|
|
|
}
|
|
|
- return user;
|
|
|
+ return bind;
|
|
|
}
|
|
|
|
|
|
|
|
@@ -172,9 +193,13 @@ public class MdeEnterpriseAuthServiceImpl implements MdeEnterpriseAuthService {
|
|
|
}
|
|
|
|
|
|
|
|
|
- protected AppMdeAuthLoginRespVO createTokenAfterLoginSuccess(MdeUserDO user, String phone, LoginLogTypeEnum logType, String openid, Long enterpriseId) {
|
|
|
+ protected AppMdeAuthLoginRespVO createTokenAfterLoginSuccess(EnterpriseUserBindDO bindUser,
|
|
|
+ MdeUserDO user,
|
|
|
+ String phone,
|
|
|
+ LoginLogTypeEnum logType,
|
|
|
+ String openid, Long enterpriseId) {
|
|
|
// 插入登陆日志
|
|
|
- createLoginLog(user.getId(), phone, logType, LoginResultEnum.SUCCESS);
|
|
|
+ createLoginLog(bindUser.getId(), phone, logType, LoginResultEnum.SUCCESS);
|
|
|
// 创建 Token 令牌
|
|
|
OAuth2AccessTokenRespDTO accessTokenRespDTO = oauth2TokenApi.createAccessToken(new OAuth2AccessTokenCreateReqDTO()
|
|
|
.setUserId(user.getId()).setUserType(getUserType().getValue())
|
|
@@ -185,12 +210,12 @@ public class MdeEnterpriseAuthServiceImpl implements MdeEnterpriseAuthService {
|
|
|
return MdeAuthConvert.INSTANCE.convert(accessTokenRespDTO, openid);
|
|
|
}
|
|
|
|
|
|
- protected void createLoginLog(Long userId, String mobile, LoginLogTypeEnum logType, LoginResultEnum loginResult) {
|
|
|
+ protected void createLoginLog(Long bindUserId, String mobile, LoginLogTypeEnum logType, LoginResultEnum loginResult) {
|
|
|
// 插入登录日志
|
|
|
LoginLogCreateReqDTO reqDTO = new LoginLogCreateReqDTO();
|
|
|
reqDTO.setLogType(logType.getType());
|
|
|
reqDTO.setTraceId(TracerUtils.getTraceId());
|
|
|
- reqDTO.setUserId(userId);
|
|
|
+ reqDTO.setUserId(bindUserId);
|
|
|
reqDTO.setUserType(getUserType().getValue());
|
|
|
reqDTO.setUsername(mobile);
|
|
|
reqDTO.setUserAgent(ServletUtils.getUserAgent());
|
|
@@ -198,8 +223,8 @@ public class MdeEnterpriseAuthServiceImpl implements MdeEnterpriseAuthService {
|
|
|
reqDTO.setResult(loginResult.getResult());
|
|
|
loginLogApi.createLoginLog(reqDTO);
|
|
|
// 更新最后登录时间
|
|
|
- if (userId != null && Objects.equals(LoginResultEnum.SUCCESS.getResult(), loginResult.getResult())) {
|
|
|
- userService.updateUserLogin(userId, getClientIP());
|
|
|
+ if (bindUserId != null && Objects.equals(LoginResultEnum.SUCCESS.getResult(), loginResult.getResult())) {
|
|
|
+ userBindService.updateUserLogin(bindUserId, getClientIP());
|
|
|
}
|
|
|
}
|
|
|
}
|