X-Git-Url: http://wamblee.org/gitweb/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fwamblee%2Fphotos%2Fwicket%2FEditProfilePage.java;h=9351cd4441427df6de9fa404d76352befdde5b45;hb=02397d5c6bbed53e9241f6513480eacdd23870c0;hp=af53c5f1e13044b4602d126de8d19415ebd7bb49;hpb=cf32509dac2f9fa4d44bedf7743f159c5795b7d8;p=photos diff --git a/src/main/java/org/wamblee/photos/wicket/EditProfilePage.java b/src/main/java/org/wamblee/photos/wicket/EditProfilePage.java index af53c5f..9351cd4 100644 --- a/src/main/java/org/wamblee/photos/wicket/EditProfilePage.java +++ b/src/main/java/org/wamblee/photos/wicket/EditProfilePage.java @@ -16,8 +16,14 @@ package org.wamblee.photos.wicket; import java.util.logging.Logger; +import javax.inject.Inject; import org.apache.wicket.PageParameters; +import org.apache.wicket.markup.html.form.Form; +import org.apache.wicket.markup.html.form.PasswordTextField; +import org.apache.wicket.model.Model; +import org.wamblee.security.authentication.User; +import org.wamblee.security.authentication.UserAdministration; /** * Homepage @@ -28,6 +34,16 @@ public class EditProfilePage extends BasePage { private static final long serialVersionUID = 1L; + @Inject + private transient User user; + + @Inject + private transient UserAdministration userAdmin; + + private PasswordTextField _currentPassword; + private PasswordTextField _password1; + private PasswordTextField _password2; + /** * Constructor that is invoked when page is invoked without a session. * @@ -35,5 +51,34 @@ public class EditProfilePage extends BasePage { */ public EditProfilePage(final PageParameters parameters) throws Exception { super(); + + Form form = new Form("changePasswordForm") { + @Override + protected void onSubmit() { + String current = _currentPassword.getValue(); + String pw1 = _password1.getValue(); + String pw2 = _password2.getValue(); + if (!userAdmin.checkPassword(user.getName(), current)) { + error("password invalid"); + return; + } + if (!pw1.equals(pw2)) { + error("Entered passwords differ"); + return; + } + if (userAdmin.changePassword(user.getName(), current, pw1)) { + info("Password changed successfully"); + setResponsePage(HomePage.class); + } + error("Could not change password"); + } + }; + add(form); + _currentPassword = new PasswordTextField("currentPassword", new Model("")); + _password1 = new PasswordTextField("password1", new Model("")); + _password2 = new PasswordTextField("password2", new Model("")); + form.add(_currentPassword); + form.add(_password1); + form.add(_password2); } } \ No newline at end of file