From 7f2921f26b0701c03d0b7a47b08ffe7179291bdf Mon Sep 17 00:00:00 2001
From: 若依 <yzz_ivy@163.com>
Date: 星期一, 06 十二月 2021 20:35:59 +0800
Subject: [PATCH] !382 update 优化查询用户的角色组、岗位组代码 Merge pull request !382 from 疯狂的狮子Li/update
---
ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java | 64 ++++++++++++++++++++++---------
1 files changed, 45 insertions(+), 19 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 c621879..2b54743 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
@@ -11,7 +11,7 @@
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.core.redis.RedisCache;
-import com.ruoyi.common.exception.CustomException;
+import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.exception.user.CaptchaException;
import com.ruoyi.common.exception.user.CaptchaExpireException;
import com.ruoyi.common.exception.user.UserPasswordNotMatchException;
@@ -21,6 +21,7 @@
import com.ruoyi.common.utils.ip.IpUtils;
import com.ruoyi.framework.manager.AsyncManager;
import com.ruoyi.framework.manager.factory.AsyncFactory;
+import com.ruoyi.system.service.ISysConfigService;
import com.ruoyi.system.service.ISysUserService;
/**
@@ -43,6 +44,9 @@
@Autowired
private ISysUserService userService;
+ @Autowired
+ private ISysConfigService configService;
+
/**
* 鐧诲綍楠岃瘉
*
@@ -54,18 +58,11 @@
*/
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)
+ boolean captchaOnOff = configService.selectCaptchaOnOff();
+ // 楠岃瘉鐮佸紑鍏�
+ if (captchaOnOff)
{
- 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();
+ validateCaptcha(username, code, uuid);
}
// 鐢ㄦ埛楠岃瘉
Authentication authentication = null;
@@ -85,23 +82,52 @@
else
{
AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, e.getMessage()));
- throw new CustomException(e.getMessage());
+ throw new ServiceException(e.getMessage());
}
}
AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success")));
LoginUser loginUser = (LoginUser) authentication.getPrincipal();
- recordLoginInfo(loginUser.getUser());
+ recordLoginInfo(loginUser.getUserId());
// 鐢熸垚token
return tokenService.createToken(loginUser);
}
/**
- * 璁板綍鐧诲綍淇℃伅
+ * 鏍¢獙楠岃瘉鐮�
+ *
+ * @param username 鐢ㄦ埛鍚�
+ * @param code 楠岃瘉鐮�
+ * @param uuid 鍞竴鏍囪瘑
+ * @return 缁撴灉
*/
- public void recordLoginInfo(SysUser user)
+ public void validateCaptcha(String username, String code, String uuid)
{
- user.setLoginIp(IpUtils.getIpAddr(ServletUtils.getRequest()));
- user.setLoginDate(DateUtils.getNowDate());
- userService.updateUserProfile(user);
+ 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();
+ }
+ }
+
+ /**
+ * 璁板綍鐧诲綍淇℃伅
+ *
+ * @param userId 鐢ㄦ埛ID
+ */
+ public void recordLoginInfo(Long userId)
+ {
+ SysUser sysUser = new SysUser();
+ sysUser.setUserId(userId);
+ sysUser.setLoginIp(IpUtils.getIpAddr(ServletUtils.getRequest()));
+ sysUser.setLoginDate(DateUtils.getNowDate());
+ userService.updateUserProfile(sysUser);
}
}
--
Gitblit v1.9.3