|
@@ -2,13 +2,16 @@ package com.fdkankan.manage.service.impl;
|
|
|
|
|
|
import cn.dev33.satoken.stp.SaLoginConfig;
|
|
|
import cn.dev33.satoken.stp.StpUtil;
|
|
|
+import cn.hutool.extra.servlet.ServletUtil;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.fdkankan.common.constant.ErrorCode;
|
|
|
import com.fdkankan.common.util.Base64Converter;
|
|
|
import com.fdkankan.common.util.SecurityUtil;
|
|
|
+import com.fdkankan.manage.common.RedisKeyUtil;
|
|
|
import com.fdkankan.manage.common.ResultCode;
|
|
|
import com.fdkankan.manage.exception.BusinessException;
|
|
|
import com.fdkankan.manage.service.ISysUserService;
|
|
|
+import com.fdkankan.manage.vo.request.ManageLoginRequest;
|
|
|
import com.fdkankan.manage.vo.response.ManageLoginResponse;
|
|
|
import com.fdkankan.redis.constant.RedisKey;
|
|
|
import com.fdkankan.redis.util.RedisUtil;
|
|
@@ -16,6 +19,8 @@ import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+
|
|
|
@Service
|
|
|
public class ManageService {
|
|
|
|
|
@@ -25,7 +30,7 @@ public class ManageService {
|
|
|
RedisUtil redisUtil;
|
|
|
|
|
|
|
|
|
- public ManageLoginResponse login(String userName, String password) {
|
|
|
+ public ManageLoginResponse login(String ip,String userName, String password) {
|
|
|
if(StringUtils.isBlank(userName) || StringUtils.isBlank(password)){
|
|
|
throw new BusinessException(ErrorCode.MISSING_REQUIRED_PARAMETERS);
|
|
|
}
|
|
@@ -33,6 +38,7 @@ public class ManageService {
|
|
|
String passwordMd5 = SecurityUtil.MD52(Base64Converter.decode(Base64Converter.subText(password)));
|
|
|
ManageLoginResponse result = sysUserService.getUserByUserNameAndPassword(userName, passwordMd5);
|
|
|
if(result == null){
|
|
|
+ this.checkLoginNum(ip,userName);
|
|
|
throw new BusinessException(ResultCode.PASSWORD_ERROR);
|
|
|
}
|
|
|
StpUtil.login(result.getId(), SaLoginConfig
|
|
@@ -51,4 +57,20 @@ public class ManageService {
|
|
|
redisUtil.del(String.format(RedisKey.TOKEN_V3 ,StpUtil.getTokenValue()));
|
|
|
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(-1,"频繁登录失败,请五分钟后再次尝试登录");
|
|
|
+ }
|
|
|
+ Integer num = Integer.parseInt(value) + 1;
|
|
|
+ redisUtil.set(redisKey,num.toString());
|
|
|
+ }else {
|
|
|
+ redisUtil.set(redisKey,"1",60);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|