* @return the name of the next view
*/
public View process(HttpServletRequest request, HttpServletResponse response) throws ServletException {
try {
SecurityRealm realm = PebbleContext.getInstance().getConfiguration().getSecurityRealm();
PebbleUserDetails currentUserDetails = SecurityUtils.getUserDetails();
String password1 = request.getParameter("password1");
String password2 = request.getParameter("password2");
String submit = request.getParameter("submit");
// can the user change their user details?
if (!currentUserDetails.isDetailsUpdateable()) {
return new ForbiddenView();
}
if (submit == null || submit.length() == 0) {
return new ChangePasswordView();
}
ValidationContext validationContext = new ValidationContext();
if (password1 == null || password1.length() == 0) {
validationContext.addError("Password can not be empty");
} else if (!password1.equals(password2)) {
validationContext.addError("Passwords do not match");
}
if (!validationContext.hasErrors()) {
realm.changePassword(currentUserDetails.getUsername(), password1);
return new PasswordChangedView();
}
getModel().put("validationContext", validationContext);