|
@@ -11,6 +11,7 @@ import com.fdkankan.manage.common.RedisKeyUtil;
|
|
import com.fdkankan.manage.common.ResultCode;
|
|
import com.fdkankan.manage.common.ResultCode;
|
|
import com.fdkankan.manage.exception.BusinessException;
|
|
import com.fdkankan.manage.exception.BusinessException;
|
|
import com.fdkankan.manage.service.ISysUserService;
|
|
import com.fdkankan.manage.service.ISysUserService;
|
|
|
|
+import com.fdkankan.manage.service.IUserService;
|
|
import com.fdkankan.manage.vo.request.ManageLoginRequest;
|
|
import com.fdkankan.manage.vo.request.ManageLoginRequest;
|
|
import com.fdkankan.manage.vo.response.ManageLoginResponse;
|
|
import com.fdkankan.manage.vo.response.ManageLoginResponse;
|
|
import com.fdkankan.redis.constant.RedisKey;
|
|
import com.fdkankan.redis.constant.RedisKey;
|
|
@@ -25,23 +26,21 @@ import javax.servlet.http.HttpServletRequest;
|
|
public class ManageService {
|
|
public class ManageService {
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
- ISysUserService sysUserService;
|
|
|
|
|
|
+ IUserService userService;
|
|
@Autowired
|
|
@Autowired
|
|
RedisUtil redisUtil;
|
|
RedisUtil redisUtil;
|
|
|
|
|
|
|
|
|
|
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(ResultCode.MISSING_REQUIRED_PARAMETERS);
|
|
throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
|
|
}
|
|
}
|
|
//对前端传的密码解密
|
|
//对前端传的密码解密
|
|
- String passwordMd5 = SecurityUtil.MD52(Base64Converter.decode(Base64Converter.subText(password)));
|
|
|
|
- ManageLoginResponse result = sysUserService.getUserByUserNameAndPassword(userName, passwordMd5);
|
|
|
|
|
|
+ String passwordMd5 = Base64Converter.decode(Base64Converter.subText(password));
|
|
|
|
+ ManageLoginResponse result = userService.getUserByUserNameAndPassword(userName,passwordMd5);
|
|
if(result == null){
|
|
if(result == null){
|
|
- this.addLoginErrorNum(ip,userName);
|
|
|
|
throw new BusinessException(ResultCode.PASSWORD_ERROR);
|
|
throw new BusinessException(ResultCode.PASSWORD_ERROR);
|
|
}
|
|
}
|
|
if(result.getStatus() == 0){
|
|
if(result.getStatus() == 0){
|
|
@@ -53,7 +52,10 @@ public class ManageService {
|
|
.setExtra("userName",result.getUserName())
|
|
.setExtra("userName",result.getUserName())
|
|
.setExtra("nickName",result.getNickName()));
|
|
.setExtra("nickName",result.getNickName()));
|
|
result.setToken(StpUtil.getTokenValue());
|
|
result.setToken(StpUtil.getTokenValue());
|
|
- redisUtil.set(String.format(RedisKeyUtil.loginToken ,result.getToken()), JSONObject.toJSONString(result), 216000);
|
|
|
|
|
|
+
|
|
|
|
+ redisUtil.set(String.format(RedisKeyUtil.loginToken ,result.getToken()), JSONObject.toJSONString(result), 2 * 60 * 60);
|
|
|
|
+ redisUtil.set(RedisKeyUtil.loginTokenUser+userName, result.getToken(),2 * 60 * 60);
|
|
|
|
+
|
|
return result;
|
|
return result;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -64,32 +66,4 @@ public class ManageService {
|
|
StpUtil.logout();
|
|
StpUtil.logout();
|
|
}
|
|
}
|
|
|
|
|
|
- public void checkLoginNum(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);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- 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;
|
|
|
|
- redisUtil.set(redisKey,num.toString(),60 * 5);
|
|
|
|
- }else {
|
|
|
|
- redisUtil.set(redisKey,"1",60 * 5);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
}
|
|
}
|