@Override
public void sendPasswordReminder(User newUser) {
log.debug("Calling send password change link for user {}", newUser);
User user = userRepository.getByUserEmail(newUser.getEmail());
if (user == null) {
throw new IllegalArgumentException("Could not find user for email " + newUser.getEmail());
}
// create user hash:
String input = user.getEmail() + user.getUsername() + String.valueOf(user.getId()) + System.nanoTime();
// hash needs to be URL friendly:
String safeString = new String(Base64.encode(passwordEncoder.encode(input).getBytes()));
String hashedInput = safeString.replaceAll("[/=]", "A");
user.setForgotPasswordHash(hashedInput);
user.setForgotPasswordTime(Calendar.getInstance().getTime());
userRepository.save(user);
String to = user.getUsername() + " <" + user.getEmail() + '>';
Map<String, Object> templateData = new HashMap<String, Object>();
templateData.put("user", user);
templateData.put("reminderUrl", baseUrl + hashedInput);
emailService.sendEmail(to, passwordReminderSubject, passwordReminderTemplate, templateData);
}