|
@@ -31,6 +31,9 @@ public class ManageService {
|
|
|
|
|
|
|
|
|
|
public ManageLoginResponse login(String ip,String userName, String password) {
|
|
public ManageLoginResponse login(String ip,String userName, String password) {
|
|
|
|
+
|
|
|
|
+ this.checkLoginNum(ip,userName);
|
|
|
|
+
|
|
if(StringUtils.isBlank(userName) || StringUtils.isBlank(password)){
|
|
if(StringUtils.isBlank(userName) || StringUtils.isBlank(password)){
|
|
throw new BusinessException(ErrorCode.MISSING_REQUIRED_PARAMETERS);
|
|
throw new BusinessException(ErrorCode.MISSING_REQUIRED_PARAMETERS);
|
|
}
|
|
}
|
|
@@ -38,7 +41,7 @@ public class ManageService {
|
|
String passwordMd5 = SecurityUtil.MD52(Base64Converter.decode(Base64Converter.subText(password)));
|
|
String passwordMd5 = SecurityUtil.MD52(Base64Converter.decode(Base64Converter.subText(password)));
|
|
ManageLoginResponse result = sysUserService.getUserByUserNameAndPassword(userName, passwordMd5);
|
|
ManageLoginResponse result = sysUserService.getUserByUserNameAndPassword(userName, passwordMd5);
|
|
if(result == null){
|
|
if(result == null){
|
|
- this.checkLoginNum(ip,userName);
|
|
|
|
|
|
+ this.addLoginErrorNum(ip,userName);
|
|
throw new BusinessException(ResultCode.PASSWORD_ERROR);
|
|
throw new BusinessException(ResultCode.PASSWORD_ERROR);
|
|
}
|
|
}
|
|
StpUtil.login(result.getId(), SaLoginConfig
|
|
StpUtil.login(result.getId(), SaLoginConfig
|
|
@@ -66,6 +69,18 @@ public class ManageService {
|
|
if("5".equals(value)){
|
|
if("5".equals(value)){
|
|
throw new BusinessException(ResultCode.LOGIN_NUM_MUCH);
|
|
throw new BusinessException(ResultCode.LOGIN_NUM_MUCH);
|
|
}
|
|
}
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void addLoginErrorNum(String ip, String userName) {
|
|
|
|
+ if(StringUtils.isNotBlank(userName)){
|
|
|
|
+ String redisKey = String.format(RedisKeyUtil.loginNum,userName,ip);
|
|
|
|
+ if(redisUtil.hasKey(redisKey)){
|
|
|
|
+ String value = redisUtil.get(redisKey);
|
|
|
|
+ if("5".equals(value)){
|
|
|
|
+ throw new BusinessException(ResultCode.LOGIN_NUM_MUCH);
|
|
|
|
+ }
|
|
Integer num = Integer.parseInt(value) + 1;
|
|
Integer num = Integer.parseInt(value) + 1;
|
|
redisUtil.set(redisKey,num.toString(),60 * 5);
|
|
redisUtil.set(redisKey,num.toString(),60 * 5);
|
|
}else {
|
|
}else {
|
|
@@ -73,4 +88,5 @@ public class ManageService {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
}
|
|
}
|