@RequestMapping(value = "/sendResetRequest")
public ModelAndView sendResetRequest(HttpServletRequest request) throws HttpException,IOException {
// create a hash for this request
String email = request.getParameter("recover[email]");
Guest guest = guestService.getGuestByEmail(email);
if (guest == null) {
ModelAndView mav = new ModelAndView("support/lostPassword");
mav.addObject("error",
"Sorry, we could not find a user with your email address. Please try again.");
mav.addObject("release", env.get("release"));
return mav;
}
SimpleMailMessage message = new SimpleMailMessage();
message.setTo(email);
// Retrieve postmark properties. Keys postmarkApiKey and postmarkSendAddress should be set
// in common.properties
String postmarkSendAddress = env.get("postmarkSendAddress");
String postmarkApiKey = env.get("postmarkApiKey");
// Process postmarkSendAddress
if(postmarkSendAddress==null) {
postmarkSendAddress = "support@fluxtream.com";
logger.warn("component=support_controller action=sendResetRequest" +
" guestId=" + guest.getId() +
" message=\"**** PLEASE SET postmarkSendAddress IN common.properties; defaulting to support@fluxtream.com\"");
}
message.setFrom(postmarkSendAddress);
// Process postmarkApiKey
if(postmarkApiKey==null) {
logger.error("component=support_controller action=sendResetRequest" +
" guestId=" + guest.getId() +
" message=\"**** PLEASE SET postmarkApiKey IN common.properties. Cannot send reset email without it.\"");
ModelAndView mav = new ModelAndView("support/serverConfigError");
mav.addObject("release", env.get("release"));
mav.addObject("userMessage", "We are not able to send email for resetting your password");
mav.addObject("adminMessage", "Please set up the following keys in common.properties to enable email sending: postmarkApiKey and postmarkSendAddress");
return mav;
}
PostmarkMailSender sender = new PostmarkMailSender(
env.get("postmarkApiKey"));
message.setSubject("Fluxtream Reset password request");
Map<String, String> vars = new HashMap<String, String>();
ResetPasswordToken pToken = guestService.createToken(guest.getId());
vars.put("token", pToken.token);
vars.put("homeBaseUrl", env.get("homeBaseUrl"));
if (guest.firstname != null && !guest.firstname.equals(""))
vars.put("username", guest.firstname);
else