WANG 6 年之前
父節點
當前提交
8779cbbe0f

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

@@ -195,7 +195,7 @@ public class AuthServiceImpl implements AuthService {
 			}
 			}
 			String rightPassword = userEntity.getPassword();
 			String rightPassword = userEntity.getPassword();
 			if (!rightPassword.equals(password)) {
 			if (!rightPassword.equals(password)) {
-				whenPasswordError(accountTypeEnum, accountValue, clientIp);
+				whenError(accountTypeEnum, accountValue, clientIp);
 				throw new StatusException("B-001003", "账号或密码错误");
 				throw new StatusException("B-001003", "账号或密码错误");
 			}
 			}
 			user.setUserId(userEntity.getId());
 			user.setUserId(userEntity.getId());
@@ -226,7 +226,12 @@ public class AuthServiceImpl implements AuthService {
 			// 验证码登录
 			// 验证码登录
 			if (AccountType.STUDENT_PHONE.equals(accountTypeEnum)
 			if (AccountType.STUDENT_PHONE.equals(accountTypeEnum)
 					&& StringUtils.isNotBlank(smsCode)) {
 					&& StringUtils.isNotBlank(smsCode)) {
-				smsCodeService.checkSmsCode(accountValue, smsCode);
+				try {
+					smsCodeService.checkSmsCode(accountValue, smsCode);
+				} catch (Exception e) {
+					whenError(accountTypeEnum, accountValue, clientIp);
+					throw e;
+				}
 			}
 			}
 			// 密码登录
 			// 密码登录
 			else {
 			else {
@@ -235,7 +240,7 @@ public class AuthServiceImpl implements AuthService {
 				}
 				}
 				String rightPassword = student.getPassword();
 				String rightPassword = student.getPassword();
 				if (!rightPassword.equals(password)) {
 				if (!rightPassword.equals(password)) {
-					whenPasswordError(accountTypeEnum, accountValue, clientIp);
+					whenError(accountTypeEnum, accountValue, clientIp);
 					throw new StatusException("B-001003", "账号或密码错误");
 					throw new StatusException("B-001003", "账号或密码错误");
 				}
 				}
 			}
 			}
@@ -256,7 +261,12 @@ public class AuthServiceImpl implements AuthService {
 				String phone = PropertiesUtil.getString("$login.admin.smsCode.phone");
 				String phone = PropertiesUtil.getString("$login.admin.smsCode.phone");
 				// 验证码不为空时,校验验证码
 				// 验证码不为空时,校验验证码
 				if (StringUtils.isNotBlank(smsCode)) {
 				if (StringUtils.isNotBlank(smsCode)) {
-					smsCodeService.checkSmsCode(phone, smsCode);
+					try {
+						smsCodeService.checkSmsCode(phone, smsCode);
+					} catch (Exception e) {
+						whenError(accountTypeEnum, accountValue, clientIp);
+						throw e;
+					}
 				}
 				}
 				// 验证码为空时,发送验证码
 				// 验证码为空时,发送验证码
 				else {
 				else {
@@ -293,15 +303,15 @@ public class AuthServiceImpl implements AuthService {
 	}
 	}
 
 
 	/**
 	/**
-	 * 密码重试限制
+	 * 重试限制
 	 *
 	 *
 	 * @author WANGWEI
 	 * @author WANGWEI
 	 * @param accountType
 	 * @param accountType
 	 * @param accountValue
 	 * @param accountValue
 	 * @param ip
 	 * @param ip
 	 */
 	 */
-	private void whenPasswordError(AccountType accountType, String accountValue, String ip) {
-		String key = new StringBuilder("$_PW_ERR_").append(accountType.getCode()).append("_")
+	private void whenError(AccountType accountType, String accountValue, String ip) {
+		String key = new StringBuilder("$_LOGIN_ERR_").append(accountType.getCode()).append("_")
 				.append(accountValue).append("_").append(ip).toString();
 				.append(accountValue).append("_").append(ip).toString();
 
 
 		Integer times = redisClient.get(key, Integer.class);
 		Integer times = redisClient.get(key, Integer.class);
@@ -324,7 +334,7 @@ public class AuthServiceImpl implements AuthService {
 	 * @return
 	 * @return
 	 */
 	 */
 	private boolean limited(AccountType accountType, String accountValue, String ip) {
 	private boolean limited(AccountType accountType, String accountValue, String ip) {
-		String key = new StringBuilder("$_PW_ERR_").append(accountType.getCode()).append("_")
+		String key = new StringBuilder("$_LOGIN_ERR_").append(accountType.getCode()).append("_")
 				.append(accountValue).append("_").append(ip).toString();
 				.append(accountValue).append("_").append(ip).toString();
 
 
 		Integer times = redisClient.get(key, Integer.class);
 		Integer times = redisClient.get(key, Integer.class);