From 19321e1348baefa2a9f5211c42f8b797c0fcccd1 Mon Sep 17 00:00:00 2001
From: rk <94314517@qq.com>
Date: 星期一, 27 十月 2025 18:11:56 +0800
Subject: [PATCH] 登录验证
---
server/system_service/src/main/java/com/doumee/service/system/impl/SystemLoginServiceImpl.java | 103 +++++++++++++++++++++++++++++++++++++++++++--------
1 files changed, 86 insertions(+), 17 deletions(-)
diff --git a/server/system_service/src/main/java/com/doumee/service/system/impl/SystemLoginServiceImpl.java b/server/system_service/src/main/java/com/doumee/service/system/impl/SystemLoginServiceImpl.java
index 722ef3e..a3f727e 100644
--- a/server/system_service/src/main/java/com/doumee/service/system/impl/SystemLoginServiceImpl.java
+++ b/server/system_service/src/main/java/com/doumee/service/system/impl/SystemLoginServiceImpl.java
@@ -5,6 +5,7 @@
import com.doumee.biz.system.SystemDictDataBiz;
import com.doumee.config.jwt.JwtTokenUtil;
import com.doumee.core.exception.BusinessException;
+import com.doumee.core.utils.DateUtil;
import com.doumee.dao.system.dto.LoginCabinetDTO;
import com.doumee.dao.system.dto.LoginH5DTO;
import com.doumee.service.business.third.TmsService;
@@ -263,13 +264,14 @@
if(!Constants.equalsInteger(user.getSource(),Constants.ZERO)){
throw new BusinessException(ResponseStatus.NO_ALLOW_LOGIN);
}
- if(StringUtils.isNotBlank( pwd)){
- String pppp = Utils.Secure.encryptPassword(new String(pwd), user.getSalt());
- // 姣旇緝瀵嗙爜
- if( !StringUtils.equals(pppp, user.getPassword())){
- throw new BusinessException(ResponseStatus.ACCOUNT_INCORRECT);
- }
- }
+ this.checkPassword(user,pwd);
+// if(StringUtils.isNotBlank( pwd)){
+// String pppp = Utils.Secure.encryptPassword(new String(pwd), user.getSalt());
+// // 姣旇緝瀵嗙爜
+// if( !StringUtils.equals(pppp, user.getPassword())){
+// throw new BusinessException(ResponseStatus.ACCOUNT_INCORRECT);
+// }
+// }
if(StringUtils.isNotBlank(openid)){
dealOpenIdBiz(user,openid);
}
@@ -291,6 +293,69 @@
return userInfo;
}
+
+ public void checkPassword(SystemUser user,String pwd){
+ //楠岃瘉鏄惁宸茬姝㈢櫥褰�
+ this.prohibitLogin(user);
+ String pppp = Utils.Secure.encryptPassword(new String(pwd), user.getSalt());
+ // 姣旇緝瀵嗙爜
+ if( !StringUtils.equals(pppp, user.getPassword())){
+ //鏄惁寮�鍚瘑鐮侀敊璇姝㈢櫥褰曪細0=鍚︼紱1=鏄紱
+ SystemDictData prohibitLoginData = systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.PROHIBIT_LOGIN_OPEN);
+ //瀵嗙爜閿欒绂佹鐧诲綍闄愬埗鏃堕棿锛堝垎閽燂級
+ SystemDictData prohibitTimeData = systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.PROHIBIT_TIME);
+ updErrTimes(user,prohibitLoginData,prohibitTimeData);
+ if(Objects.nonNull(prohibitLoginData)&&"1".equals(prohibitLoginData.getCode())){
+ SystemDictData prohibitErrTimesData = systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.ERR_TIMES);
+ if(Objects.nonNull(prohibitErrTimesData)){
+ if(Integer.valueOf(prohibitErrTimesData.getCode())
+ -(Constants.formatIntegerNum(user.getErrTimes())+1) == Constants.ZERO){
+ throw new BusinessException(ResponseStatus.ACCOUNT_INCORRECT.getCode(),"璐﹀彿瀵嗙爜閿欒锛岃处鎴峰凡閿佸畾锛岃"+prohibitTimeData.getCode()+"鍒嗛挓鍚庨噸璇曪紒");
+ }
+
+ throw new BusinessException(ResponseStatus.ACCOUNT_INCORRECT.getCode(),"璐﹀彿瀵嗙爜閿欒锛屽墿浣欏皾璇曟鏁�"+(Integer.valueOf(prohibitErrTimesData.getCode())
+ -(Constants.formatIntegerNum(user.getErrTimes())+1))+"娆★紝瓒呭嚭閿欒娆℃暟灏嗛攣瀹氳处鍙�");
+ }
+ throw new BusinessException(ResponseStatus.ACCOUNT_INCORRECT);
+ }else{
+ throw new BusinessException(ResponseStatus.ACCOUNT_INCORRECT);
+ }
+ }else{
+ systemUserMapper.update(null,new UpdateWrapper<SystemUser>().lambda()
+ .set(SystemUser::getProhibitStatus,Constants.ZERO)
+ .set(SystemUser::getErrTimes,Constants.ZERO)
+ .setSql(" PROHIBIT_TIME = null ")
+ .eq(SystemUser::getId,user.getId())
+ );
+ }
+ }
+
+ public void updErrTimes(SystemUser systemUser,SystemDictData prohibitLoginData,SystemDictData prohibitTimeData){
+ //鏈�澶ч敊璇鏁� 杩涜鐧诲綍闄愬埗
+ SystemDictData prohibitErrTimesData = systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.ERR_TIMES);
+ if(Objects.isNull(prohibitTimeData)||Objects.isNull(prohibitLoginData)||Objects.isNull(prohibitTimeData)){
+ return;
+ }
+ systemUserMapper.update(null,new UpdateWrapper<SystemUser>().lambda()
+ .setSql( " PROHIBIT_STATUS = CASE WHEN "+prohibitLoginData.getCode()+" = 1 and ( IFNULL(ERR_TIMES,0) + 1 ) >= "+prohibitErrTimesData.getCode()+" then 1 else 0 end ")
+ .setSql(" PROHIBIT_TIME = CASE WHEN PROHIBIT_STATUS = 1 then DATE_ADD(NOW(), INTERVAL "+prohibitTimeData.getCode()+" MINUTE) else null end ")
+ .setSql(" ERR_TIMES = (ifnull(ERR_TIMES,0) + 1) ")
+ .setSql(" PROHIBIT_REMARK = '浜�"+DateUtil.getCurrDateTime()+"鐧诲綍瀵嗙爜閿欒娆℃暟杩囧锛岀姝㈢櫥褰曪紒' ")
+ .eq(SystemUser::getId,systemUser.getId())
+ );
+ }
+
+ public void prohibitLogin(SystemUser systemUser){
+ if(Constants.equalsInteger(systemUser.getProhibitStatus(),Constants.ONE)){
+ Long betweenMin = DateUtil.getBetweenMin(new Date(),systemUser.getProhibitTime());
+ if(betweenMin <= 0L){
+ betweenMin = 0L;
+ }
+ throw new BusinessException( ResponseStatus.NOT_ALLOWED.getCode(),"瀵嗙爜閿欒娆℃暟杩囧锛岃鍚�"+ betweenMin +"鍒嗛挓鍚庨噸璇�");
+ }
+ }
+
+
@Override
public LoginUserInfo loginByPasswordForPda(LoginDTO dto, ServerHttpRequest request) {
SystemLoginLog loginLog =getInitLoginlog(dto.getUsername(),request);
@@ -305,11 +370,14 @@
if(!Constants.equalsInteger(user.getSource(),Constants.ZERO)){
throw new BusinessException(ResponseStatus.NO_ALLOW_LOGIN);
}
- String pwd = Utils.Secure.encryptPassword(new String(dto.getPassword()), user.getSalt());
- // 姣旇緝瀵嗙爜
- if( !StringUtils.equals(pwd, user.getPassword())){
- throw new BusinessException(ResponseStatus.ACCOUNT_INCORRECT);
- }
+
+// String pwd = Utils.Secure.encryptPassword(new String(dto.getPassword()), user.getSalt());
+// // 姣旇緝瀵嗙爜
+// if( !StringUtils.equals(pwd, user.getPassword())){
+// throw new BusinessException(ResponseStatus.ACCOUNT_INCORRECT);
+// }
+
+ this.checkPassword(user,dto.getPassword());
dealOpenIdBiz(user,dto.getOpenid());
Company company = new Company();
if(Objects.nonNull(user.getCompanyId())){
@@ -487,11 +555,12 @@
throw new BusinessException(ResponseStatus.NO_ALLOW_LOGIN.getCode(),"瀵逛笉璧凤紝璇ヨ处鍙蜂笉鑳界櫥褰曞徃鏈虹鍝︼紒");
}
if(StringUtils.isNotBlank(password)){
- String pwd = Utils.Secure.encryptPassword(new String(password), user.getSalt());
- // 姣旇緝瀵嗙爜
- if( !StringUtils.equals(pwd, user.getPassword())){
- throw new BusinessException(ResponseStatus.ACCOUNT_INCORRECT);
- }
+// String pwd = Utils.Secure.encryptPassword(new String(password), user.getSalt());
+// // 姣旇緝瀵嗙爜
+// if( !StringUtils.equals(pwd, user.getPassword())){
+// throw new BusinessException(ResponseStatus.ACCOUNT_INCORRECT);
+// }
+ this.checkPassword(user,password);
}
dealOpenIdBiz(user,openid);
Company company = new Company();
--
Gitblit v1.9.3