return loginResult;
}
public ResetPasswordResult resetUserPassword(String username) {
ResetPasswordResult result = new ResetPasswordResult();
// Issue 258:"reset password in effect but lost if error while sending email"
// Part of the fix is to first check the mail account parameters are given:
final String mail_user = config.getMailUser();
final String mail_password = config.getMailPassword();
if ( mail_user == null || mail_user.equals("-") ) {
String error = "Email server account not configured. Please report this bug. (u)";
result.setError(error);
log.error(error);
return result;
}
if ( mail_password == null || mail_password.equals("-") ) {
String error = "Email server account not configured. Please report this bug. (p)";
result.setError(error);
log.error(error);
return result;
}
///////////////////////////////////////////////////////////////
// Get email address for the user
UserInfoResult userInfoResult = getUserInfo(username);
if ( userInfoResult.getError() != null ) {
result.setError(userInfoResult.getError());
return result;
}
final String email = userInfoResult.getProps().get("email");
if ( email == null ) {
result.setError("No email associated with username: " +username);
return result;
}
///////////////////////////////////////////////////////////////
// get new password
String newPassword = Util2.generatePassword();
///////////////////////////////////////////////////////////////
// update password in back-end
Map<String, String> values = userInfoResult.getProps();
values.put("id", userInfoResult.getProps().get("id"));
values.put("password", newPassword);
values.put("sessionid", "4444444444444");
CreateUpdateUserAccountResult updatePwResult = createUpdateUserAccount(values);
if ( updatePwResult.getError() != null ) {
result.setError(updatePwResult.getError());
return result;
}
///////////////////////////////////////////////////////////////
// send email with new password
boolean debug = false;
final String from = "MMI-ORR <techlead@marinemetadata.org>";
final String replyTo = "techlead@marinemetadata.org";
final String subject = "Password reset";
final String text = "Your MMI ORR password has been reset.\n" +
"\n" +
"Username: " +username+ "\n" +
" email: " +email+ "\n" +
"Password: " +newPassword+ "\n" +
"\n"
;
try {
MailSender.sendMessage(mail_user, mail_password, debug , from, email, replyTo, subject, text);
result.setEmail(email);
}
catch (Exception e) {
String error = "Error sending email: " +e.getMessage();
result.setError(error);
log.error(error, e);
}
return result;
}