Added edit profile page.
[photos] / src / main / java / org / wamblee / photos / wicket / EditProfilePage.java
index af53c5f1e13044b4602d126de8d19415ebd7bb49..967bfa630f896c05081d0568b8107bd7069a8a6f 100644 (file)
 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 User user;
+
+    @Inject
+    private 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