|
@@ -18,7 +18,10 @@ import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
+import org.springframework.web.context.request.RequestContextHolder;
|
|
|
+import org.springframework.web.context.request.ServletRequestAttributes;
|
|
|
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
import java.util.List;
|
|
|
import java.util.Objects;
|
|
|
import java.util.Random;
|
|
@@ -62,19 +65,22 @@ public class SysLoginService {
|
|
|
|
|
|
// 用户名或密码为空 错误
|
|
|
if (StringUtils.isAnyBlank(username, password)) {
|
|
|
- asyncManager.insertLog(tenantId,username,Constants.LOGIN_FAIL, "用户/密码必须填写", null);
|
|
|
+ HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
|
|
|
+ asyncManager.insertLog(request, tenantId,username,Constants.LOGIN_FAIL, "用户/密码必须填写", null);
|
|
|
throw new BusinessException("用户/密码必须填写");
|
|
|
}
|
|
|
// 密码如果不在指定范围内 错误
|
|
|
if (password.length() < UserConstants.PASSWORD_MIN_LENGTH
|
|
|
|| password.length() > UserConstants.PASSWORD_MAX_LENGTH) {
|
|
|
- asyncManager.insertLog(tenantId,username, Constants.LOGIN_FAIL, "用户密码不在指定范围", null);
|
|
|
+ HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
|
|
|
+ asyncManager.insertLog(request, tenantId,username, Constants.LOGIN_FAIL, "用户密码不在指定范围", null);
|
|
|
throw new BusinessException("用户密码不在指定范围");
|
|
|
}
|
|
|
// 用户名不在指定范围内 错误
|
|
|
if (username.length() < UserConstants.USERNAME_MIN_LENGTH
|
|
|
|| username.length() > UserConstants.USERNAME_MAX_LENGTH) {
|
|
|
- asyncManager.insertLog(tenantId,username, Constants.LOGIN_FAIL, "用户名不在指定范围", null);
|
|
|
+ HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
|
|
|
+ asyncManager.insertLog(request, tenantId,username, Constants.LOGIN_FAIL, "用户名不在指定范围", null);
|
|
|
throw new BusinessException("用户名不在指定范围");
|
|
|
}
|
|
|
|
|
@@ -88,15 +94,18 @@ public class SysLoginService {
|
|
|
|
|
|
SysUserVO user = loginUser.getSysUser();
|
|
|
if (UserStatus.DELETED.getCode().equals(user.getDelFlag())) {
|
|
|
- asyncManager.insertLog(tenantId,username, Constants.LOGIN_FAIL, "对不起,您的账号已被删除", null);
|
|
|
+ HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
|
|
|
+ asyncManager.insertLog(request, tenantId,username, Constants.LOGIN_FAIL, "对不起,您的账号已被删除", null);
|
|
|
throw new BusinessException("对不起,您的账号:" + username + " 已被删除");
|
|
|
}
|
|
|
if (UserStatus.DISABLE.getCode().equals(user.getStatus())) {
|
|
|
- asyncManager.insertLog(tenantId,username, Constants.LOGIN_FAIL, "用户已停用,请联系管理员", null);
|
|
|
+ HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
|
|
|
+ asyncManager.insertLog(request, tenantId,username, Constants.LOGIN_FAIL, "用户已停用,请联系管理员", null);
|
|
|
throw new BusinessException("对不起,您的账号:" + username + " 已停用");
|
|
|
}
|
|
|
if (!SecurityUtils.matchesPassword(password, user.getPassword())) {
|
|
|
- asyncManager.insertLog(tenantId,username, Constants.LOGIN_FAIL, "用户密码错误", null);
|
|
|
+ HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
|
|
|
+ asyncManager.insertLog(request, tenantId,username, Constants.LOGIN_FAIL, "用户密码错误", null);
|
|
|
throw new BusinessException("用户不存在/密码错误");
|
|
|
}
|
|
|
|
|
@@ -109,7 +118,8 @@ public class SysLoginService {
|
|
|
String status = list.get(0).getStatus();
|
|
|
String domain = list.get(0).getDomain();
|
|
|
if(status.equals("1")){
|
|
|
- asyncManager.insertLog(tenantId,username, Constants.LOGIN_FAIL, "系统已停用,请联系管理员", null);
|
|
|
+ HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
|
|
|
+ asyncManager.insertLog(request, tenantId,username, Constants.LOGIN_FAIL, "系统已停用,请联系管理员", null);
|
|
|
throw new BusinessException("对不起,系统已停用,请联系管理员");
|
|
|
}
|
|
|
}
|
|
@@ -128,7 +138,8 @@ public class SysLoginService {
|
|
|
|
|
|
SysPerson sysPerson = sysPersonService.getsysPerson(user.getUserId());
|
|
|
loginUser.setSysPerson(sysPerson);
|
|
|
- asyncManager.insertLog(tenantId,username, Constants.LOGIN_SUCCESS, "登录成功", deptId);
|
|
|
+ HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
|
|
|
+ asyncManager.insertLog(request, tenantId,username, Constants.LOGIN_SUCCESS, "登录成功", deptId);
|
|
|
return loginUser;
|
|
|
}
|
|
|
|
|
@@ -139,31 +150,36 @@ public class SysLoginService {
|
|
|
if (!StringUtils.isBlank(username) && !StringUtils.isBlank(password)) {
|
|
|
// 用户名或密码为空 错误
|
|
|
if (StringUtils.isAnyBlank(username, password)) {
|
|
|
- asyncManager.insertLog(tenantId,loginUser.getUserName(), Constants.LOGIN_FAIL, "用户/密码必须填写", null);
|
|
|
+ HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
|
|
|
+ asyncManager.insertLog(request, tenantId,loginUser.getUserName(), Constants.LOGIN_FAIL, "用户/密码必须填写", null);
|
|
|
throw new BusinessException("用户/密码必须填写");
|
|
|
}
|
|
|
|
|
|
// 密码如果不在指定范围内 错误
|
|
|
if (password.length() < UserConstants.PASSWORD_MIN_LENGTH
|
|
|
|| password.length() > UserConstants.PASSWORD_MAX_LENGTH) {
|
|
|
- asyncManager.insertLog(tenantId,loginUser.getUserName(), Constants.LOGIN_FAIL, "用户密码不在指定范围", null);
|
|
|
+ HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
|
|
|
+ asyncManager.insertLog(request, tenantId,loginUser.getUserName(), Constants.LOGIN_FAIL, "用户密码不在指定范围", null);
|
|
|
throw new BusinessException("用户密码不在指定范围");
|
|
|
}
|
|
|
|
|
|
// 用户名不在指定范围内 错误
|
|
|
if (username.length() < UserConstants.USERNAME_MIN_LENGTH
|
|
|
|| username.length() > UserConstants.USERNAME_MAX_LENGTH) {
|
|
|
- asyncManager.insertLog(tenantId,loginUser.getUserName(), Constants.LOGIN_FAIL, "用户名不在指定范围", null);
|
|
|
+ HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
|
|
|
+ asyncManager.insertLog(request, tenantId,loginUser.getUserName(), Constants.LOGIN_FAIL, "用户名不在指定范围", null);
|
|
|
throw new BusinessException("用户名不在指定范围");
|
|
|
}
|
|
|
loginUser = sysUserService.getAppUserInfo(username, tenantId, null, method);
|
|
|
if (Objects.isNull(loginUser)) {
|
|
|
- asyncManager.insertLog(tenantId,loginUser.getUserName(), Constants.LOGIN_FAIL, "用户不存在", null);
|
|
|
+ HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
|
|
|
+ asyncManager.insertLog(request, tenantId,loginUser.getUserName(), Constants.LOGIN_FAIL, "用户不存在", null);
|
|
|
throw new BusinessException("用户不存在");
|
|
|
}
|
|
|
|
|
|
if (!SecurityUtils.matchesPassword(password, loginUser.getPassword())) {
|
|
|
- asyncManager.insertLog(tenantId,loginUser.getUserName(), Constants.LOGIN_FAIL, "用户密码错误", null);
|
|
|
+ HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
|
|
|
+ asyncManager.insertLog(request, tenantId,loginUser.getUserName(), Constants.LOGIN_FAIL, "用户密码错误", null);
|
|
|
throw new BusinessException("用户不存在/密码错误");
|
|
|
}
|
|
|
} else if(!StringUtils.isBlank(phone) && !StringUtils.isBlank(verify)) {
|
|
@@ -212,11 +228,13 @@ public class SysLoginService {
|
|
|
deptId = sysUser.getDeptId().intValue(); // 将Long转换为Integer
|
|
|
}
|
|
|
if (UserStatus.DELETED.getCode().equals(loginUser.getDelFlag())) {
|
|
|
- asyncManager.insertLog(tenantId,loginUser.getUserName(), Constants.LOGIN_FAIL, "对不起,您的账号已被删除", null);
|
|
|
+ HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
|
|
|
+ asyncManager.insertLog(request, tenantId,loginUser.getUserName(), Constants.LOGIN_FAIL, "对不起,您的账号已被删除", null);
|
|
|
throw new BusinessException("对不起,您的账号:" + username + " 已被删除");
|
|
|
}
|
|
|
if (UserStatus.DISABLE.getCode().equals(loginUser.getStatus())) {
|
|
|
- asyncManager.insertLog(tenantId,loginUser.getUserName(), Constants.LOGIN_FAIL, "用户已停用,请联系管理员", null);
|
|
|
+ HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
|
|
|
+ asyncManager.insertLog(request, tenantId,loginUser.getUserName(), Constants.LOGIN_FAIL, "用户已停用,请联系管理员", null);
|
|
|
throw new BusinessException("对不起,您的账号:" + loginUser.getUserName() + " 已停用");
|
|
|
}
|
|
|
|
|
@@ -225,13 +243,15 @@ public class SysLoginService {
|
|
|
if (loginUser != null && loginUser.getDeptId() != null) {
|
|
|
deptId = loginUser.getDeptId().intValue();
|
|
|
}
|
|
|
- asyncManager.insertLog(tenantId,loginUser.getUserName(), Constants.LOGIN_SUCCESS, "登录成功", deptId);
|
|
|
+ HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
|
|
|
+ asyncManager.insertLog(request, tenantId,loginUser.getUserName(), Constants.LOGIN_SUCCESS, "登录成功", deptId);
|
|
|
return loginUser;
|
|
|
}
|
|
|
|
|
|
|
|
|
public void logout(Integer tenantId,String loginName) {
|
|
|
- asyncManager.insertLog(tenantId,loginName, Constants.LOGOUT, "退出成功", null);
|
|
|
+ HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
|
|
|
+ asyncManager.insertLog(request, tenantId,loginName, Constants.LOGOUT, "退出成功", null);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -257,7 +277,8 @@ public class SysLoginService {
|
|
|
sysUser.setNickName(username);
|
|
|
sysUser.setPassword(SecurityUtils.encryptPassword(password));
|
|
|
sysUserService.register(BeanMapperUtils.map(sysUser, SysUser.class));
|
|
|
- asyncManager.insertLog(SecurityUtils.getTenantId(),username, Constants.REGISTER, "注册成功", null);
|
|
|
+ HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
|
|
|
+ asyncManager.insertLog(request, SecurityUtils.getTenantId(),username, Constants.REGISTER, "注册成功", null);
|
|
|
}
|
|
|
|
|
|
|