From 0140965a30ea1b53dfaf722b1c165b2dbe8c6338 Mon Sep 17 00:00:00 2001
From: 疯狂的狮子li <15040126243@163.com>
Date: 星期四, 17 六月 2021 09:42:00 +0800
Subject: [PATCH] update 优化 jdk11 相关 pr
---
ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java | 64 ++++++++++++++++++--------------
1 files changed, 36 insertions(+), 28 deletions(-)
diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java
index 280ccfd..d0b9511 100644
--- a/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java
+++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java
@@ -1,12 +1,5 @@
package com.ruoyi.framework.web.service;
-import javax.annotation.Resource;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.security.authentication.AuthenticationManager;
-import org.springframework.security.authentication.BadCredentialsException;
-import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
-import org.springframework.security.core.Authentication;
-import org.springframework.stereotype.Component;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.domain.model.LoginUser;
@@ -18,10 +11,17 @@
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.MessageUtils;
import com.ruoyi.common.utils.ServletUtils;
-import com.ruoyi.common.utils.ip.IpUtils;
-import com.ruoyi.framework.manager.AsyncManager;
-import com.ruoyi.framework.manager.factory.AsyncFactory;
+import com.ruoyi.framework.config.properties.CaptchaProperties;
import com.ruoyi.system.service.ISysUserService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.authentication.AuthenticationManager;
+import org.springframework.security.authentication.BadCredentialsException;
+import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
+import org.springframework.security.core.Authentication;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.Resource;
+import javax.servlet.http.HttpServletRequest;
/**
* 鐧诲綍鏍¢獙鏂规硶
@@ -40,8 +40,14 @@
@Autowired
private RedisCache redisCache;
- @Autowired
+ @Autowired
+ private CaptchaProperties captchaProperties;
+
+ @Autowired
private ISysUserService userService;
+
+ @Autowired
+ private AsyncService asyncService;
/**
* 鐧诲綍楠岃瘉
@@ -54,19 +60,20 @@
*/
public String login(String username, String password, String code, String uuid)
{
- String verifyKey = Constants.CAPTCHA_CODE_KEY + uuid;
- String captcha = redisCache.getCacheObject(verifyKey);
- redisCache.deleteObject(verifyKey);
- if (captcha == null)
- {
- AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.jcaptcha.expire")));
- throw new CaptchaExpireException();
- }
- if (!code.equalsIgnoreCase(captcha))
- {
- AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.jcaptcha.error")));
- throw new CaptchaException();
- }
+ HttpServletRequest request = ServletUtils.getRequest();
+ if(captchaProperties.getEnabled()) {
+ String verifyKey = Constants.CAPTCHA_CODE_KEY + uuid;
+ String captcha = redisCache.getCacheObject(verifyKey);
+ redisCache.deleteObject(verifyKey);
+ if (captcha == null) {
+ asyncService.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.jcaptcha.expire"), request);
+ throw new CaptchaExpireException();
+ }
+ if (!code.equalsIgnoreCase(captcha)) {
+ asyncService.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.jcaptcha.error"), request);
+ throw new CaptchaException();
+ }
+ }
// 鐢ㄦ埛楠岃瘉
Authentication authentication = null;
try
@@ -79,16 +86,16 @@
{
if (e instanceof BadCredentialsException)
{
- AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.password.not.match")));
+ asyncService.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.password.not.match"), request);
throw new UserPasswordNotMatchException();
}
else
{
- AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, e.getMessage()));
+ asyncService.recordLogininfor(username, Constants.LOGIN_FAIL, e.getMessage(), request);
throw new CustomException(e.getMessage());
}
}
- AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success")));
+ asyncService.recordLogininfor(username, Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success"), request);
LoginUser loginUser = (LoginUser) authentication.getPrincipal();
recordLoginInfo(loginUser.getUser());
// 鐢熸垚token
@@ -100,8 +107,9 @@
*/
public void recordLoginInfo(SysUser user)
{
- user.setLoginIp(IpUtils.getIpAddr(ServletUtils.getRequest()));
+ user.setLoginIp(ServletUtils.getClientIP());
user.setLoginDate(DateUtils.getNowDate());
+ user.setUpdateBy(user.getUserName());
userService.updateUserProfile(user);
}
}
--
Gitblit v1.9.3