| | |
| | | /** |
| | | * 保存项目介绍密码配置 |
| | | */ |
| | | @Transactional |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void savePasswordConfig(ProjectIntroductionPasswordRequest req) { |
| | | // 验证密码格式 |
| | | if (req.getPasswordEnabled() == 1) { |
| | |
| | | } |
| | | passwordMapper.insert(config); |
| | | } else { |
| | | // 更新 |
| | | config.setPasswordEnabled(req.getPasswordEnabled()); |
| | | // 更新 - 使用自定义SQL支持设置为null |
| | | String encodedPassword = null; |
| | | if (req.getPasswordEnabled() == 1 && StrUtil.isNotBlank(req.getPassword())) { |
| | | config.setPassword(passwordEncoder.encode(req.getPassword())); |
| | | } else { |
| | | // 不启用密码时,清空密码 |
| | | config.setPassword(null); |
| | | encodedPassword = passwordEncoder.encode(req.getPassword()); |
| | | } |
| | | passwordMapper.updateById(config); |
| | | passwordMapper.updatePasswordConfig(config.getId(), req.getPasswordEnabled(), encodedPassword); |
| | | } |
| | | } |
| | | |
| | |
| | | && !config.getPassword().isEmpty() |
| | | && passwordEncoder.matches(inputPassword, config.getPassword()); |
| | | } |
| | | |
| | | /** |
| | | * 检查项目介绍是否启用密码访问 |
| | | */ |
| | | public boolean isPasswordEnabled() { |
| | | ProjectIntroductionPassword config = passwordMapper.selectOne( |
| | | new LambdaQueryWrapper<ProjectIntroductionPassword>() |
| | | .eq(ProjectIntroductionPassword::getPasswordEnabled, 1) |
| | | .orderByAsc(ProjectIntroductionPassword::getId) |
| | | .last("limit 1") |
| | | ); |
| | | return config != null; |
| | | } |
| | | } |