HttpServletRequest request,
HttpServletResponse response,
Object command,
BindException errors) throws Exception {
User user = (User) command;
String username = user.getUsername().trim();
String userEmail = user.getTmpEmailAddress().trim();
if ( TreebaseUtil.isEmpty(username) && TreebaseUtil.isEmpty(userEmail) ) {
request.setAttribute("errors", "Please provide either user name or email.");
return showForm(request, response, errors);
}
// look up user information
User u = null;
if (!TreebaseUtil.isEmpty(username)) {
u = mUserService.findUserByName(username);
}
else {
List<User> users = mUserService.findUserByEmail(userEmail);
if (users != null && !users.isEmpty()) {
u = users.iterator().next();
}
}
if ( u == null ) {
request.setAttribute("errors", "User name: " + username
+ ", email: " + userEmail
+ ", you have provided does not exist.");
return showForm(request, response, errors);
}
if ( LOGGER.isDebugEnabled() ) {
LOGGER.debug("Server URL: " + generateServerURL(request));
}
//SimpleMailMessage msg = new SimpleMailMessage(this.message);
// XXX start of new stuff
// create mail session
Properties props = new Properties();
props.put("mail.smtp.host", TreebaseUtil.getSmtpHost());
Session mailSession = Session.getDefaultInstance(props,null);
// create email message header information
MimeMessage message = new MimeMessage(mailSession);
message.setRecipient(Message.RecipientType.TO, new InternetAddress(u.getEmailAddressString(),u.getLastName() + ", " + u.getFirstName()));
message.setFrom(new InternetAddress("admin@treebase.org", "TreeBase administrator"));
InternetAddress[] replyTo = { new InternetAddress("admin@treebase.org", "TreeBase administrator") };
message.setReplyTo(replyTo);
message.setRecipient(Message.RecipientType.BCC, new InternetAddress("passwords@treebase.org", "TreeBase passwords"));
message.setSubject("TreeBASE Password", "UTF8");
message.setText(
"To: " + u.getEmailAddressString() + "\n"
+ "Subject: TreeBASE Password\n\n"
+ "Thank you for requesting username/password from TreeBASE.\n\nHere is your username: "
+ u.getUsername() + "\nYour password: "
+ u.getPassword()
+ "\n\nTreebase site: "
+ TreebaseUtil.getSiteUrl());
// + "\n\nTreebase login site: "
// + generateServerURL(request)
// + "/login.jsp");
// send the message
Transport.send(message);
request.setAttribute("messages", getMessageSourceAccessor().getMessage(
"user.password.sent.successful")
+ " (" + u.getEmailAddressString() + ")");
// XXX end of new stuff
/*
// XXX old spring-style mail sending
SimpleMailMessage msg = new SimpleMailMessage();