String username = parameters.get("username").toString();
log.debug("username {}", username);
if (username == null || "".equals(username)) {
log.warn("Username not specified, notifying user that it's a required field.");
getSession().error(new NotificationMessage(
new StringResourceModel("errors.required", this, null, new Object[]{"username"})));
throw new RestartResponseException(Login.class);
}
log.debug("Processing Password Hint for username: {}", username);
// look up the user's information
try {
User user = userManager.getUserByUsername(username);
StringBuilder msg = new StringBuilder();
msg.append("Your password hint is: ").append(user.getPasswordHint());
msg.append("\n\nLogin at: ")
.append(RequestCycle.get().getUrlRenderer().renderFullUrl(
Url.parse(urlFor(Login.class, null).toString())));
SimpleMailMessage message = new SimpleMailMessage();
message.setTo(user.getEmail());
String subject = '[' + getString("webapp.name") + "] " + getString("user.passwordHint");
message.setSubject(subject);
message.setText(msg.toString());
log.debug("subject: {}", subject);
log.debug("message: {}", message);
mailEngine.send(message);
getSession().info(createDefaultInfoNotificationMessage(new StringResourceModel(
"login.passwordHint.sent", this, null, new Object[] {username, "provided email address"})));
} catch (UsernameNotFoundException e) {
log.warn(e.getMessage());
// This exception is expected to not be rethrown
getSession().error(new NotificationMessage(new StringResourceModel(
"login.passwordHint.error", this, null, new Object[] {username})));
} catch (MailException me) {
log.error(me.getMessage(), me);
getSession().error(new NotificationMessage(new ResourceModel("errors.sending.email")));
}
throw new RestartResponseException(Login.class);
}