| | |
| | | import com.cl.common.context.BaseContext; |
| | | import com.cl.common.exception.user.AddUserException; |
| | | import com.cl.common.exception.user.UserException; |
| | | import com.cl.common.result.Result; |
| | | import com.cl.mapper.UserMapper; |
| | | import com.cl.pojo.dto.AddUserDTO; |
| | | import com.cl.pojo.dto.EditUserDTO; |
| | | import com.cl.pojo.dto.PasswordBeforeLoginDTO; |
| | | import com.cl.pojo.dto.PasswordDTO; |
| | | import com.cl.pojo.entity.User; |
| | | import com.cl.pojo.vo.UserVO; |
| | |
| | | updateWrapper.set(User::getPhone, editUserDTO.getPhone()); |
| | | |
| | | updateWrapper.set(User::getRemark, editUserDTO.getRemark()); |
| | | updateWrapper.set(User::getUpdateBy, BaseContext.getCurrentUser().getPhone()); |
| | | updateWrapper.set(User::getUpdateBy, BaseContext.getCurrentUser().getId()); |
| | | updateWrapper.set(User::getUpdateTime, LocalDateTime.now()); |
| | | |
| | | int update = userMapper.update(new User(), updateWrapper); |
| | |
| | | //校验原密码 |
| | | if (!BCryptPasswordEncoder.matches(passwordDTO.getPassword(), user.getPassword())) { |
| | | //不通过 |
| | | throw new UserException("原密码错误"); |
| | | throw new UserException("修改失败,旧密码错误"); |
| | | } |
| | | if (passwordDTO.getPassword().equals(passwordDTO.getNewPassword())){ |
| | | //不通过 |
| | | throw new UserException("修改失败,旧密码与新密码不能一样"); |
| | | } |
| | | //修改密码 |
| | | user.setPassword(BCryptPasswordEncoder.encode(passwordDTO.getNewPassword())); |
| | | user.setUpdateBy(user.getId()); |
| | | user.setUpdateTime(LocalDateTime.now()); |
| | | boolean save = this.save(user); |
| | | boolean save = this.updateById(user); |
| | | if (!save) { |
| | | throw new UserException("修改密码失败"); |
| | | } |
| | | //将令牌加入黑名单 |
| | | tokenBlacklistService.addToBlacklist(token); |
| | | } |
| | | |
| | | @Override |
| | | public Result<String> passwordBeforeLogin(PasswordBeforeLoginDTO passwordDTO) { |
| | | //检查手机号是否存在 |
| | | LambdaQueryWrapper<User> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.eq(User::getPhone, passwordDTO.getPhone()); |
| | | queryWrapper.eq(User::getDelFlag, DelFlagConstant.UNDELETE); |
| | | User user = userMapper.selectOne(queryWrapper); |
| | | if (user == null) { |
| | | return Result.error("手机号不存在"); |
| | | } |
| | | if (user.getStatus().equals(DelFlagConstant.DELETE)) { |
| | | return Result.error("该用户已被冻结"); |
| | | } |
| | | if (!BCryptPasswordEncoder.matches(passwordDTO.getPassword(), user.getPassword())) { |
| | | return Result.error("原密码错误"); |
| | | } |
| | | //修改密码 |
| | | user.setPassword(BCryptPasswordEncoder.encode(passwordDTO.getNewPassword())); |
| | | user.setUpdateBy(user.getId()); |
| | | user.setUpdateTime(LocalDateTime.now()); |
| | | boolean save = this.updateById(user); |
| | | if (!save) { |
| | | throw new UserException("修改密码失败"); |
| | | } |
| | | return Result.success("修改成功"); |
| | | } |
| | | @Override |
| | | public void resetPassword(Integer id) { |
| | | User user = userMapper.selectById(id); |
| | |
| | | user.setIsFirst(1); |
| | | user.setUpdateBy(BaseContext.getCurrentUser().getId()); |
| | | user.setUpdateTime(LocalDateTime.now()); |
| | | boolean save = this.save(user); |
| | | boolean save = this.updateById(user); |
| | | if (!save) { |
| | | throw new UserException("重置密码失败"); |
| | | } |
| | |
| | | user.setStatus(Objects.equals(user.getStatus(), StatusConstant.DISABLE) ? StatusConstant.ENABLE : StatusConstant.DISABLE); |
| | | user.setUpdateBy(BaseContext.getCurrentUser().getId()); |
| | | user.setUpdateTime(LocalDateTime.now()); |
| | | boolean save = this.save(user); |
| | | boolean save = this.updateById(user); |
| | | if (!save) { |
| | | throw new UserException("冻结/解冻用户失败"); |
| | | } |
| | | } |
| | | |
| | | |
| | | } |