use of pl.pollub.cs.pentagoncafe.flare.exception.ResetPasswordException in project Flare-event-calendar by PollubCafe.
the class SecurityServiceImpl method resetPassword.
@Override
@Transactional(rollbackFor = { MessagingException.class, ObjectNotFoundException.class, ResetPasswordException.class })
public void resetPassword(EmailReqDTO emailReqDTO) {
String recipientAddress = emailReqDTO.getEmail();
User user = userRepository.findByEmail(recipientAddress).orElseThrow(() -> new ObjectNotFoundException(User.class, "e-mail", emailReqDTO.getEmail()));
if (!user.isEnabled()) {
throw new ResetPasswordException(messages.get("login.userAccount.disabled"));
}
if (user.isBanned()) {
throw new ResetPasswordException(messages.get("login.userAccount.locked"));
}
String generatedPassword = RandomPasswordGenerator.generate();
user.setPassword(passwordEncoder.encode(generatedPassword));
userRepository.save(user);
Email resetPasswordEmail = emailBuilder.buildResetPasswordEmail(generatedPassword).to(recipientAddress);
this.sendResetPasswordEmail(resetPasswordEmail);
}
Aggregations