Added edit profile page.
authorErik Brakkee <erik@brakkee.org>
Sun, 29 Sep 2013 15:33:45 +0000 (17:33 +0200)
committerErik Brakkee <erik@brakkee.org>
Sun, 29 Sep 2013 15:33:45 +0000 (17:33 +0200)
src/main/java/org/wamblee/photos/wicket/BasePage.html
src/main/java/org/wamblee/photos/wicket/EditProfilePage.html
src/main/java/org/wamblee/photos/wicket/EditProfilePage.java
src/main/java/org/wamblee/photos/wicket/HomePage.html
src/main/java/org/wamblee/photos/wicket/WicketApplication.java
src/main/java/org/wamblee/photos/wicket/photos.css

index 491f6a63b20ddc9d71a3738e1456d955dcf04d83..18ee2e835d5b9483c6a3570e0ac566a56710f524 100644 (file)
@@ -34,7 +34,7 @@
     <div wicket:id="feedback"></div>
 </div>
 
-<div id="content">
+<div id="main">
     <wicket:child/>
 </div>
 
index 173e1a2a350fcf3ac86934fba66d2de54eefc7cc..2ddfbef485ed6783eb9c8717646bc1ec7a4bdc2d 100644 (file)
 
 <wicket:extend>
 
+    <h1>Edit user profile</h1>
+
+    <form wicket:id="changePasswordForm" method="post">
+        <table>
+            <tr>
+                <td>Current password:</td>
+                <td><input type="password" wicket:id="currentPassword" value=""/></td>
+            </tr>
+            <tr>
+                <td>New password:</td>
+                <td><input type="password" wicket:id="password1"/></td>
+            </tr>
+            <tr>
+                <td>Reenter new password:</td>
+                <td><input type="password" wicket:id="password2"/></td>
+            </tr>
+            <tr>
+                <td></td>
+                <td><input type="submit" value="Submit"/></td>
+            </tr>
+        </table>
+    </form>
+
 </wicket:extend>
 
 </body>
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
index dcd6266aa9c583dd2449648ba36f602ffa3b45cc..87f7e6bc67eaf8e6294f5bb0081f72fb2c0b3544 100644 (file)
@@ -10,8 +10,9 @@
 
 <wicket:extend>
 
-
-    <span wicket:id="content">Content</span>
+    <div id="content">
+        <span wicket:id="content">Content</span>
+    </div>
 
 </wicket:extend>
 
index a1859a70ac3e0d9bbb7d0276d77a52ee922863fb..bac2877bd8fc4554a39ea3f85720c5a5d4e0f2e0 100644 (file)
@@ -55,6 +55,8 @@ public class WicketApplication extends WebApplication {
         settings.setInternalErrorPage(ErrorPage.class);
 
         mount(new MixedParamUrlCodingStrategy("view", HomePage.class, new String[]{"path"}));
+        mount(new MixedParamUrlCodingStrategy("editprofile", EditProfilePage.class, new String[]{}));
+        mount(new MixedParamUrlCodingStrategy("admin", AdminPage.class, new String[]{}));
 
         // Use the lines below to get the internal error page also when in
         // development mode.
index df80436018f16adb770e335faf73980595aced6c..a99f31bc8c6327ffb97b1855c7d2ea590e5d5815 100644 (file)
@@ -2,6 +2,11 @@
 body {
     font-family: sans-serif;
 }
+
+h1 {
+font-size: 1.3em;
+}
+
 /* menu styling */
 
 #menu {