// Message Body
String body = "<p>Your new password is: " + newpassword + "</p>";
// Send
new SendMail(new PropertiesManager().getAdminEmailAddress(), ap.getUsername(), subject, body).send("text/html");
// (Remove new password from end of this message once mailing works, Currently attached just so can use)
rp.setResponse(new ResponseObject("Reset Password",true,"Password reset successfully, new password has been emailed to user."));
}//TESTED
else
{ // Two stage process ... first "forgotten password" just sends email containing link to click on
// To avoid people just hitting this button 1000 times, ensure only sent once per 5 minutes
if ((now.getTime() - ap.getModified().getTime()) < 300000L) { // ie 300s ie 5mins
rp.setResponse(new ResponseObject("Reset Password",true,"Password reset request ignored, try later."));
return rp;
}//TESTED
// Update auth to ensure this isn't abused
ap.setModified(now);
DbManager.getSocial().getAuthentication().save(ap.toDb());
//email new password
// Subject Line
String subject = "Request to reset password";
PropertiesManager props = new PropertiesManager();
// Message Body
StringBuffer newLink = new StringBuffer(props.getUrlRoot()).append("auth/forgotpassword").
append("?username=").append(URLEncoder.encode(username, "UTF-8")).
append("&password=").append(URLEncoder.encode(ap.getPassword(), "UTF-8"));
String body = "<p>Click on this link to reset password: " + newLink.toString() + "</p>";
// Send
new SendMail(props.getAdminEmailAddress(), ap.getUsername(), subject, body).send("text/html");
// (Remove new password from end of this message once mailing works, Currently attached just so can use)
rp.setResponse(new ResponseObject("Reset Password",true,"Email has been sent containing link to reset password."));
}//TESTED
}