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