From cf6254a8d5fa0b57795531566bf4c9c8fa115eca Mon Sep 17 00:00:00 2001 From: RuoYi Date: Mon, 24 May 2021 14:21:29 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=A8=E6=88=B7=E7=99=BB=E5=BD=95=E5=90=8E?= =?UTF-8?q?=E8=AE=B0=E5=BD=95=E6=9C=80=E5=90=8E=E7=99=BB=E5=BD=95IP&?= =?UTF-8?q?=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../web/service/SysLoginService.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) 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 020831036..c62187949 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 @@ -8,15 +8,20 @@ import org.springframework.security.authentication.UsernamePasswordAuthenticatio 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; import com.ruoyi.common.core.redis.RedisCache; import com.ruoyi.common.exception.CustomException; import com.ruoyi.common.exception.user.CaptchaException; import com.ruoyi.common.exception.user.CaptchaExpireException; import com.ruoyi.common.exception.user.UserPasswordNotMatchException; +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.system.service.ISysUserService; /** * 登录校验方法 @@ -34,6 +39,9 @@ public class SysLoginService @Autowired private RedisCache redisCache; + + @Autowired + private ISysUserService userService; /** * 登录验证 @@ -82,7 +90,18 @@ public class SysLoginService } AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success"))); LoginUser loginUser = (LoginUser) authentication.getPrincipal(); + recordLoginInfo(loginUser.getUser()); // 生成token return tokenService.createToken(loginUser); } + + /** + * 记录登录信息 + */ + public void recordLoginInfo(SysUser user) + { + user.setLoginIp(IpUtils.getIpAddr(ServletUtils.getRequest())); + user.setLoginDate(DateUtils.getNowDate()); + userService.updateUserProfile(user); + } }