|
|
@@ -15,6 +15,7 @@ import com.baomidou.mybatisplus.core.toolkit.StringPool;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.google.gson.JsonArray;
|
|
|
import com.google.gson.JsonObject;
|
|
|
+import com.google.gson.JsonParser;
|
|
|
import com.xjrsoft.common.constant.GlobalConstant;
|
|
|
import com.xjrsoft.common.enums.EnabledMark;
|
|
|
import com.xjrsoft.common.enums.RoleEnum;
|
|
|
@@ -40,6 +41,7 @@ import lombok.AllArgsConstructor;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.time.LocalDateTime;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
import java.time.temporal.ChronoUnit;
|
|
|
import java.util.List;
|
|
|
import java.util.UUID;
|
|
|
@@ -85,10 +87,12 @@ public class LoginServiceImpl implements ILoginService {
|
|
|
public LoginVo login(LoginDto dto) throws Exception {
|
|
|
if(redisUtil.containsKey(dto.getUserName() + loginLockKey )){
|
|
|
|
|
|
- LocalDateTime dateTime = redisUtil.get(dto.getUserName() + loginLockKey, LocalDateTime.class);
|
|
|
- long minutes = ChronoUnit.MINUTES.between(LocalDateTime.now(), dateTime);
|
|
|
+ String dateTime = redisUtil.get(dto.getUserName() + loginLockKey);
|
|
|
+ long minutes = ChronoUnit.MINUTES.between(LocalDateTime.now(), LocalDateTime.parse(dateTime, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
|
|
|
|
|
throw new MyException("账户被锁定!请在" + minutes + "分钟后重新登录");
|
|
|
+ }else{
|
|
|
+ redisUtil.delete(dto.getUserName() + loginLockKey);
|
|
|
}
|
|
|
if (licenseConfig.getEnabled()) {
|
|
|
//查出所有在线用户
|
|
|
@@ -122,25 +126,33 @@ public class LoginServiceImpl implements ILoginService {
|
|
|
|
|
|
if (loginUser == null || !BCrypt.checkpw(dto.getPassword(), loginUser.getPassword())) {
|
|
|
if(loginUser != null){
|
|
|
+ JsonParser parser = new JsonParser();
|
|
|
JsonObject loginErrorJson;
|
|
|
if(!redisUtil.containsKey(loginErrorKey)){
|
|
|
//第一次登录失败
|
|
|
loginErrorJson = new JsonObject();
|
|
|
loginErrorJson.addProperty(loginUser.getId().toString(), 1);
|
|
|
+ redisUtil.set(loginErrorKey, loginErrorJson.toString());
|
|
|
}else{
|
|
|
- loginErrorJson = redisUtil.get(loginErrorKey, JsonObject.class);
|
|
|
- int count = loginErrorJson.get(loginUser.getId().toString()).getAsInt();
|
|
|
- if(count == 3){
|
|
|
- //密码错误3次,锁定登录
|
|
|
- LocalDateTime now = LocalDateTime.now();
|
|
|
- now.plusMinutes(10);
|
|
|
- redisUtil.set(loginUser.getUserName() + loginLockKey, now, 600);
|
|
|
- //锁定之后,清空次数计算
|
|
|
- loginErrorJson.remove(loginUser.getId().toString());
|
|
|
- redisUtil.set(loginErrorKey, loginErrorJson);
|
|
|
+ loginErrorJson = parser.parse(redisUtil.get(loginErrorKey)).getAsJsonObject();
|
|
|
+
|
|
|
+ if(loginErrorJson.has(loginUser.getId().toString())){
|
|
|
+ int count = loginErrorJson.get(loginUser.getId().toString()).getAsInt();
|
|
|
+ if(count == 2){
|
|
|
+ //密码错误3次,锁定登录
|
|
|
+ LocalDateTime now = LocalDateTime.now();
|
|
|
+ now = now.plusMinutes(10);
|
|
|
+ redisUtil.set(loginUser.getUserName() + loginLockKey, now.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")), 600);
|
|
|
+ //锁定之后,清空次数计算
|
|
|
+ loginErrorJson.remove(loginUser.getId().toString());
|
|
|
+ redisUtil.set(loginErrorKey, loginErrorJson.toString());
|
|
|
+ }else{
|
|
|
+ loginErrorJson.addProperty(loginUser.getId().toString(), count + 1);
|
|
|
+ redisUtil.set(loginErrorKey, loginErrorJson.toString());
|
|
|
+ }
|
|
|
}else{
|
|
|
- loginErrorJson.addProperty(loginUser.getId().toString(), count + 1);
|
|
|
- redisUtil.set(loginErrorKey, loginErrorJson);
|
|
|
+ loginErrorJson.addProperty(loginUser.getId().toString(), 1);
|
|
|
+ redisUtil.set(loginErrorKey, loginErrorJson.toString());
|
|
|
}
|
|
|
}
|
|
|
}
|