setEmail(getModel().getEmail());
return changePasswordGeneric();
}
public String changePasswordGeneric() {
User user = (User) getModel();
if (user == null) return ERROR;
SecurityModel.checkAllowed(Operation.WRITE, user);
if (oldPassword == null && newPassword == null) return INPUT;
if (!getCurrentUser().getAccessLevel().getIsSuperUser() && !user.checkPassword(oldPassword))
{
log.warn(String.format("%s Failed password change - wrong current password for %s", getRequestSource(), user.getEmail()));
addActionError("Current password supplied is incorrect. Please try again");
return INPUT;
}
if (newPassword == null || newPassword.length() == 0 )
{
log.info(String.format("%s Failed password change - missing new password for %s", getRequestSource(), user.getEmail()));
addActionError("A new password must be supplied.");
return INPUT;
}
if (!newPassword.equals(newPasswordConfirm))
{
log.info(String.format("%s Failed password change - new passwords didn't match for %s", getRequestSource(), user.getEmail()));
addActionError("The new password and the confirmation of the new password must be the same.");
return INPUT;
}
user.setPassword(newPassword);
CannedQueries.save(user);
log.warn(String.format("%s Password for %s changed", getRequestSource(), user.getEmail()));
addActionMessage("Password for user '"+user.getName()+"' successfully changed.");
return SUCCESS;
}