|
|
@@ -243,6 +243,12 @@ public class UserService {
|
|
|
return setPassword(userId, password);
|
|
|
}
|
|
|
|
|
|
+ public String forgotPassword(String phone, String password, String code) {
|
|
|
+ User user = userRepo.findByPhoneAndDelFalse(phone).orElseThrow(new BusinessException("手机号未注册"));
|
|
|
+ smsService.verify(user.getPhone(), code);
|
|
|
+ return setPassword(user.getId(), password);
|
|
|
+ }
|
|
|
+
|
|
|
public void bindPhone(Long userId, String phone) {
|
|
|
User user = userRepo.findByIdAndDelFalse(userId).orElseThrow(new BusinessException("用户不存在"));
|
|
|
if (StringUtils.isNoneEmpty(user.getPhone())) {
|
|
|
@@ -291,4 +297,18 @@ public class UserService {
|
|
|
List<UserDTO> userDTOS = toDTO(users.getContent());
|
|
|
return new PageImpl<>(userDTOS, users.getPageable(), users.getTotalElements());
|
|
|
}
|
|
|
+
|
|
|
+ public void setTradeCode(Long userId, String code, String tradeCode) {
|
|
|
+ User user = userRepo.findById(userId).orElseThrow(new BusinessException("用户不存在"));
|
|
|
+ smsService.verify(user.getPhone(), code);
|
|
|
+ user.setTradeCode(new BCryptPasswordEncoder().encode(tradeCode));
|
|
|
+ userRepo.save(user);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void verifyTradeCode(Long userId, String tradeCode) {
|
|
|
+ User user = userRepo.findById(userId).orElseThrow(new BusinessException("用户不存在"));
|
|
|
+ if (!new BCryptPasswordEncoder().matches(tradeCode, user.getTradeCode())) {
|
|
|
+ throw new BusinessException("校验失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|