|
@@ -17,6 +17,7 @@ import cn.iocoder.yudao.module.system.api.social.dto.SocialUserBindReqDTO;
|
|
|
import cn.iocoder.yudao.module.system.api.social.dto.SocialUserRespDTO;
|
|
import cn.iocoder.yudao.module.system.api.social.dto.SocialUserRespDTO;
|
|
|
import cn.iocoder.yudao.module.system.controller.admin.auth.vo.*;
|
|
import cn.iocoder.yudao.module.system.controller.admin.auth.vo.*;
|
|
|
import cn.iocoder.yudao.module.system.controller.admin.authentication.vo.AuthenticationPageReqVO;
|
|
import cn.iocoder.yudao.module.system.controller.admin.authentication.vo.AuthenticationPageReqVO;
|
|
|
|
|
+import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserPageReqVO;
|
|
|
import cn.iocoder.yudao.module.system.convert.auth.AuthConvert;
|
|
import cn.iocoder.yudao.module.system.convert.auth.AuthConvert;
|
|
|
import cn.iocoder.yudao.module.system.dal.dataobject.authentication.AuthenticationDO;
|
|
import cn.iocoder.yudao.module.system.dal.dataobject.authentication.AuthenticationDO;
|
|
|
import cn.iocoder.yudao.module.system.dal.dataobject.oauth2.OAuth2AccessTokenDO;
|
|
import cn.iocoder.yudao.module.system.dal.dataobject.oauth2.OAuth2AccessTokenDO;
|
|
@@ -51,9 +52,7 @@ import javax.annotation.Resource;
|
|
|
import javax.validation.Validator;
|
|
import javax.validation.Validator;
|
|
|
import java.time.Duration;
|
|
import java.time.Duration;
|
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
|
-import java.util.List;
|
|
|
|
|
-import java.util.Objects;
|
|
|
|
|
-import java.util.UUID;
|
|
|
|
|
|
|
+import java.util.*;
|
|
|
|
|
|
|
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
|
|
import static cn.iocoder.yudao.framework.common.util.servlet.ServletUtils.getClientIP;
|
|
import static cn.iocoder.yudao.framework.common.util.servlet.ServletUtils.getClientIP;
|
|
@@ -162,7 +161,10 @@ public class AdminAuthServiceImpl implements AdminAuthService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 登录场景,验证是否存在
|
|
// 登录场景,验证是否存在
|
|
|
- if (userService.getUserByMobile(reqVO.getMobile()) == null) {
|
|
|
|
|
|
|
+ UserPageReqVO userReqVO = new UserPageReqVO();
|
|
|
|
|
+ userReqVO.setMobile(reqVO.getMobile());
|
|
|
|
|
+ List<AdminUserDO> users = userService.users(userReqVO);
|
|
|
|
|
+ if (CollUtil.isEmpty(users)) {
|
|
|
throw exception(AUTH_MOBILE_NOT_EXISTS);
|
|
throw exception(AUTH_MOBILE_NOT_EXISTS);
|
|
|
}
|
|
}
|
|
|
// 发送验证码
|
|
// 发送验证码
|
|
@@ -175,13 +177,47 @@ public class AdminAuthServiceImpl implements AdminAuthService {
|
|
|
smsCodeApi.useSmsCode(AuthConvert.INSTANCE.convert(reqVO, SmsSceneEnum.ADMIN_MEMBER_LOGIN.getScene(), getClientIP()));
|
|
smsCodeApi.useSmsCode(AuthConvert.INSTANCE.convert(reqVO, SmsSceneEnum.ADMIN_MEMBER_LOGIN.getScene(), getClientIP()));
|
|
|
|
|
|
|
|
// 获得用户信息
|
|
// 获得用户信息
|
|
|
- AdminUserDO user = userService.getUserByMobile(reqVO.getMobile());
|
|
|
|
|
- if (user == null) {
|
|
|
|
|
|
|
+ // AdminUserDO user = userService.getUserByMobile(reqVO.getMobile());
|
|
|
|
|
+ UserPageReqVO userReqVO = new UserPageReqVO();
|
|
|
|
|
+ userReqVO.setMobile(reqVO.getMobile());
|
|
|
|
|
+ List<AdminUserDO> users = userService.users(userReqVO);
|
|
|
|
|
+ if (CollUtil.isEmpty(users)) {
|
|
|
|
|
+ throw exception(USER_NOT_EXISTS);
|
|
|
|
|
+ }
|
|
|
|
|
+ Long pmsUserId = null;
|
|
|
|
|
+ // 根据手机号获取用户信息
|
|
|
|
|
+ try {
|
|
|
|
|
+ String dingUserId = DingtalkUtil.getUserInfoByMobile(reqVO.getMobile());
|
|
|
|
|
+ if (StrUtil.isBlank(dingUserId)) {
|
|
|
|
|
+ // 查询不到用户详情 返回 登录失败
|
|
|
|
|
+ throw exception(USER_NOT_EXISTS);
|
|
|
|
|
+ }
|
|
|
|
|
+ // 根据钉钉用户id 查询用户详情
|
|
|
|
|
+ OapiV2UserGetResponse.UserGetResponse userDetail = DingtalkUtil.getUserDetail(dingUserId);
|
|
|
|
|
+ if (ObjUtil.isEmpty(userDetail)) {
|
|
|
|
|
+ // 查询不到用户详情 返回 登录失败
|
|
|
|
|
+ throw exception(USER_NOT_EXISTS);
|
|
|
|
|
+ }
|
|
|
|
|
+ // 工号
|
|
|
|
|
+ String jobNumber = userDetail.getJobNumber();
|
|
|
|
|
+ List<Long> userIds = new ArrayList<>();
|
|
|
|
|
+ users.forEach(user -> {
|
|
|
|
|
+ if (StrUtil.isNotBlank(jobNumber) && jobNumber.equals(user.getUsername())) {
|
|
|
|
|
+ userIds.add(user.getId());
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ if (CollUtil.isEmpty(userIds)) {
|
|
|
|
|
+ throw exception(USER_NOT_EXISTS);
|
|
|
|
|
+ }
|
|
|
|
|
+ pmsUserId = userIds.get(0);
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+ if (ObjUtil.isEmpty(pmsUserId)) {
|
|
|
throw exception(USER_NOT_EXISTS);
|
|
throw exception(USER_NOT_EXISTS);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
// 创建 Token 令牌,记录登录日志
|
|
// 创建 Token 令牌,记录登录日志
|
|
|
- return createTokenAfterLoginSuccess(user.getId(), reqVO.getMobile(), LoginLogTypeEnum.LOGIN_MOBILE);
|
|
|
|
|
|
|
+ return createTokenAfterLoginSuccess(pmsUserId, reqVO.getMobile(), LoginLogTypeEnum.LOGIN_MOBILE);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private void createLoginLog(Long userId, String username,
|
|
private void createLoginLog(Long userId, String username,
|
|
@@ -248,17 +284,47 @@ public class AdminAuthServiceImpl implements AdminAuthService {
|
|
|
if (StrUtil.isEmpty(accessToken)) {
|
|
if (StrUtil.isEmpty(accessToken)) {
|
|
|
throw exception(USER_NOT_EXISTS);
|
|
throw exception(USER_NOT_EXISTS);
|
|
|
}
|
|
}
|
|
|
- String mobile = DingtalkUtil.getUserInfo(accessToken);
|
|
|
|
|
- if (StrUtil.isEmpty(mobile)) {
|
|
|
|
|
|
|
+ Map<String, String> resultMap = DingtalkUtil.getUserInfo(accessToken);
|
|
|
|
|
+ if (CollUtil.isEmpty(resultMap)) {
|
|
|
throw exception(USER_NOT_EXISTS);
|
|
throw exception(USER_NOT_EXISTS);
|
|
|
}
|
|
}
|
|
|
|
|
+ String mobile = resultMap.get("mobile");
|
|
|
|
|
+ String unionId = resultMap.get("unionId");
|
|
|
|
|
+ // 根据unionId查询钉钉用户id
|
|
|
|
|
+ String dingUserId = DingtalkUtil.getUserIdByUnion(unionId);
|
|
|
|
|
+ // 根据钉钉用户id 查询用户详情
|
|
|
|
|
+ OapiV2UserGetResponse.UserGetResponse userDetail = DingtalkUtil.getUserDetail(dingUserId);
|
|
|
|
|
+ if (ObjUtil.isEmpty(userDetail)) {
|
|
|
|
|
+ // 查询不到用户详情 返回 登录失败
|
|
|
|
|
+ throw exception(USER_NOT_EXISTS);
|
|
|
|
|
+ }
|
|
|
|
|
+ // 工号
|
|
|
|
|
+ String jobNumber = userDetail.getJobNumber();
|
|
|
// 查询当前用户表中 此手机号 是否存在
|
|
// 查询当前用户表中 此手机号 是否存在
|
|
|
- AdminUserDO user = userService.getUserByMobile(mobile);
|
|
|
|
|
- if (ObjUtil.isEmpty(user)) {
|
|
|
|
|
|
|
+ // AdminUserDO user = userService.getUserByMobile(mobile);
|
|
|
|
|
+
|
|
|
|
|
+ UserPageReqVO userReqVO = new UserPageReqVO();
|
|
|
|
|
+ userReqVO.setMobile(mobile);
|
|
|
|
|
+ List<AdminUserDO> users = userService.users(userReqVO);
|
|
|
|
|
+ if (CollUtil.isEmpty(users)) {
|
|
|
|
|
+ throw exception(USER_NOT_EXISTS);
|
|
|
|
|
+ }
|
|
|
|
|
+ List<Long> userIds = new ArrayList<>();
|
|
|
|
|
+ List<String> usernames = new ArrayList<>();
|
|
|
|
|
+ users.forEach(loginUser -> {
|
|
|
|
|
+ if (StrUtil.isNotBlank(jobNumber) && jobNumber.equals(loginUser.getUsername())) {
|
|
|
|
|
+ userIds.add(loginUser.getId());
|
|
|
|
|
+ usernames.add(jobNumber);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ if (CollUtil.isEmpty(userIds) || CollUtil.isEmpty(usernames)) {
|
|
|
throw exception(USER_NOT_EXISTS);
|
|
throw exception(USER_NOT_EXISTS);
|
|
|
}
|
|
}
|
|
|
|
|
+ Long pmsUserId = userIds.get(0);
|
|
|
|
|
+ String username = usernames.get(0);
|
|
|
|
|
+
|
|
|
// 创建 Token 令牌,记录登录日志
|
|
// 创建 Token 令牌,记录登录日志
|
|
|
- return createTokenAfterLoginSuccess(user.getId(), user.getUsername(), LoginLogTypeEnum.LOGIN_DING_APP);
|
|
|
|
|
|
|
+ return createTokenAfterLoginSuccess(pmsUserId, username, LoginLogTypeEnum.LOGIN_DING_APP);
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
throw new RuntimeException(e);
|
|
throw new RuntimeException(e);
|
|
|
}
|
|
}
|
|
@@ -289,12 +355,29 @@ public class AdminAuthServiceImpl implements AdminAuthService {
|
|
|
throw exception(USER_NOT_EXISTS);
|
|
throw exception(USER_NOT_EXISTS);
|
|
|
}
|
|
}
|
|
|
// 查询当前用户表中 此手机号 是否存在
|
|
// 查询当前用户表中 此手机号 是否存在
|
|
|
- AdminUserDO user = userService.getUserByMobile(mobile);
|
|
|
|
|
- if (ObjUtil.isEmpty(user)) {
|
|
|
|
|
|
|
+ // AdminUserDO user = userService.getUserByMobile(mobile);
|
|
|
|
|
+ // 可能多个用户使用了相同的手机号
|
|
|
|
|
+ UserPageReqVO userReqVO = new UserPageReqVO();
|
|
|
|
|
+ userReqVO.setMobile(mobile);
|
|
|
|
|
+ List<AdminUserDO> users = userService.users(userReqVO);
|
|
|
|
|
+ if (CollUtil.isEmpty(users)) {
|
|
|
throw exception(USER_NOT_EXISTS);
|
|
throw exception(USER_NOT_EXISTS);
|
|
|
}
|
|
}
|
|
|
|
|
+ List<Long> userIds = new ArrayList<>();
|
|
|
|
|
+ List<String> usernames = new ArrayList<>();
|
|
|
|
|
+ users.forEach(user -> {
|
|
|
|
|
+ if (StrUtil.isNotBlank(jobNumber) && jobNumber.equals(user.getUsername())) {
|
|
|
|
|
+ userIds.add(user.getId());
|
|
|
|
|
+ usernames.add(jobNumber);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ if (CollUtil.isEmpty(userIds) || CollUtil.isEmpty(usernames)) {
|
|
|
|
|
+ throw exception(USER_NOT_EXISTS);
|
|
|
|
|
+ }
|
|
|
|
|
+ Long pmsUserId = userIds.get(0);
|
|
|
|
|
+ String username = usernames.get(0);
|
|
|
// 创建 Token 令牌,记录登录日志 h5钉钉微应用登录
|
|
// 创建 Token 令牌,记录登录日志 h5钉钉微应用登录
|
|
|
- return createTokenAfterLoginSuccess(user.getId(), user.getUsername(), LoginLogTypeEnum.LOGIN_DING_H5);
|
|
|
|
|
|
|
+ return createTokenAfterLoginSuccess(pmsUserId, username, LoginLogTypeEnum.LOGIN_DING_H5);
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
// 调用钉钉接口报错 提示 登录失败
|
|
// 调用钉钉接口报错 提示 登录失败
|
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
@@ -451,8 +534,46 @@ public class AdminAuthServiceImpl implements AdminAuthService {
|
|
|
@Override
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public void resetPassword(AuthResetPasswordReqVO reqVO) {
|
|
public void resetPassword(AuthResetPasswordReqVO reqVO) {
|
|
|
- AdminUserDO userByMobile = userService.getUserByMobile(reqVO.getMobile());
|
|
|
|
|
- if (userByMobile == null) {
|
|
|
|
|
|
|
+ // AdminUserDO userByMobile = userService.getUserByMobile(reqVO.getMobile());
|
|
|
|
|
+
|
|
|
|
|
+ UserPageReqVO userReqVO = new UserPageReqVO();
|
|
|
|
|
+ userReqVO.setMobile(reqVO.getMobile());
|
|
|
|
|
+ List<AdminUserDO> users = userService.users(userReqVO);
|
|
|
|
|
+
|
|
|
|
|
+ if (CollUtil.isEmpty(users)) {
|
|
|
|
|
+ throw exception(USER_MOBILE_NOT_EXISTS);
|
|
|
|
|
+ }
|
|
|
|
|
+ Long pmsUserId = null;
|
|
|
|
|
+ // 根据手机号获取钉钉用户id
|
|
|
|
|
+ try {
|
|
|
|
|
+ String dingUserId = DingtalkUtil.getUserInfoByMobile(reqVO.getMobile());
|
|
|
|
|
+ if (StrUtil.isBlank(dingUserId)) {
|
|
|
|
|
+ // 查询不到用户详情 返回 登录失败
|
|
|
|
|
+ throw exception(USER_MOBILE_NOT_EXISTS);
|
|
|
|
|
+ }
|
|
|
|
|
+ // 根据钉钉用户id 查询用户详情
|
|
|
|
|
+ OapiV2UserGetResponse.UserGetResponse userDetail = DingtalkUtil.getUserDetail(dingUserId);
|
|
|
|
|
+ if (ObjUtil.isEmpty(userDetail)) {
|
|
|
|
|
+ // 查询不到用户详情 返回 登录失败
|
|
|
|
|
+ throw exception(USER_MOBILE_NOT_EXISTS);
|
|
|
|
|
+ }
|
|
|
|
|
+ // 工号
|
|
|
|
|
+ String jobNumber = userDetail.getJobNumber();
|
|
|
|
|
+ List<Long> userIds = new ArrayList<>();
|
|
|
|
|
+ users.forEach(user -> {
|
|
|
|
|
+ if (StrUtil.isNotBlank(jobNumber) && jobNumber.equals(user.getUsername())) {
|
|
|
|
|
+ userIds.add(user.getId());
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ if (CollUtil.isEmpty(userIds)) {
|
|
|
|
|
+ throw exception(USER_MOBILE_NOT_EXISTS);
|
|
|
|
|
+ }
|
|
|
|
|
+ pmsUserId = userIds.get(0);
|
|
|
|
|
+
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+ if (ObjUtil.isEmpty(pmsUserId)) {
|
|
|
throw exception(USER_MOBILE_NOT_EXISTS);
|
|
throw exception(USER_MOBILE_NOT_EXISTS);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -463,7 +584,7 @@ public class AdminAuthServiceImpl implements AdminAuthService {
|
|
|
.setUsedIp(getClientIP())
|
|
.setUsedIp(getClientIP())
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
- userService.updateUserPassword(userByMobile.getId(), reqVO.getPassword());
|
|
|
|
|
|
|
+ userService.updateUserPassword(pmsUserId, reqVO.getPassword());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|