WANG 6 жил өмнө
parent
commit
9183df6ef8

+ 14 - 10
examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/core/basic/service/impl/AuthServiceImpl.java

@@ -133,7 +133,7 @@ public class AuthServiceImpl implements AuthService {
 			}
 		}
 
-		if (limited(accountTypeEnum, accountValue, clientIp)) {
+		if (5 < getLoginErrorTimes(accountTypeEnum, accountValue, clientIp)) {
 			throw new StatusException("B-001205", "登陆失败次数已达到上限,请5分钟后重试");
 		}
 
@@ -195,7 +195,7 @@ public class AuthServiceImpl implements AuthService {
 			}
 			String rightPassword = userEntity.getPassword();
 			if (!rightPassword.equals(password)) {
-				whenError(accountTypeEnum, accountValue, clientIp);
+				whenLoginError(accountTypeEnum, accountValue, clientIp);
 				throw new StatusException("B-001003", "账号或密码错误");
 			}
 			user.setUserId(userEntity.getId());
@@ -229,7 +229,7 @@ public class AuthServiceImpl implements AuthService {
 				try {
 					smsCodeService.checkSmsCode(accountValue, smsCode);
 				} catch (Exception e) {
-					whenError(accountTypeEnum, accountValue, clientIp);
+					whenLoginError(accountTypeEnum, accountValue, clientIp);
 					throw e;
 				}
 			}
@@ -240,7 +240,7 @@ public class AuthServiceImpl implements AuthService {
 				}
 				String rightPassword = student.getPassword();
 				if (!rightPassword.equals(password)) {
-					whenError(accountTypeEnum, accountValue, clientIp);
+					whenLoginError(accountTypeEnum, accountValue, clientIp);
 					throw new StatusException("B-001003", "账号或密码错误");
 				}
 			}
@@ -264,7 +264,7 @@ public class AuthServiceImpl implements AuthService {
 					try {
 						smsCodeService.checkSmsCode(phone, smsCode);
 					} catch (Exception e) {
-						whenError(accountTypeEnum, accountValue, clientIp);
+						whenLoginError(accountTypeEnum, accountValue, clientIp);
 						throw e;
 					}
 				}
@@ -303,14 +303,14 @@ public class AuthServiceImpl implements AuthService {
 	}
 
 	/**
-	 * 重试限制
+	 * 登陆限制
 	 *
 	 * @author WANGWEI
 	 * @param accountType
 	 * @param accountValue
 	 * @param ip
 	 */
-	private void whenError(AccountType accountType, String accountValue, String ip) {
+	private void whenLoginError(AccountType accountType, String accountValue, String ip) {
 		String key = new StringBuilder("$_LOGIN_ERR_").append(accountType.getCode()).append("_")
 				.append(accountValue).append("_").append(ip).toString();
 
@@ -325,7 +325,7 @@ public class AuthServiceImpl implements AuthService {
 	}
 
 	/**
-	 * 是否可登录
+	 * 获取登陆错误次数
 	 *
 	 * @author WANGWEI
 	 * @param accountType
@@ -333,13 +333,17 @@ public class AuthServiceImpl implements AuthService {
 	 * @param ip
 	 * @return
 	 */
-	private boolean limited(AccountType accountType, String accountValue, String ip) {
+	private Integer getLoginErrorTimes(AccountType accountType, String accountValue, String ip) {
 		String key = new StringBuilder("$_LOGIN_ERR_").append(accountType.getCode()).append("_")
 				.append(accountValue).append("_").append(ip).toString();
 
 		Integer times = redisClient.get(key, Integer.class);
 
-		return null != times && times > 5;
+		if (null == times) {
+			times = 0;
+		}
+
+		return times;
 	}
 
 	/**