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