|
@@ -1,12 +1,14 @@
|
|
|
package com.citu.module.menduner.system.service.auth;
|
|
|
|
|
|
import cn.hutool.core.lang.Assert;
|
|
|
+import cn.hutool.core.map.MapUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import com.baomidou.dynamic.datasource.annotation.DSTransactional;
|
|
|
import com.citu.framework.common.enums.UserTypeEnum;
|
|
|
import com.citu.framework.common.util.monitor.TracerUtils;
|
|
|
import com.citu.framework.common.util.servlet.ServletUtils;
|
|
|
import com.citu.framework.common.util.validation.ValidationUtils;
|
|
|
+import com.citu.framework.security.core.LoginUser;
|
|
|
import com.citu.module.menduner.system.controller.app.auth.vo.AppMdeAuthLoginReqVO;
|
|
|
import com.citu.module.menduner.system.controller.app.auth.vo.AppMdeAuthLoginRespVO;
|
|
|
import com.citu.module.menduner.system.controller.app.auth.vo.enterprise.AppEnterpriseAuthLoginReqVO;
|
|
@@ -14,16 +16,14 @@ 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;
|
|
|
import com.citu.module.system.api.oauth2.OAuth2TokenApi;
|
|
|
import com.citu.module.system.api.oauth2.dto.OAuth2AccessTokenCreateReqDTO;
|
|
|
import com.citu.module.system.api.oauth2.dto.OAuth2AccessTokenRespDTO;
|
|
|
-import com.citu.module.system.api.sms.SmsCodeApi;
|
|
|
-import com.citu.module.system.api.social.SocialClientApi;
|
|
|
import com.citu.module.system.api.social.SocialUserApi;
|
|
|
import com.citu.module.system.api.social.dto.SocialUserBindReqDTO;
|
|
|
import com.citu.module.system.enums.logger.LoginLogTypeEnum;
|
|
@@ -39,7 +39,6 @@ import org.springframework.validation.annotation.Validated;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import javax.validation.Validator;
|
|
|
-
|
|
|
import java.util.Objects;
|
|
|
|
|
|
import static com.citu.framework.common.exception.util.ServiceExceptionUtil.exception;
|
|
@@ -57,8 +56,6 @@ import static com.citu.module.menduner.system.enums.ErrorCodeConstants.*;
|
|
|
public class MdeEnterpriseAuthServiceImpl implements MdeEnterpriseAuthService {
|
|
|
|
|
|
|
|
|
- @Resource
|
|
|
- private EnterpriseUserBindService bindService;
|
|
|
@Resource
|
|
|
protected MdeUserService userService;
|
|
|
@Resource
|
|
@@ -67,7 +64,6 @@ public class MdeEnterpriseAuthServiceImpl implements MdeEnterpriseAuthService {
|
|
|
protected SocialUserApi socialUserApi;
|
|
|
@Resource
|
|
|
protected OAuth2TokenApi oauth2TokenApi;
|
|
|
-
|
|
|
/**
|
|
|
* 验证码的开关,默认为 true
|
|
|
*/
|
|
@@ -75,9 +71,10 @@ public class MdeEnterpriseAuthServiceImpl implements MdeEnterpriseAuthService {
|
|
|
protected Boolean captchaEnable;
|
|
|
@Resource
|
|
|
protected Validator validator;
|
|
|
-
|
|
|
@Resource
|
|
|
protected CaptchaService captchaService;
|
|
|
+ @Resource
|
|
|
+ private EnterpriseUserBindMapper userBindMapper;
|
|
|
|
|
|
@VisibleForTesting
|
|
|
protected void validateCaptcha(AppMdeAuthLoginReqVO reqVO) {
|
|
@@ -104,7 +101,7 @@ public class MdeEnterpriseAuthServiceImpl implements MdeEnterpriseAuthService {
|
|
|
// 校验验证码
|
|
|
validateCaptcha(reqVO);
|
|
|
// 使用手机 + 密码,进行登录。
|
|
|
- MdeUserDO user = check(reqVO.getPhone(), reqVO.getPassword());
|
|
|
+ MdeUserDO user = check(reqVO.getEnterpriseId(),reqVO.getPhone(), reqVO.getPassword());
|
|
|
|
|
|
// 如果 socialType 非空,说明需要绑定社交用户
|
|
|
String openid = null;
|
|
@@ -114,7 +111,7 @@ public class MdeEnterpriseAuthServiceImpl implements MdeEnterpriseAuthService {
|
|
|
}
|
|
|
|
|
|
// 创建 Token 令牌,记录登录日志
|
|
|
- return createTokenAfterLoginSuccess(user, reqVO.getPhone(), LoginLogTypeEnum.LOGIN_MOBILE, openid);
|
|
|
+ return createTokenAfterLoginSuccess(user, reqVO.getPhone(), LoginLogTypeEnum.LOGIN_MOBILE, openid, reqVO.getEnterpriseId());
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -136,11 +133,11 @@ public class MdeEnterpriseAuthServiceImpl implements MdeEnterpriseAuthService {
|
|
|
}
|
|
|
|
|
|
// 创建 Token 令牌,记录登录日志
|
|
|
- return createTokenAfterLoginSuccess(user, reqVO.getPhone(), LoginLogTypeEnum.LOGIN_SMS, openid);
|
|
|
+ return createTokenAfterLoginSuccess(user, reqVO.getPhone(), LoginLogTypeEnum.LOGIN_SMS, openid, reqVO.getEnterpriseId());
|
|
|
}
|
|
|
|
|
|
|
|
|
- protected MdeUserDO check(String mobile, String password) {
|
|
|
+ protected MdeUserDO check(Long enterpriseId, String mobile, String password) {
|
|
|
final LoginLogTypeEnum logTypeEnum = LoginLogTypeEnum.LOGIN_MOBILE;
|
|
|
// 校验账号是否存在
|
|
|
MdeUserDO user = userService.getUserByPhone(mobile);
|
|
@@ -153,7 +150,10 @@ public class MdeEnterpriseAuthServiceImpl implements MdeEnterpriseAuthService {
|
|
|
throw exception(MDE_AUTH_LOGIN_BAD_CREDENTIALS);
|
|
|
}
|
|
|
// 查询绑定用户
|
|
|
- EnterpriseUserBindDO bind = bindService.getEnterpriseUserBind(user.getId());
|
|
|
+ EnterpriseUserBindDO bind = userBindMapper.selectByEnterpriseIdAndUserId(
|
|
|
+ enterpriseId,
|
|
|
+ user.getId()
|
|
|
+ );
|
|
|
if (null == bind) {
|
|
|
createLoginLog(user.getId(), mobile, logTypeEnum, LoginResultEnum.BAD_CREDENTIALS);
|
|
|
throw exception(MDE_USER_ENTERPRISE_NOT_USER_NULL);
|
|
@@ -168,17 +168,19 @@ public class MdeEnterpriseAuthServiceImpl implements MdeEnterpriseAuthService {
|
|
|
|
|
|
|
|
|
protected UserTypeEnum getUserType() {
|
|
|
- return UserTypeEnum.ADMIN;
|
|
|
+ return UserTypeEnum.MEMBER_ADMIN;
|
|
|
}
|
|
|
|
|
|
|
|
|
- protected AppMdeAuthLoginRespVO createTokenAfterLoginSuccess(MdeUserDO user, String phone, LoginLogTypeEnum logType, String openid) {
|
|
|
+ protected AppMdeAuthLoginRespVO createTokenAfterLoginSuccess(MdeUserDO user, String phone, LoginLogTypeEnum logType, String openid, Long enterpriseId) {
|
|
|
// 插入登陆日志
|
|
|
createLoginLog(user.getId(), phone, logType, LoginResultEnum.SUCCESS);
|
|
|
// 创建 Token 令牌
|
|
|
OAuth2AccessTokenRespDTO accessTokenRespDTO = oauth2TokenApi.createAccessToken(new OAuth2AccessTokenCreateReqDTO()
|
|
|
.setUserId(user.getId()).setUserType(getUserType().getValue())
|
|
|
- .setClientId(OAuth2ClientConstants.CLIENT_ID_MENDUNER)).getCheckedData();
|
|
|
+ .setClientId(OAuth2ClientConstants.CLIENT_ID_MENDUNER)
|
|
|
+ .setUserInfo(MapUtil.builder(LoginUser.INFO_KEY_DATA_ID, enterpriseId.toString()).build())
|
|
|
+ ).getCheckedData();
|
|
|
// 构建返回结果
|
|
|
return MdeAuthConvert.INSTANCE.convert(accessTokenRespDTO, openid);
|
|
|
}
|