| | |
| | | /** |
| | | * 登录校验方法 |
| | | * |
| | | * @author ruoyi |
| | | * @author Lion Li |
| | | */ |
| | | @Slf4j |
| | | @Service |
| | |
| | | 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(); |
| | |
| | | * |
| | | * @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); |
| | | } |
| | | } |