JetspeedRunData data = (JetspeedRunData)rundata;
try {
String username = data.getParameters().getString("username", "");
JetspeedUser user = null;
try {
user = JetspeedSecurity.getUser(username);
} catch (JetspeedSecurityException ignored) {
}
if (user == null)
{
data.setScreenTemplate("LoginHelp");
data.setMessage(CustomLocalization.getString("JLOGINUSER_PASSWORDREMINDER_INVALIDUSER", rundata));
if (logger.isDebugEnabled())
logger.debug(CustomLocalization.getString("JLOGINUSER_PASSWORDREMINDER_INVALIDUSER", rundata));
return;
}
user.setHasLoggedIn( Boolean.FALSE);
data.setUser(user);
DynamicURI url = new DynamicURI(data);
//build body via template
StringWriter email_body = new StringWriter();
Context context = TurbineVelocity.getContext(data);
context.put( "data", data );
context.put( "user", user );
context.put("userurl",url);
context.put("config",new JetspeedResources());
//determine the language to be used for the notification email
String lang = (String)user.getPerm("language");
String ctry = (String)user.getPerm("country");
Locale loc = null;
if (lang != null && ctry != null)
{
loc = new Locale(lang,ctry);
}
String templatePath = TemplateLocator.locateEmailTemplate(data, JetspeedResources.getString("password.reminder.template"), loc);
SimpleEmail se = new SimpleEmail();
context.put("email",se);
TurbineVelocity.handleRequest(context, templatePath, email_body);
se.setMsg(email_body.toString());
Properties props = System.getProperties();
String mailServerMachine = JetspeedResources.getString( "mail.server" );
props.put("mail.host", mailServerMachine );
props.put("mail.smtp.host", mailServerMachine);
se.send();
data.setMessage (CustomLocalization.getString("JLOGINUSER_PASSWORDREMINDER_SENT", rundata));
logger.info( "Password for user " + user.getUserName() + " was sent to " + user.getEmail());
logger.info(CustomLocalization.getString("JLOGINUSER_PASSWORDREMINDER_SENT", rundata));
data.setScreenTemplate("Login");
} catch ( Exception e ) {
data.setScreenTemplate("LoginHelp");
String errorTitle = CustomLocalization.getString("JLOGINUSER_PASSWORDREMINDER_ERROR", rundata) ;