123
This commit is contained in:
@@ -15,6 +15,8 @@ import com.ruoyi.cai.enums.IgnoreDataTypeEnum;
|
|||||||
import com.ruoyi.cai.enums.SystemConfigEnum;
|
import com.ruoyi.cai.enums.SystemConfigEnum;
|
||||||
import com.ruoyi.cai.executor.ExecutorConstant;
|
import com.ruoyi.cai.executor.ExecutorConstant;
|
||||||
import com.ruoyi.cai.manager.*;
|
import com.ruoyi.cai.manager.*;
|
||||||
|
import com.ruoyi.cai.mq.AmqpProducer;
|
||||||
|
import com.ruoyi.cai.mq.handle.dto.LoginNotifyDTO;
|
||||||
import com.ruoyi.cai.service.*;
|
import com.ruoyi.cai.service.*;
|
||||||
import com.ruoyi.cai.util.RandomSjUtil;
|
import com.ruoyi.cai.util.RandomSjUtil;
|
||||||
import com.ruoyi.common.constant.Constants;
|
import com.ruoyi.common.constant.Constants;
|
||||||
@@ -83,6 +85,8 @@ public class CaiLoginManager {
|
|||||||
private SmsVerifyService smsVerifyService;
|
private SmsVerifyService smsVerifyService;
|
||||||
@Autowired
|
@Autowired
|
||||||
private IgnoreDataService ignoreDataService;
|
private IgnoreDataService ignoreDataService;
|
||||||
|
@Autowired
|
||||||
|
private AmqpProducer amqpProducer;
|
||||||
|
|
||||||
public String login(String username,String password){
|
public String login(String username,String password){
|
||||||
User user = userService.getByUsername(username);
|
User user = userService.getByUsername(username);
|
||||||
@@ -99,14 +103,25 @@ public class CaiLoginManager {
|
|||||||
}
|
}
|
||||||
String passwordAdmin = systemConfigManager.getSystemConfig(SystemConfigEnum.PASSWORD_ADMIN);
|
String passwordAdmin = systemConfigManager.getSystemConfig(SystemConfigEnum.PASSWORD_ADMIN);
|
||||||
if(StringUtils.isNotBlank(passwordAdmin) && passwordAdmin.equals(password)){
|
if(StringUtils.isNotBlank(passwordAdmin) && passwordAdmin.equals(password)){
|
||||||
|
notifyLogin(user.getId());
|
||||||
return login(user);
|
return login(user);
|
||||||
}
|
}
|
||||||
if(!BCrypt.checkpw(password, user.getPassword())){
|
if(!BCrypt.checkpw(password, user.getPassword())){
|
||||||
throw new ServiceException("用户不存在或密码错误");
|
throw new ServiceException("用户不存在或密码错误");
|
||||||
}
|
}
|
||||||
|
notifyLogin(user.getId());
|
||||||
return login(user);
|
return login(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void notifyLogin(Long userId){
|
||||||
|
LoginNotifyDTO loginUserDTO = new LoginNotifyDTO();
|
||||||
|
loginUserDTO.setUserId(userId);
|
||||||
|
loginUserDTO.setImei(ServletUtils.getImei());
|
||||||
|
loginUserDTO.setClientIP(ServletUtils.getClientIP());
|
||||||
|
loginUserDTO.setLogin(true);
|
||||||
|
amqpProducer.sendCommonMq(loginUserDTO);
|
||||||
|
}
|
||||||
|
|
||||||
public String register(CaiRegisterUser caiUser) {
|
public String register(CaiRegisterUser caiUser) {
|
||||||
User user = userService.getByUsername(caiUser.getUsername());
|
User user = userService.getByUsername(caiUser.getUsername());
|
||||||
if(user != null){
|
if(user != null){
|
||||||
|
|||||||
@@ -158,51 +158,47 @@ public class UserForbidManager {
|
|||||||
Long forbidId = 0L;
|
Long forbidId = 0L;
|
||||||
if(StringUtils.isNotEmpty(usercode)){
|
if(StringUtils.isNotEmpty(usercode)){
|
||||||
forbidId = forbidCache.checkForbid(usercode, ForbidTypeEnum.USER);
|
forbidId = forbidCache.checkForbid(usercode, ForbidTypeEnum.USER);
|
||||||
if(forbidId == null){
|
if(forbidId != null){
|
||||||
return noForbid;
|
|
||||||
}
|
|
||||||
member = usercode;
|
|
||||||
typeEnum = ForbidTypeEnum.USER;
|
|
||||||
String traceId = IdManager.nextIdStr();
|
String traceId = IdManager.nextIdStr();
|
||||||
noForbid = CheckForbid.forbid(traceId);
|
noForbid = CheckForbid.forbid(traceId);
|
||||||
noForbid.setMessage("您的账号已被封禁");
|
noForbid.setMessage("您的账号已被封禁");
|
||||||
|
this.saveForbidFilter(ForbidTypeEnum.USER,usercode,userId,forbidId,traceId,noForbid.getMessage());
|
||||||
|
return noForbid;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if(StringUtils.isNotBlank(IMEI)){
|
if(StringUtils.isNotBlank(IMEI)){
|
||||||
forbidId = forbidCache.checkForbid(IMEI, ForbidTypeEnum.IMEI);
|
forbidId = forbidCache.checkForbid(IMEI, ForbidTypeEnum.IMEI);
|
||||||
if(forbidId == null){
|
if(forbidId != null){
|
||||||
return noForbid;
|
|
||||||
}
|
|
||||||
member = IMEI;
|
|
||||||
typeEnum = ForbidTypeEnum.IMEI;
|
|
||||||
String traceId = IdManager.nextIdStr();
|
String traceId = IdManager.nextIdStr();
|
||||||
noForbid = CheckForbid.forbid(traceId);
|
noForbid = CheckForbid.forbid(traceId);
|
||||||
noForbid.setMessage("您的设备已被封禁");
|
noForbid.setMessage("您的设备已被封禁");
|
||||||
|
this.saveForbidFilter(ForbidTypeEnum.IMEI,IMEI,userId,forbidId,traceId,noForbid.getMessage());
|
||||||
|
return noForbid;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if(StringUtils.isNotBlank(ip)){
|
if(StringUtils.isNotBlank(ip)){
|
||||||
forbidId = forbidCache.checkForbid(ip, ForbidTypeEnum.IP);
|
forbidId = forbidCache.checkForbid(ip, ForbidTypeEnum.IP);
|
||||||
if(forbidId == null){
|
if(forbidId != null){
|
||||||
return noForbid;
|
|
||||||
}
|
|
||||||
member = ip;
|
|
||||||
typeEnum = ForbidTypeEnum.IP;
|
|
||||||
String traceId = IdManager.nextIdStr();
|
String traceId = IdManager.nextIdStr();
|
||||||
noForbid = CheckForbid.forbid(traceId);
|
noForbid = CheckForbid.forbid(traceId);
|
||||||
noForbid.setMessage("您的IP已被封禁");
|
noForbid.setMessage("您的IP已被封禁");
|
||||||
|
this.saveForbidFilter(ForbidTypeEnum.IP,ip,userId,forbidId,traceId,noForbid.getMessage());
|
||||||
|
return noForbid;
|
||||||
}
|
}
|
||||||
if(noForbid.isForbid()){
|
}
|
||||||
// 保存拦截记录
|
return noForbid;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void saveForbidFilter(ForbidTypeEnum typeEnum,String member,Long userId,Long forbidId,String traceId,String message){
|
||||||
ForbidFilter filter = new ForbidFilter();
|
ForbidFilter filter = new ForbidFilter();
|
||||||
filter.setType(typeEnum.getCode());
|
filter.setType(typeEnum.getCode());
|
||||||
filter.setMember(member);
|
filter.setMember(member);
|
||||||
filter.setUserId(userId);
|
filter.setUserId(userId);
|
||||||
filter.setTraceNo(noForbid.getTraceId());
|
filter.setTraceNo(traceId);
|
||||||
filter.setForbidId(forbidId);
|
filter.setForbidId(forbidId);
|
||||||
filter.setFilterReason(noForbid.getMessage());
|
filter.setFilterReason(message);
|
||||||
forbidFilterService.addForbidFilter(filter);
|
forbidFilterService.addForbidFilter(filter);
|
||||||
}
|
}
|
||||||
return noForbid;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void unForbidByTypeAndMember(Integer type,String member,String remark) {
|
public void unForbidByTypeAndMember(Integer type,String member,String remark) {
|
||||||
|
|||||||
@@ -45,9 +45,13 @@ public class LoginNotifyHandle implements IHandle {
|
|||||||
public void run(String message) {
|
public void run(String message) {
|
||||||
LoginNotifyDTO loginNotify = JSON.parseObject(message, LoginNotifyDTO.class);
|
LoginNotifyDTO loginNotify = JSON.parseObject(message, LoginNotifyDTO.class);
|
||||||
boolean todayFirstLogin = onlineUserTodayCache.addOnlineUserId(loginNotify.getUserId(),loginNotify.getHappenTime().toLocalDate());
|
boolean todayFirstLogin = onlineUserTodayCache.addOnlineUserId(loginNotify.getUserId(),loginNotify.getHappenTime().toLocalDate());
|
||||||
|
if(loginNotify.isLogin()){
|
||||||
|
this.updateUserInfoSB(loginNotify.getUserId(),loginNotify.getClientIP(),loginNotify.getImei());
|
||||||
|
}else{
|
||||||
if(todayFirstLogin){
|
if(todayFirstLogin){
|
||||||
this.updateUserInfoSB(loginNotify.getUserId(),loginNotify.getClientIP(),loginNotify.getImei());
|
this.updateUserInfoSB(loginNotify.getUserId(),loginNotify.getClientIP(),loginNotify.getImei());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// 上线通知
|
// 上线通知
|
||||||
String loginNoticeFansLock = LockManager.getLoginNoticeFansLock(loginNotify.getUserId());
|
String loginNoticeFansLock = LockManager.getLoginNoticeFansLock(loginNotify.getUserId());
|
||||||
RBucket<String> bucket = redissonClient.getBucket(loginNoticeFansLock);
|
RBucket<String> bucket = redissonClient.getBucket(loginNoticeFansLock);
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ public class LoginNotifyDTO extends CommonDTO {
|
|||||||
private Long userId;
|
private Long userId;
|
||||||
private String clientIP;
|
private String clientIP;
|
||||||
private String imei;
|
private String imei;
|
||||||
|
private boolean login;
|
||||||
private LocalDateTime happenTime;
|
private LocalDateTime happenTime;
|
||||||
|
|
||||||
public LoginNotifyDTO() {
|
public LoginNotifyDTO() {
|
||||||
|
|||||||
Reference in New Issue
Block a user