From a27162cb82ef0cabf9b43cbfd1f3eb8c177d1e14 Mon Sep 17 00:00:00 2001
From: heheng <heheng@123456>
Date: Mon, 13 Jan 2025 15:22:44 +0800
Subject: [PATCH] 修改问题
---
src/main/java/com/gkhy/labRiskManage/application/account/service/impl/AccountAppServiceImpl.java | 92 ++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 88 insertions(+), 4 deletions(-)
diff --git a/src/main/java/com/gkhy/labRiskManage/application/account/service/impl/AccountAppServiceImpl.java b/src/main/java/com/gkhy/labRiskManage/application/account/service/impl/AccountAppServiceImpl.java
index a1a49b1..c504bb9 100644
--- a/src/main/java/com/gkhy/labRiskManage/application/account/service/impl/AccountAppServiceImpl.java
+++ b/src/main/java/com/gkhy/labRiskManage/application/account/service/impl/AccountAppServiceImpl.java
@@ -16,6 +16,7 @@
import com.gkhy.labRiskManage.application.account.dto.respDto.LoginRespDto;
import com.gkhy.labRiskManage.application.account.dto.respDto.TokenInfoDto;
import com.gkhy.labRiskManage.domain.account.converter.UserRoleBindConverter;
+import com.gkhy.labRiskManage.domain.account.entity.User;
import com.gkhy.labRiskManage.domain.account.enums.IdentityStatusEnum;
import com.gkhy.labRiskManage.domain.account.enums.UserStatusEnum;
import com.gkhy.labRiskManage.application.account.service.AccountAppService;
@@ -28,19 +29,23 @@
import com.gkhy.labRiskManage.domain.account.model.bo.UpdateUserBO;
import com.gkhy.labRiskManage.domain.account.model.dto.SysUserRoleBindDomainDTO;
+import com.gkhy.labRiskManage.domain.account.repository.jpa.UserRepository;
import com.gkhy.labRiskManage.domain.account.service.SysUserIdentityBindDomainService;
import com.gkhy.labRiskManage.domain.account.service.UserDomainService;
import com.gkhy.labRiskManage.domain.account.model.dto.UserInfoDomainDTO;
import com.gkhy.labRiskManage.domain.account.service.UserRoleDomainService;
+import com.gkhy.labRiskManage.domain.riskReport.utils.GetRoleTagUtils;
import org.redisson.api.RedissonClient;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
+import org.springframework.util.ObjectUtils;
import java.util.ArrayList;
import java.util.List;
+import java.util.Optional;
@Service
public class AccountAppServiceImpl implements AccountAppService {
@@ -68,6 +73,7 @@
@Autowired
private UserRoleBindConverter converter;
+
@Override
public SearchResult<UserInfoAppRespDTO> findUserByLoginName(String loginName){
@@ -152,7 +158,11 @@
@Override
@Transactional
- public Result updateUserPassword(ChangePasswdReqDto dto) {
+ public Result updateUserPassword(ChangePasswdReqDto dto, Long currentUserId) {
+ //人员校验
+ if (!currentUserId.equals(dto.getUid())){
+ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "修改密码遇到错误");
+ }
Result result = new Result<>();
if(userDomainService.updateUserPwd(dto.getUid(),dto.getOldPwd(),dto.getNewPwd()) == true){
result.setSuccess();
@@ -160,6 +170,36 @@
result.setCode(ResultCode.SYSTEM_ERROR.getCode());
result.setMsg("修改密码失败");
}
+ return result;
+ }
+
+ @Override
+ public Result resetUserPassword(ChangePasswdReqDto dto, Long currentUserId) {
+ //todo 身份校验
+
+ if (currentUserId.equals(53)){
+ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"管理员用户不可重置");
+ }
+ UserInfoDomainDTO userInfo = userDomainService.getUserById(currentUserId);
+
+ if (ObjectUtils.isEmpty(userInfo)){
+ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"用户不存在");
+ }
+
+ int roleTag = GetRoleTagUtils.GetRoleTagUtils(userInfo);
+ if (roleTag < 2){
+ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"无权限重置");
+ }
+
+ Result result = new Result<>();
+
+ if(userDomainService.resetUserPassword(dto.getUid(), currentUserId) == true){
+ result.setSuccess();
+ }else {
+ result.setCode(ResultCode.SYSTEM_ERROR.getCode());
+ result.setMsg("重置密码失败");
+ }
+
return result;
}
@@ -216,7 +256,6 @@
result.setMsg("用户不存在");
return result;
}
-
if(!userDomainService.checkPassword(loginReqAppDTO.getPwd(), userInfoDomainDTO.getHash(), userInfoDomainDTO.getSalt())){
result.setCode(ResultCode.BUSINESS_ERROR_NOT_ALLOWED.getCode());
result.setMsg("密码错误");
@@ -252,13 +291,14 @@
loginRespDto.setRealName(userInfoDomainDTO.getRealName());
loginRespDto.setTk(tokenInfoDto.getTk());
loginRespDto.setRoles(converter.userRoleBindConverter(userInfoDomainDTO.getRoles()));
- //todo:获取其他需返回的信息
+ //获取其他需返回的信息
result.setSuccess();
result.setData(loginRespDto);
return result;
}
+
@Override
public Result logout(Long userId) {
@@ -293,8 +333,26 @@
createUserBO.setRealName(createNewUserAppReqDTO.getRealName());
//如果没有提供密码,初始密码为“123456”
if(createNewUserAppReqDTO.getPwd() == null || createNewUserAppReqDTO.getPwd().isEmpty()){
- createNewUserAppReqDTO.setPwd("123456");
+ createNewUserAppReqDTO.setPwd("Gs@123456");
}
+
+ //todo 2024 弱口令问题处理
+ if (createNewUserAppReqDTO.getPwd().length() < 8){
+ throw new BusinessException(this.getClass(),ResultCode.PARAM_ERROR_ILLEGAL.getCode(),"密码长度不够");
+ }
+ if (!createNewUserAppReqDTO.getPwd().matches(".*[A-Z].*")){
+ throw new BusinessException(this.getClass(),ResultCode.PARAM_ERROR_ILLEGAL.getCode(),"密码需要包含大小写字母、数字、特殊符号");
+ }
+ if (!createNewUserAppReqDTO.getPwd().matches(".*[a-z].*")){
+ throw new BusinessException(this.getClass(),ResultCode.PARAM_ERROR_ILLEGAL.getCode(),"密码需要包含大小写字母、数字、特殊符号");
+ }
+ if (!createNewUserAppReqDTO.getPwd().matches(".*\\d.*")){
+ throw new BusinessException(this.getClass(),ResultCode.PARAM_ERROR_ILLEGAL.getCode(),"密码需要包含大小写字母、数字、特殊符号");
+ }
+ if (!createNewUserAppReqDTO.getPwd().matches(".*[!@#$%^&*.()?+`~<>,-].*")){
+ throw new BusinessException(this.getClass(),ResultCode.PARAM_ERROR_ILLEGAL.getCode(),"密码需要包含大小写字母、数字、特殊符号");
+ }
+
createUserBO.setPwd(createNewUserAppReqDTO.getPwd());
createUserBO.setPhone(createNewUserAppReqDTO.getPhone());
createUserBO.setIdType(createNewUserAppReqDTO.getIdType());
@@ -345,6 +403,28 @@
bo.setDepId(updateUserAppReqDTO.getDepId());
bo.setIdentityStatus(updateUserAppReqDTO.getIdentityStatus());
bo.setQualificationAttId(updateUserAppReqDTO.getQualificationAttId());
+ if (!ObjectUtils.isEmpty(updateUserAppReqDTO.getPwd())){
+ if (updateUserAppReqDTO.getPwd().length() < 8){
+ throw new BusinessException(this.getClass(),ResultCode.PARAM_ERROR_ILLEGAL.getCode(),"密码长度不够");
+ }
+ if (!updateUserAppReqDTO.getPwd().matches(".*[A-Z].*")){
+ throw new BusinessException(this.getClass(),ResultCode.PARAM_ERROR_ILLEGAL.getCode(),"密码需要包含大小写字母、数字、特殊符号");
+ }
+ if (!updateUserAppReqDTO.getPwd().matches(".*[a-z].*")){
+ throw new BusinessException(this.getClass(),ResultCode.PARAM_ERROR_ILLEGAL.getCode(),"密码需要包含大小写字母、数字、特殊符号");
+ }
+ if (!updateUserAppReqDTO.getPwd().matches(".*\\d.*")){
+ throw new BusinessException(this.getClass(),ResultCode.PARAM_ERROR_ILLEGAL.getCode(),"密码需要包含大小写字母、数字、特殊符号");
+ }
+ if (!updateUserAppReqDTO.getPwd().matches(".*[!@#$%^&*.()?+`~<>,-].*")){
+ throw new BusinessException(this.getClass(),ResultCode.PARAM_ERROR_ILLEGAL.getCode(),"密码需要包含大小写字母、数字、特殊符号");
+ }
+ bo.setPwd(updateUserAppReqDTO.getPwd());
+ }
+
+
+
+
UserInfoDomainDTO updateRs = userDomainService.updateUserInfo(bo);
//修改用户绑定角色
userRoleDomainService.updateUserRole(updateUserAppReqDTO.getId(), updateUserAppReqDTO.getRoleIds());
@@ -365,6 +445,8 @@
}
return result;
}
+
+
@Transactional
@Override
@@ -406,4 +488,6 @@
}
+
+
}
--
Gitblit v1.9.2