2 * Copyright 2005-2010 the original author or authors.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.wamblee.photos.wicket;
18 import java.util.logging.Logger;
19 import javax.inject.Inject;
21 import org.apache.wicket.PageParameters;
22 import org.apache.wicket.markup.html.form.Form;
23 import org.apache.wicket.markup.html.form.PasswordTextField;
24 import org.apache.wicket.model.Model;
25 import org.wamblee.security.authentication.User;
26 import org.wamblee.security.authentication.UserAdministration;
31 public class EditProfilePage extends BasePage {
33 private static final Logger LOGGER = Logger.getLogger(EditProfilePage.class.getName());
35 private static final long serialVersionUID = 1L;
38 private transient User user;
41 private transient UserAdministration userAdmin;
43 private PasswordTextField _currentPassword;
44 private PasswordTextField _password1;
45 private PasswordTextField _password2;
48 * Constructor that is invoked when page is invoked without a session.
50 * @param parameters Page parameters
52 public EditProfilePage(final PageParameters parameters) throws Exception {
55 Form form = new Form("changePasswordForm") {
57 protected void onSubmit() {
58 String current = _currentPassword.getValue();
59 String pw1 = _password1.getValue();
60 String pw2 = _password2.getValue();
61 if (!userAdmin.checkPassword(user.getName(), current)) {
62 error("password invalid");
65 if (!pw1.equals(pw2)) {
66 error("Entered passwords differ");
69 if (userAdmin.changePassword(user.getName(), current, pw1)) {
70 info("Password changed successfully");
71 setResponsePage(HomePage.class);
73 error("Could not change password");
77 _currentPassword = new PasswordTextField("currentPassword", new Model(""));
78 _password1 = new PasswordTextField("password1", new Model(""));
79 _password2 = new PasswordTextField("password2", new Model(""));
80 form.add(_currentPassword);