<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>
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
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.
*
*/
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
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.