small registration fixes

This commit is contained in:
eugenp 2015-02-14 13:57:07 +02:00
parent 1d026ac087
commit 506d0f405d
3 changed files with 18 additions and 6 deletions

View File

@ -23,6 +23,8 @@ public class RegistrationListener implements ApplicationListener<OnRegistrationC
@Autowired @Autowired
private JavaMailSender mailSender; private JavaMailSender mailSender;
// API
@Override @Override
public void onApplicationEvent(OnRegistrationCompleteEvent event) { public void onApplicationEvent(OnRegistrationCompleteEvent event) {
this.confirmRegistration(event); this.confirmRegistration(event);
@ -33,14 +35,23 @@ public class RegistrationListener implements ApplicationListener<OnRegistrationC
String token = UUID.randomUUID().toString(); String token = UUID.randomUUID().toString();
service.createVerificationTokenForUser(user, token); service.createVerificationTokenForUser(user, token);
String recipientAddress = user.getEmail(); final SimpleMailMessage email = constructEmailMessage(event, user, token);
String subject = "Registration Confirmation"; mailSender.send(email);
String confirmationUrl = event.getAppUrl() + "/regitrationConfirm.html?token=" + token; }
String message = messages.getMessage("message.regSucc", null, event.getLocale());
SimpleMailMessage email = new SimpleMailMessage(); //
private final SimpleMailMessage constructEmailMessage(final OnRegistrationCompleteEvent event, final User user, final String token) {
final String recipientAddress = user.getEmail();
final String subject = "Registration Confirmation";
final String confirmationUrl = "http://" + event.getAppUrl() + "/regitrationConfirm.html?token=" + token;
final String message = messages.getMessage("message.regSucc", null, event.getLocale());
final SimpleMailMessage email = new SimpleMailMessage();
email.setTo(recipientAddress); email.setTo(recipientAddress);
email.setSubject(subject); email.setSubject(subject);
email.setText(message + " \r\n" + confirmationUrl); email.setText(message + " \r\n" + confirmationUrl);
mailSender.send(email); email.setFrom("eugen@baeldung.com");
return email;
} }
} }

View File

@ -190,6 +190,7 @@ public class RegistrationController {
userService.createPasswordResetTokenForUser(user, token); userService.createPasswordResetTokenForUser(user, token);
final String appUrl = request.getServerName() + ":" + request.getServerPort() + request.getContextPath(); final String appUrl = request.getServerName() + ":" + request.getServerPort() + request.getContextPath();
final SimpleMailMessage email = constructResetTokenEmail(appUrl, request.getLocale(), token, user); final SimpleMailMessage email = constructResetTokenEmail(appUrl, request.getLocale(), token, user);
email.setFrom("eugen@baeldung.com");
mailSender.send(email); mailSender.send(email);
return new ObjectMapper().writeValueAsString(messages.getMessage("message.resetPassword", null, request.getLocale())); return new ObjectMapper().writeValueAsString(messages.getMessage("message.resetPassword", null, request.getLocale()));