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 |  125 ++++++++++++++++++++++++++++++++++++-----
 1 files changed, 108 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 5334a12..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,8 @@
 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;
 import com.doumee.service.business.third.model.LoginUserInfo;
@@ -170,6 +172,27 @@
             throw e;
         }
     }
+
+    @Override
+    public LoginUserInfo loginByPasswordForCabinet(LoginCabinetDTO dto, ServerHttpRequest request) {
+        SystemLoginLog loginLog = getInitLoginlog(dto.getUsername(),request);
+        try {
+            LoginUserInfo user = dealLoginByPwdNewBiz(dto.getUsername(),dto.getPassword(),null,null,null,request);
+            systemLoginLogService.create(loginLog);
+            return  user;
+        }catch (BusinessException e){
+            loginLog.setSuccess(Boolean.FALSE);
+            systemLoginLogService.create(loginLog);
+            throw e;
+
+        }catch (Exception e){
+            loginLog.setSuccess(Boolean.FALSE);
+            systemLoginLogService.create(loginLog);
+            throw e;
+        }
+    }
+
+
     @Override
     public LoginUserInfo loginH5 (LoginH5DTO dto, ServerHttpRequest request) {
         SystemLoginLog loginLog = getInitLoginlog(dto.getUsername(),request);
@@ -241,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);
         }
@@ -269,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);
@@ -283,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())){
@@ -465,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