疯狂的狮子li
2021-10-27 695cb6d76b838b1e4cb161bae335faa948dca12a
ruoyi-system/src/main/java/com/ruoyi/system/service/SysLoginService.java
@@ -22,7 +22,7 @@
/**
 * 登录校验方法
 *
 * @author ruoyi
 * @author Lion Li
 */
@Slf4j
@Service
@@ -64,15 +64,13 @@
            log.info("登录用户:{} 已被停用.", username);
            throw new ServiceException("对不起,您的账号:" + username + " 已停用");
        }
        BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
        String encodePassword = passwordEncoder.encode(password);
        if (SecurityUtils.matchesPassword(user.getPassword(), encodePassword)) {
        if (!SecurityUtils.matchesPassword(password, user.getPassword())) {
            asyncService.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.password.not.match"), request);
            throw new UserPasswordNotMatchException();
        }
      asyncService.recordLogininfor(username, Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success"), request);
        recordLoginInfo(user.getUserId());
        recordLoginInfo(user.getUserId(), username);
        // 生成token
        LoginUtils.loginByDevice(user.getUserId(), UserType.SYS_USER, DeviceType.PC);
        return StpUtil.getTokenValue();
@@ -105,11 +103,12 @@
     *
     * @param userId 用户ID
     */
    public void recordLoginInfo(Long userId) {
    public void recordLoginInfo(Long userId, String username) {
        SysUser sysUser = new SysUser();
        sysUser.setUserId(userId);
        sysUser.setLoginIp(ServletUtils.getClientIP());
        sysUser.setLoginDate(DateUtils.getNowDate());
        sysUser.setUpdateBy(username);
        userService.updateUserProfile(sysUser);
    }
}