/* * Copyright 2005-2010 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ 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 */ public class EditProfilePage extends BasePage { private static final Logger LOGGER = Logger.getLogger(EditProfilePage.class.getName()); private static final long serialVersionUID = 1L; @Inject private transient User user; @Inject private transient UserAdministration userAdmin; private PasswordTextField _currentPassword; private PasswordTextField _password1; private PasswordTextField _password2; /** * Constructor that is invoked when page is invoked without a session. * * @param parameters Page parameters */ 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); } }