From 0293e06edd011d6921ec2cc08392042f5765dfb8 Mon Sep 17 00:00:00 2001
From: liusheng <337615773@qq.com>
Date: 星期四, 18 九月 2025 13:35:54 +0800
Subject: [PATCH] 日志修改
---
ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java | 132 ++++++++++++++++++++++++-------------------
1 files changed, 74 insertions(+), 58 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 3dcc042..d5ea1c8 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
@@ -3,9 +3,12 @@
import javax.annotation.Resource;
import com.ruoyi.common.core.domain.AjaxResult;
+import com.ruoyi.common.exception.base.BaseException;
import com.ruoyi.common.exception.user.WxOpenIDNotFindException;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.framework.wxopenidConfig.WxOpenIDAuthenticationToken;
+import com.ruoyi.system.mapper.SysUserMapper;
+import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.BadCredentialsException;
@@ -31,12 +34,12 @@
/**
* 鐧诲綍鏍¢獙鏂规硶
- *
+ *
* @author ruoyi
*/
+@Slf4j
@Component
-public class SysLoginService
-{
+public class SysLoginService {
@Autowired
private TokenService tokenService;
@@ -45,47 +48,62 @@
@Autowired
private RedisCache redisCache;
-
+
@Autowired
private ISysUserService userService;
@Autowired
private ISysConfigService configService;
+
+ @Autowired
+ private SysUserMapper sysUserMapper;
+
/**
* 鐧诲綍楠岃瘉
- *
+ *
* @param username 鐢ㄦ埛鍚�
* @param password 瀵嗙爜
- * @param code 楠岃瘉鐮�
- * @param uuid 鍞竴鏍囪瘑
+ * @param code 楠岃瘉鐮�
+ * @param uuid 鍞竴鏍囪瘑
* @return 缁撴灉
*/
- public String login(String username, String password, String code, String uuid, String openId)
- {
+ public String login(String username, String password, String code, String uuid, String openId, String dingUserId) {
+ log.info("username鏄惁涓虹┖锛歿},password鏄惁涓虹┖锛歿},dingUserId鏄惁涓虹┖锛歿}", username, password, dingUserId);
+ //鍏嶇櫥
+ if (StringUtils.isNotEmpty(dingUserId)) {
+ SysUser sysUser = sysUserMapper.selectUserByDingUserId(dingUserId);
+ LoginUser loginUser = new LoginUser();
+ loginUser.setUserId(sysUser.getUserId());
+ loginUser.setDeptId(sysUser.getDeptId());
+ loginUser.setUser(sysUser);
+ return tokenService.createToken(loginUser);
+ }
+
+ SysUser sysUser = sysUserMapper.selectUserByUserName(username);
+ //鑾峰彇閿佸畾娆℃暟
+ String s = configService.selectConfigByKey("sys.opo.lockpwd");
+ if (sysUser.getErrorNums() >= Integer.valueOf(s)) {
+ //鏍¢獙澶辫触娆℃暟
+ throw new BaseException("浣犵殑瀵嗙爜杈撳叆閿欒娆℃暟杩囧锛岃鑱旂郴绠$悊鍛樺鐞�");
+ }
+
boolean captchaOnOff = configService.selectCaptchaOnOff();
// 楠岃瘉鐮佸紑鍏�
- if (captchaOnOff)
- {
+ if (captchaOnOff) {
validateCaptcha(username, code, uuid);
}
// 鐢ㄦ埛楠岃瘉
Authentication authentication = null;
- try
- {
+ try {
// 璇ユ柟娉曚細鍘昏皟鐢║serDetailsServiceImpl.loadUserByUsername
- authentication = authenticationManager
- .authenticate(new UsernamePasswordAuthenticationToken(username, password));
- }
- catch (Exception e)
- {
- if (e instanceof BadCredentialsException)
- {
+ authentication = authenticationManager.authenticate(new UsernamePasswordAuthenticationToken(username, password));
+ } catch (Exception e) {
+ if (e instanceof BadCredentialsException) {
AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.password.not.match")));
+ sysUserMapper.updateErrorNums(sysUser);
throw new UserPasswordNotMatchException();
- }
- else
- {
+ } else {
AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, e.getMessage()));
throw new ServiceException(e.getMessage());
}
@@ -97,52 +115,44 @@
//鏇存柊openid
String userOpenId = user.getOpenId();
- if(StringUtils.isEmpty(openId))
- {
+ if (StringUtils.isEmpty(openId)) {
recordLoginInfo(loginUser.getUserId());
- }else
- {
- if(StringUtils.isNotEmpty(userOpenId))
- {
+ } else {
+ if (StringUtils.isNotEmpty(userOpenId)) {
//褰撴湰娆$櫥褰曠殑寰俊OPENID涓嶇瓑浜庣涓�娆$粦瀹氱殑寰俊OPENID灏变笉鍏佽鐧诲綍锛岄槻姝㈠悓涓�涓处鍙峰寰俊鐧诲綍
- if(!userOpenId.equals(openId))
- {
+ if (!userOpenId.equals(openId)) {
AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, "璇ヨ处鎴峰凡缁忕粦瀹氬叾浠栬澶囷紝椤诲厛瑙i櫎缁戝畾鍐嶇櫥褰曪紝璇疯窡绯荤粺绠$悊鍛樿仈绯伙紒"));
throw new ServiceException("璇ヨ处鎴峰凡缁忕粦瀹氬叾浠栬澶囷紝椤诲厛瑙i櫎缁戝畾鍐嶇櫥褰曪紝璇疯窡绯荤粺绠$悊鍛樿仈绯伙紒");
- }else
- {
+ } else {
recordLoginInfo(loginUser.getUserId());
}
- }else
- {
+ } else {
recordLoginInfo(loginUser.getUserId(), openId);
}
}
-
+ //娓呴櫎澶辫触娆℃暟
+ sysUserMapper.cleanErrorNums(username);
// 鐢熸垚token
return tokenService.createToken(loginUser);
}
/**
* 鏍¢獙楠岃瘉鐮�
- *
+ *
* @param username 鐢ㄦ埛鍚�
- * @param code 楠岃瘉鐮�
- * @param uuid 鍞竴鏍囪瘑
+ * @param code 楠岃瘉鐮�
+ * @param uuid 鍞竴鏍囪瘑
* @return 缁撴灉
*/
- public void validateCaptcha(String username, String code, String uuid)
- {
+ public void validateCaptcha(String username, String code, String uuid) {
String verifyKey = Constants.CAPTCHA_CODE_KEY + uuid;
String captcha = redisCache.getCacheObject(verifyKey);
redisCache.deleteObject(verifyKey);
- if (captcha == null)
- {
+ if (captcha == null) {
AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.jcaptcha.expire")));
throw new CaptchaExpireException();
}
- if (!code.equalsIgnoreCase(captcha))
- {
+ if (!code.equalsIgnoreCase(captcha)) {
AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.jcaptcha.error")));
throw new CaptchaException();
}
@@ -155,20 +165,15 @@
* @return 缁撴灉
*/
- public AjaxResult wxopenidLogin(String openid)
- {
+ public AjaxResult wxopenidLogin(String openid) {
// 鐢ㄦ埛楠岃瘉
Authentication authentication = null;
- try
- {
+ try {
// 璇ユ柟娉曚細鍘昏皟鐢║serDetailsServiceImpl.loadUserByUsername
- authentication = authenticationManager
- .authenticate(new WxOpenIDAuthenticationToken(openid));
- }
- catch (Exception e)
- {
+ authentication = authenticationManager.authenticate(new WxOpenIDAuthenticationToken(openid));
+ } catch (Exception e) {
AsyncManager.me().execute(AsyncFactory.recordLogininfor(openid, Constants.LOGIN_FAIL, e.getMessage()));
throw new WxOpenIDNotFindException();
@@ -184,13 +189,25 @@
return ajax;
}
+ public String getToken(String username, String code) {
+ SysUser sysUser = sysUserMapper.selectUserByDingUserId(code);
+ System.out.println("sysUser鐨勭粨鏋滀负锛�" + sysUser);
+ //鏌ュ嚭鏉ヤ笉瀵圭殑璇濓紝灏辫繑鍥瀗ull
+ if (!sysUser.getUserName().trim().equals(username.trim())) return null;
+
+ LoginUser loginUser = new LoginUser();
+ loginUser.setUserId(sysUser.getUserId());
+ loginUser.setDeptId(sysUser.getDeptId());
+ loginUser.setUser(sysUser);
+ return tokenService.createToken(loginUser);
+ }
+
/**
* 璁板綍鐧诲綍淇℃伅
*
* @param userId 鐢ㄦ埛ID
*/
- public void recordLoginInfo(Long userId)
- {
+ public void recordLoginInfo(Long userId) {
SysUser sysUser = new SysUser();
sysUser.setUserId(userId);
sysUser.setLoginIp(IpUtils.getIpAddr(ServletUtils.getRequest()));
@@ -199,8 +216,7 @@
}
- public void recordLoginInfo(Long userId, String openId)
- {
+ public void recordLoginInfo(Long userId, String openId) {
SysUser sysUser = new SysUser();
sysUser.setUserId(userId);
sysUser.setOpenId(openId);
--
Gitblit v1.9.3