@RequestMapping(method = RequestMethod.GET) public ModelAndView handleRequest(HttpServletRequest request) throws Exception { log.debug("entering 'handleRequest' method..."); String username = request.getParameter("username"); MessageSourceAccessor text = new MessageSourceAccessor(messageSource, request.getLocale()); // ensure that the username has been sent if (username == null) { log.warn("Username not specified, notifying user that it's a required field."); request.setAttribute( "error", text.getMessage("errors.required", text.getMessage("user.username"))); return new ModelAndView("login"); } log.debug("Processing Password Hint..."); // look up the user's information try { User user = userManager.getUserByUsername(username); StringBuffer msg = new StringBuffer(); msg.append("Your password hint is: ").append(user.getPasswordHint()); msg.append("\n\nLogin at: ").append(RequestUtil.getAppURL(request)); message.setTo(user.getEmail()); String subject = '[' + text.getMessage("webapp.name") + "] " + text.getMessage("user.passwordHint"); message.setSubject(subject); message.setText(msg.toString()); mailEngine.send(message); saveMessage( request, text.getMessage("login.passwordHint.sent", new Object[] {username, user.getEmail()})); } catch (UsernameNotFoundException e) { log.warn(e.getMessage()); saveError(request, text.getMessage("login.passwordHint.error", new Object[] {username})); } catch (MailException me) { log.warn(me.getMessage()); saveError(request, me.getCause().getLocalizedMessage()); } return new ModelAndView(new RedirectView(request.getContextPath())); }
/** * Convenience message to send messages to users, includes app URL as footer. * * @param user the user to send a message to. * @param msg the message to send. * @param url the URL of the application. */ protected void sendUserMessage(User user, String msg, String url) { if (log.isDebugEnabled()) { log.debug("sending e-mail to user [" + user.getEmail() + "]..."); } message.setTo(user.getFullName() + "<" + user.getEmail() + ">"); Map<String, Serializable> model = new HashMap<String, Serializable>(); model.put("user", user); // TODO: once you figure out how to get the global resource bundle in // WebWork, then figure it out here too. In the meantime, the Username // and Password labels are hard-coded into the template. // model.put("bundle", getTexts()); model.put("message", msg); model.put("applicationURL", url); mailEngine.sendMessage(message, templateName, model); }
public void send(User user, String subject, String message, String url, boolean hint) throws UsernameNotFoundException, MailException { StringBuilder msg = new StringBuilder(message); if (!hint) { msg.append("\n\n").append(messages.get("user.username")); msg.append(": ").append(user.getUsername()).append("\n"); msg.append(messages.get("user.password")).append(": "); msg.append(user.getPassword()); } msg.append("\n\nLogin at: ").append(url); simpleMailMessage.setTo(user.getFullName() + "<" + user.getEmail() + ">"); simpleMailMessage.setSubject(subject); simpleMailMessage.setText(msg.toString()); mailEngine.send(simpleMailMessage); }