|
|
@ -1,5 +1,6 @@
|
|
|
|
package com.ruoyi.framework.web.service;
|
|
|
|
package com.ruoyi.framework.web.service;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
|
import com.ruoyi.common.constant.CacheConstants;
|
|
|
|
import com.ruoyi.common.constant.CacheConstants;
|
|
|
|
import com.ruoyi.common.constant.Constants;
|
|
|
|
import com.ruoyi.common.constant.Constants;
|
|
|
|
import com.ruoyi.common.constant.UserConstants;
|
|
|
|
import com.ruoyi.common.constant.UserConstants;
|
|
|
@ -11,7 +12,11 @@ import com.ruoyi.common.exception.ServiceException;
|
|
|
|
import com.ruoyi.common.exception.user.CaptchaException;
|
|
|
|
import com.ruoyi.common.exception.user.CaptchaException;
|
|
|
|
import com.ruoyi.common.exception.user.CaptchaExpireException;
|
|
|
|
import com.ruoyi.common.exception.user.CaptchaExpireException;
|
|
|
|
import com.ruoyi.common.exception.user.UserPasswordNotMatchException;
|
|
|
|
import com.ruoyi.common.exception.user.UserPasswordNotMatchException;
|
|
|
|
import com.ruoyi.common.utils.*;
|
|
|
|
import com.ruoyi.common.utils.DateUtils;
|
|
|
|
|
|
|
|
import com.ruoyi.common.utils.MessageUtils;
|
|
|
|
|
|
|
|
import com.ruoyi.common.utils.RsaUtils;
|
|
|
|
|
|
|
|
import com.ruoyi.common.utils.ServletUtils;
|
|
|
|
|
|
|
|
import com.ruoyi.common.utils.StringUtils;
|
|
|
|
import com.ruoyi.common.utils.ip.IpUtils;
|
|
|
|
import com.ruoyi.common.utils.ip.IpUtils;
|
|
|
|
import com.ruoyi.framework.manager.AsyncManager;
|
|
|
|
import com.ruoyi.framework.manager.AsyncManager;
|
|
|
|
import com.ruoyi.framework.manager.factory.AsyncFactory;
|
|
|
|
import com.ruoyi.framework.manager.factory.AsyncFactory;
|
|
|
@ -72,7 +77,7 @@ public class SysLoginService {
|
|
|
|
* @return 结果
|
|
|
|
* @return 结果
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public Map<String, Object> login(String username, String password, String code, String uuid, String userType) {
|
|
|
|
public Map<String, Object> login(String username, String password, String code, String uuid, String userType) {
|
|
|
|
String strP = "";
|
|
|
|
String strP;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
strP = RsaUtils.decryptByPrivateKey(password);
|
|
|
|
strP = RsaUtils.decryptByPrivateKey(password);
|
|
|
|
} catch (Exception e) {
|
|
|
|
} catch (Exception e) {
|
|
|
@ -81,9 +86,14 @@ public class SysLoginService {
|
|
|
|
// 验证码校验
|
|
|
|
// 验证码校验
|
|
|
|
// validateCaptcha(username, code, uuid);
|
|
|
|
// validateCaptcha(username, code, uuid);
|
|
|
|
// 登录前置校验
|
|
|
|
// 登录前置校验
|
|
|
|
loginPreCheck(username,strP);
|
|
|
|
loginPreCheck(username, strP);
|
|
|
|
|
|
|
|
Map<String, Object> map = redisCache.getCacheObject(username + password);
|
|
|
|
|
|
|
|
if (CollectionUtil.isNotEmpty(map)) {
|
|
|
|
|
|
|
|
map.remove("@type");
|
|
|
|
|
|
|
|
return map;
|
|
|
|
|
|
|
|
}
|
|
|
|
// 用户验证
|
|
|
|
// 用户验证
|
|
|
|
Authentication authentication = null;
|
|
|
|
Authentication authentication;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(username, strP);
|
|
|
|
UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(username, strP);
|
|
|
|
AuthenticationContextHolder.setContext(authenticationToken);
|
|
|
|
AuthenticationContextHolder.setContext(authenticationToken);
|
|
|
@ -100,14 +110,14 @@ public class SysLoginService {
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
AuthenticationContextHolder.clearContext();
|
|
|
|
AuthenticationContextHolder.clearContext();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success")));
|
|
|
|
// AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success")));
|
|
|
|
LoginUser loginUser = (LoginUser) authentication.getPrincipal();
|
|
|
|
LoginUser loginUser = (LoginUser) authentication.getPrincipal();
|
|
|
|
// recordLoginInfo(loginUser.getUserId());
|
|
|
|
// recordLoginInfo(loginUser.getUserId());
|
|
|
|
if (StringUtils.isNull(loginUser) || StringUtils.isNull(loginUser.getUserId())) {
|
|
|
|
if (StringUtils.isNull(loginUser) || StringUtils.isNull(loginUser.getUserId())) {
|
|
|
|
addRecord(username, Constants.LOGIN_FAIL, "登录用户不存在");
|
|
|
|
// addRecord(username, Constants.LOGIN_FAIL, "登录用户不存在");
|
|
|
|
throw new ServiceException("登录用户:" + username + " 不存在");
|
|
|
|
throw new ServiceException("登录用户:" + username + " 不存在");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
loginUser.getUser().setPassword(password);
|
|
|
|
SysUser user = loginUser.getUser();
|
|
|
|
SysUser user = loginUser.getUser();
|
|
|
|
// 判断用户类型
|
|
|
|
// 判断用户类型
|
|
|
|
if (!"admin".equals(username)) {
|
|
|
|
if (!"admin".equals(username)) {
|
|
|
@ -117,11 +127,11 @@ public class SysLoginService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (UserStatus.DELETED.getCode().equals(user.getDelFlag())) {
|
|
|
|
if (UserStatus.DELETED.getCode().equals(user.getDelFlag())) {
|
|
|
|
addRecord(username, Constants.LOGIN_FAIL, "对不起,您的账号已被删除");
|
|
|
|
// addRecord(username, Constants.LOGIN_FAIL, "对不起,您的账号已被删除");
|
|
|
|
throw new ServiceException("对不起,您的账号:" + username + " 已被删除");
|
|
|
|
throw new ServiceException("对不起,您的账号:" + username + " 已被删除");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (UserStatus.DISABLE.getCode().equals(user.getStatus())) {
|
|
|
|
if (UserStatus.DISABLE.getCode().equals(user.getStatus())) {
|
|
|
|
addRecord(username, Constants.LOGIN_FAIL, "用户已停用,请联系管理员");
|
|
|
|
// addRecord(username, Constants.LOGIN_FAIL, "用户已停用,请联系管理员");
|
|
|
|
throw new ServiceException("对不起,您的账号:" + username + " 已停用");
|
|
|
|
throw new ServiceException("对不起,您的账号:" + username + " 已停用");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// sysPasswordService.validate(user);
|
|
|
|
// sysPasswordService.validate(user);
|
|
|
@ -164,19 +174,19 @@ public class SysLoginService {
|
|
|
|
public void loginPreCheck(String username, String password) {
|
|
|
|
public void loginPreCheck(String username, String password) {
|
|
|
|
// 用户名或密码为空 错误
|
|
|
|
// 用户名或密码为空 错误
|
|
|
|
if (StringUtils.isAnyBlank(username, password)) {
|
|
|
|
if (StringUtils.isAnyBlank(username, password)) {
|
|
|
|
this.addRecord(username, Constants.LOGIN_FAIL, "用户/密码必须填写");
|
|
|
|
// this.addRecord(username, Constants.LOGIN_FAIL, "用户/密码必须填写");
|
|
|
|
throw new ServiceException("用户/密码必须填写");
|
|
|
|
throw new ServiceException("用户/密码必须填写");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// 密码如果不在指定范围内 错误
|
|
|
|
// 密码如果不在指定范围内 错误
|
|
|
|
if (password.length() < UserConstants.PASSWORD_MIN_LENGTH
|
|
|
|
if (password.length() < UserConstants.PASSWORD_MIN_LENGTH
|
|
|
|
|| password.length() > UserConstants.PASSWORD_MAX_LENGTH) {
|
|
|
|
|| password.length() > UserConstants.PASSWORD_MAX_LENGTH) {
|
|
|
|
this.addRecord(username, Constants.LOGIN_FAIL, "用户密码不在指定范围");
|
|
|
|
// this.addRecord(username, Constants.LOGIN_FAIL, "用户密码不在指定范围");
|
|
|
|
throw new ServiceException("用户密码不在指定范围");
|
|
|
|
throw new ServiceException("用户密码不在指定范围");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// 用户名不在指定范围内 错误
|
|
|
|
// 用户名不在指定范围内 错误
|
|
|
|
if (username.length() < UserConstants.USERNAME_MIN_LENGTH
|
|
|
|
if (username.length() < UserConstants.USERNAME_MIN_LENGTH
|
|
|
|
|| username.length() > UserConstants.USERNAME_MAX_LENGTH) {
|
|
|
|
|| username.length() > UserConstants.USERNAME_MAX_LENGTH) {
|
|
|
|
this.addRecord(username, Constants.LOGIN_FAIL, "用户名不在指定范围");
|
|
|
|
// this.addRecord(username, Constants.LOGIN_FAIL, "用户名不在指定范围");
|
|
|
|
throw new ServiceException("用户名不在指定范围");
|
|
|
|
throw new ServiceException("用户名不在指定范围");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|