疯狂的狮子li
2021-09-26 6f6a3566ac50bcb9bcae4ae68744c9f49b75933c
ruoyi-system/src/main/java/com/ruoyi/system/service/SysLoginService.java
@@ -77,9 +77,14 @@
            asyncService.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.password.not.match"), request);
            throw new UserPasswordNotMatchException();
        }
        else
        {
            asyncService.recordLogininfor(username, Constants.LOGIN_FAIL, e.getMessage(), request);
            throw new ServiceException(e.getMessage());
        }
      asyncService.recordLogininfor(username, Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success"), request);
        recordLoginInfo(user);
        recordLoginInfo(user.getUserId());
        // 生成token
        StpUtil.login(user.getUserId(), "PC");
        return StpUtil.getTokenValue();
@@ -109,12 +114,15 @@
    /**
     * 记录登录信息
     *
     * @param userId 用户ID
     */
    public void recordLoginInfo(SysUser user)
    public void recordLoginInfo(Long userId)
    {
        user.setLoginIp(ServletUtils.getClientIP());
        user.setLoginDate(DateUtils.getNowDate());
      user.setUpdateBy(user.getUserName());
        userService.updateUserProfile(user);
        SysUser sysUser = new SysUser();
        sysUser.setUserId(userId);
        sysUser.setLoginIp(ServletUtils.getClientIP());
        sysUser.setLoginDate(DateUtils.getNowDate());
        userService.updateUserProfile(sysUser);
    }
}