| | |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void changePassword(Integer shopId, String newPassword, String token) { |
| | | if (StringUtils.isBlank(newPassword)) { |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "密码不能为空"); |
| | | } |
| | | // 校验密码必须同时包含字母和数字 |
| | | boolean hasLetter = newPassword.chars().anyMatch(Character::isLetter); |
| | | boolean hasDigit = newPassword.chars().anyMatch(Character::isDigit); |
| | | if (!hasLetter || !hasDigit) { |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "密码必须同时包含字母和数字"); |
| | | } |
| | | // 查询门店 |
| | | ShopInfo shopInfo = shopInfoMapper.selectById(shopId); |
| | | if (shopInfo == null || Constants.equalsInteger(shopInfo.getDeleted(), Constants.ONE)) { |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY); |
| | | } |
| | | // 重新生成salt,加密新密码并更新 |
| | | String salt = RandomStringUtils.randomAlphabetic(6); |
| | | shopInfo.setPassword(Utils.Secure.encryptPassword(newPassword, salt)); |
| | | shopInfo.setSalt(salt); |
| | | shopInfoMapper.updateById(shopInfo); |
| | | // 清除token,强制重新登录 |
| | | if (StringUtils.isNotBlank(token)) { |
| | | redisTemplate.delete(token); |
| | | } |
| | | } |
| | | |
| | | } |