Browse Source

Merge remote-tracking branch 'origin/developer' into developerH

Duan_xu 2 years ago
parent
commit
e6874ed998

+ 1 - 4
src/main/java/com/caimei365/user/service/impl/BaseServiceImpl.java

@@ -401,10 +401,7 @@ public class BaseServiceImpl implements BaseService {
         String dbPassword = Md5Util.md5(passWord);
         baseMapper.updatePasswordByUserId(dbPassword, dbUserId);
         //重新设置密码后将登录失败表中近30分钟记录置为删除
-        Calendar c = Calendar.getInstance();
-        c.setTime(new Date());
-        c.add(Calendar.MINUTE, -30);
-        loginMapper.updateLoginFailRecord(dbUserId, c.getTime());
+        redisService.remove("login-"+dbUserId);
         return ResponseJson.success("密码修改成功", "");
     }
 

+ 28 - 12
src/main/java/com/caimei365/user/service/impl/LoginServiceImpl.java

@@ -17,6 +17,7 @@ import com.caimei365.user.model.vo.*;
 import com.caimei365.user.service.LoginService;
 import com.caimei365.user.service.RemoteCallService;
 import com.caimei365.user.utils.JwtUtil;
+import com.caimei365.user.utils.MathUtil;
 import com.caimei365.user.utils.Md5Util;
 import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.PageInfo;
@@ -99,16 +100,19 @@ public class LoginServiceImpl implements LoginService {
         }
         //处理比对密码
         UserLoginVo baseUser = loginMapper.getLoginUserByMobileOrEmail(mobileOrEmail);
-
-        if (baseUser != null) {
+        if (null != baseUser) {
+            String key = "login-" + baseUser.getUserId();
+            boolean exists = redisService.exists(key);
             //如果30分钟内输入错误记录>=5,return该账号暂时被冻结,请(30-最前一次时间)分钟后重试或直接修改密码
-            Calendar c = Calendar.getInstance();
-            c.setTime(new Date());
-            c.add(Calendar.MINUTE, -30);
-            List<LoginFailRecordVo> fail = loginMapper.findLoginFailRecord(baseUser.getUserId(), c.getTime());
-            if (null != fail && fail.size() >= 5) {
-                Integer minutes = loginMapper.findTimes(fail.get(0).getId(),new Date());
-                return ResponseJson.error("该账号暂时被冻结,请" + (30 - minutes) + "分钟后重试或直接修改密码", null);
+            if (exists) {
+                String val = (String) redisService.get(key);
+                String[] split = val.split(",");
+                int count = Integer.parseInt(split[0]);
+                if (count >= 5) {
+                    long s = Long.parseLong(split[1]);
+                    int l = (int) Math.floor((System.currentTimeMillis() - s) / 1000 / 60);
+                    return ResponseJson.error("该账号暂时被冻结,请" + (30-l) + "分钟后重试或直接修改密码", null);
+                }
             }
             // 如果前端传入unionId,则存入返回前端
             baseUser.setUnionId(unionId);
@@ -135,9 +139,21 @@ public class LoginServiceImpl implements LoginService {
                 }
             } else {
                 // 增加一次错误输入密码记录,30分钟内连续五次冻结
-                loginMapper.insertLoginFailRecord(new Date(),baseUser.getUserId());
-                if (null != fail && 4 ==fail.size() ) {
-                    return ResponseJson.error("您已连续输错5次密码,账号被暂时冻结,请于30分钟后重试或直接修改密码",null);
+                if (exists) {
+                    String val = (String) redisService.get(key);
+                    String[] split = val.split(",");
+                    int count = Integer.parseInt(split[0]);
+                    if (count < 5) {
+                        count++;
+                        String va = count + "," + System.currentTimeMillis();
+                        redisService.set(key, va);
+                    }
+                    if (count >= 5) {
+                        redisService.set(key, 5 + "," + System.currentTimeMillis(), 1800L);
+                    }
+                } else {
+                    String val = 1 + "," + System.currentTimeMillis();
+                    redisService.set(key, val);
                 }
             }
         }

+ 30 - 7
src/main/resources/mapper/LoginMapper.xml

@@ -45,13 +45,36 @@
                cu.status            as operationStatus,
                cu.mobile            as operationMobile
         from user u
-                 left join cm_mall_operation_user cu on cu.userID = u.userID
-        where (u.bindMobile = #{mobileOrEmail}
-            or u.email = #{mobileOrEmail}
-            or (cu.mobile = #{mobileOrEmail} and cu.delFlag != 1)
-            )
-          and u.userIdentity in (1, 2, 3, 4)
-          and u.userOrganizeID = 0
+        left join cm_mall_operation_user cu on cu.userID = u.userID
+        where (u.bindMobile = #{mobileOrEmail} or u.email = #{mobileOrEmail})
+            and u.userIdentity in (1, 2, 3, 4)
+            and u.userOrganizeID = 0
+        union
+        SELECT u.userID             AS userId,
+               u.clubID             AS clubId,
+               u.shopID             AS shopId,
+               u.serviceProviderId  AS serviceProviderId,
+               u.userName           AS userName,
+               u.name               AS NAME,
+               u.mobile             AS mobile,
+               u.bindMobile         AS bindMobile,
+               u.email              AS email,
+               u.userPermission     AS userPermission,
+               u.userIdentity       AS userIdentity,
+               u.password           AS PASSWORD,
+               u.guideFlag          AS guideFlag,
+               u.clubStatus         AS clubStatus,
+               u.manufacturerStatus AS shopStatus,
+               cu.id                AS operationId,
+               cu.status            AS operationStatus,
+               cu.mobile            AS operationMobile
+        FROM USER u
+        LEFT JOIN cm_mall_operation_user cu ON cu.userID = u.userID
+        WHERE
+            cu.mobile = #{mobileOrEmail}
+          and cu.delFlag != 1
+          AND u.userIdentity IN (1, 2, 3, 4)
+          AND u.userOrganizeID = 0
         limit 1
     </select>
     <select id="getLoginUserByMobile" resultType="com.caimei365.user.model.vo.UserLoginVo">