init
This commit is contained in:
@@ -91,7 +91,8 @@ public class CaiLoginManager {
|
||||
if(user == null){
|
||||
throw new ServiceException("用户不存在或密码错误");
|
||||
}
|
||||
UserForbidManager.CheckForbid forbid = userForbidManager.checkForbid(user.getId(), user.getUsercode(), null, ServletUtils.getClientIP());
|
||||
String imei = ServletUtils.getImei();
|
||||
UserForbidManager.CheckForbid forbid = userForbidManager.checkForbid(user.getId(), user.getUsercode(), imei, ServletUtils.getClientIP());
|
||||
if(forbid != null && forbid.isForbid()){
|
||||
throw new ServiceException(forbid.getMessage());
|
||||
}
|
||||
@@ -216,7 +217,7 @@ public class CaiLoginManager {
|
||||
}
|
||||
|
||||
|
||||
public void recordLoginInfo(User user, String ip) {
|
||||
public void recordLoginInfo(User user, String ip,String imei) {
|
||||
String address = AddressUtils.getRealAddressByIP(ip);
|
||||
UserInfo userInfo = userInfoService.getById(user.getId());
|
||||
UserInfo update = new UserInfo();
|
||||
@@ -225,6 +226,9 @@ public class CaiLoginManager {
|
||||
update.setLastLoginIp(ip);
|
||||
update.setLastLoginTime(LocalDateTime.now());
|
||||
update.setLastLocation(address);
|
||||
if(StringUtils.isNotBlank(imei)){
|
||||
update.setImei(imei);
|
||||
}
|
||||
userInfoService.updateById(update);
|
||||
}
|
||||
|
||||
@@ -259,7 +263,8 @@ public class CaiLoginManager {
|
||||
LoginHelper.login(loginUser);
|
||||
sysLoginService.recordLogininfor(loginUser.getUsername(), UserType.APP_USER.getUserType(), Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success"));
|
||||
String clientIP = ServletUtils.getClientIP();
|
||||
ExecutorConstant.COMMON_EXECUTOR.execute(() -> recordLoginInfo(user,clientIP));
|
||||
String imei = ServletUtils.getImei();
|
||||
ExecutorConstant.COMMON_EXECUTOR.execute(() -> recordLoginInfo(user,clientIP,imei));
|
||||
return StpUtil.getTokenValue();
|
||||
}
|
||||
|
||||
|
||||
@@ -69,5 +69,9 @@ public class UserInfo {
|
||||
* 注册时间
|
||||
*/
|
||||
private LocalDateTime regTime;
|
||||
/**
|
||||
* 设备号
|
||||
*/
|
||||
private String imei;
|
||||
|
||||
}
|
||||
|
||||
@@ -12,7 +12,8 @@ public class UserForbidInfo {
|
||||
private UserForbid userForbid;
|
||||
private String userForbidBetween;
|
||||
private UserForbid ipUserForbid;
|
||||
|
||||
private String ipForbidBetween;
|
||||
private UserForbid imeiUserForbid;
|
||||
private String imeiForbidBetween;
|
||||
|
||||
}
|
||||
|
||||
@@ -56,7 +56,15 @@ public class UserForbidManager {
|
||||
dto.setRemark(userForbidReq.getReason());
|
||||
this.forbid(dto);
|
||||
}else if(integer == 2){ // 封设备
|
||||
// 封设备
|
||||
UserInfo userInfo = userInfoService.getByUserId(user.getId());
|
||||
if(userInfo != null && StringUtils.isNotEmpty(userInfo.getImei())){
|
||||
UserForbidDTO dto = new UserForbidDTO();
|
||||
dto.setForbidTime(userForbidReq.getForbidTime());
|
||||
dto.setForbidType(ForbidTypeEnum.IMEI.getCode());
|
||||
dto.setMember(userInfo.getImei());
|
||||
dto.setRemark(userForbidReq.getReason());
|
||||
this.forbid(dto);
|
||||
}
|
||||
}else if(integer == 3){ // 封IP
|
||||
UserInfo userInfo = userInfoService.getByUserId(user.getId());
|
||||
if(userInfo != null && StringUtils.isNotEmpty(userInfo.getLastLoginIp())){
|
||||
@@ -113,7 +121,7 @@ public class UserForbidManager {
|
||||
noForbid = CheckForbid.forbid(traceId);
|
||||
noForbid.setMessage("您的账号已被封禁");
|
||||
|
||||
}else if(IMEI != null){
|
||||
}else if(StringUtils.isNotBlank(IMEI)){
|
||||
forbidId = forbidCache.checkForbid(IMEI, ForbidTypeEnum.IMEI);
|
||||
if(forbidId == null){
|
||||
return noForbid;
|
||||
@@ -123,7 +131,7 @@ public class UserForbidManager {
|
||||
String traceId = IdManager.nextIdStr();
|
||||
noForbid = CheckForbid.forbid(traceId);
|
||||
noForbid.setMessage("您的设备已被封禁");
|
||||
}else if(ip != null){
|
||||
}else if(StringUtils.isNotBlank(ip)){
|
||||
forbidId = forbidCache.checkForbid(ip, ForbidTypeEnum.IP);
|
||||
if(forbidId == null){
|
||||
return noForbid;
|
||||
|
||||
@@ -21,6 +21,7 @@ import com.ruoyi.cai.service.UserInfoService;
|
||||
import com.ruoyi.cai.service.UserService;
|
||||
import com.ruoyi.cai.util.CaiDateUtil;
|
||||
import com.ruoyi.common.core.domain.PageQuery;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -118,12 +119,23 @@ public class UserForbidServiceImpl extends ServiceImpl<UserForbidMapper, UserFor
|
||||
userForbidInfo.setUserForbid(userForbid);
|
||||
userForbidInfo.setUserForbidBetween(CaiDateUtil.betweenShowString(LocalDateTime.now(),userForbid.getEndTime()));
|
||||
}
|
||||
UserForbid ipUserForbid = this.getOne(Wrappers.lambdaQuery(UserForbid.class)
|
||||
.eq(UserForbid::getMember, userInfo.getLastLoginIp())
|
||||
.eq(UserForbid::getType, ForbidTypeEnum.IP.getCode()).last("limit 1"));
|
||||
if(ipUserForbid != null && ForbidStatusEnum.FORBID.getCode().equals(ipUserForbid.getForbidStatus()) && ipUserForbid.getEndTime().isAfter(LocalDateTime.now())){
|
||||
userForbidInfo.setIpUserForbid(ipUserForbid);
|
||||
userForbidInfo.setIpForbidBetween(CaiDateUtil.betweenShowString(LocalDateTime.now(),ipUserForbid.getEndTime()));
|
||||
if(StringUtils.isNotBlank(userInfo.getLastLoginIp())){
|
||||
UserForbid ipUserForbid = this.getOne(Wrappers.lambdaQuery(UserForbid.class)
|
||||
.eq(UserForbid::getMember, userInfo.getLastLoginIp())
|
||||
.eq(UserForbid::getType, ForbidTypeEnum.IP.getCode()).last("limit 1"));
|
||||
if(ipUserForbid != null && ForbidStatusEnum.FORBID.getCode().equals(ipUserForbid.getForbidStatus()) && ipUserForbid.getEndTime().isAfter(LocalDateTime.now())){
|
||||
userForbidInfo.setIpUserForbid(ipUserForbid);
|
||||
userForbidInfo.setIpForbidBetween(CaiDateUtil.betweenShowString(LocalDateTime.now(),ipUserForbid.getEndTime()));
|
||||
}
|
||||
}
|
||||
if(StringUtils.isNotBlank(userInfo.getImei())){
|
||||
UserForbid imeiUserForbid = this.getOne(Wrappers.lambdaQuery(UserForbid.class)
|
||||
.eq(UserForbid::getMember, userInfo.getImei())
|
||||
.eq(UserForbid::getType, ForbidTypeEnum.IMEI.getCode()).last("limit 1"));
|
||||
if(imeiUserForbid != null && ForbidStatusEnum.FORBID.getCode().equals(imeiUserForbid.getForbidStatus()) && imeiUserForbid.getEndTime().isAfter(LocalDateTime.now())){
|
||||
userForbidInfo.setImeiUserForbid(imeiUserForbid);
|
||||
userForbidInfo.setImeiForbidBetween(CaiDateUtil.betweenShowString(LocalDateTime.now(),imeiUserForbid.getEndTime()));
|
||||
}
|
||||
}
|
||||
return userForbidInfo;
|
||||
}
|
||||
|
||||
@@ -20,9 +20,11 @@ import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLDecoder;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.attribute.FileTime;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* 客户端工具类
|
||||
@@ -32,6 +34,8 @@ import java.util.Map;
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public class ServletUtils extends ServletUtil {
|
||||
|
||||
private final static String HEAD_UUID = "uuid";
|
||||
|
||||
/**
|
||||
* 获取String参数
|
||||
*/
|
||||
@@ -172,6 +176,10 @@ public class ServletUtils extends ServletUtil {
|
||||
return getClientIP(getRequest());
|
||||
}
|
||||
|
||||
public static String getImei(){
|
||||
return getRequest().getHeader(HEAD_UUID);
|
||||
}
|
||||
|
||||
/**
|
||||
* 内容编码
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user