/**
* OLAT - Online Learning and Training<br>
* http://www.olat.org
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); <br>
* you may not use this file except in compliance with the License.<br>
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing,<br>
* software distributed under the License is distributed on an "AS IS" BASIS, <br>
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br>
* See the License for the specific language governing permissions and <br>
* limitations under the License.
* <p>
* Copyright (c) since 2004 at Multimedia- & E-Learning Services (MELS),<br>
* University of Zurich, Switzerland.
* <p>
*/
package org.olat.user;
import org.olat.core.gui.components.form.Form;
import org.olat.core.gui.formelements.PasswordElement;
import org.olat.core.gui.formelements.SpacerElement;
import org.olat.core.gui.formelements.TitleElement;
import org.olat.core.gui.translator.Translator;
/**
* Initial Date: Jul 14, 2003
*
* @author gnaegi
*
* Comment:
* Form for changing the password. It asks for the old and the new password
*
*/
public class ChangePasswordForm extends Form {
protected static final String FORMNAME = "chpwdform";
protected static final String PASSWORD_OLD = "passwordold";
protected static final String PASSWORD_NEW1 = "passwordnew1";
protected static final String PASSWORD_NEW2 = "passwordnew2";
/**
* @param name
*/
public ChangePasswordForm(String name, Translator translator) {
super(name, translator);
init();
}
/**
* PreferencesForm definition
*/
public void init() {
addFormElement("heading1", new TitleElement("form.please.enter.old"));
addFormElement(PASSWORD_OLD, new PasswordElement("form.password.old", 20, 128));
getPasswordElement(PASSWORD_OLD).setMandatory(true);
addFormElement("spacer1", new SpacerElement(false, true));
addFormElement("heading2", new TitleElement("form.please.enter.new"));
addFormElement(PASSWORD_NEW1, new PasswordElement("form.password.new1", 20, 128));
getPasswordElement(PASSWORD_NEW1).setMandatory(true);
addFormElement(PASSWORD_NEW2, new PasswordElement("form.password.new2", 20, 128));
getPasswordElement(PASSWORD_NEW2).setMandatory(true);
addSubmitKey("save","save");
setCancelButton();
}
/**
* @see org.olat.core.gui.components.Form#validate(org.olat.core.gui.UserRequest)
*/
public boolean validate() {
boolean oldNotEmpty = getPasswordElement(PASSWORD_OLD).notEmpty("error.password.empty");
// validate if new password has does match the syntactical password
// requirements
boolean newIsValid = UserManager.getInstance().syntaxCheckOlatPassword(getPasswordElement(PASSWORD_NEW1).getValue());
if (!newIsValid) getPasswordElement(PASSWORD_NEW1).setErrorKey("error.password.characters");
// validate that both passwords are the same
boolean newDoesMatch = getPasswordElement(PASSWORD_NEW2).isEqual(getPasswordElement(PASSWORD_NEW1).getValue(),
"error.password.nomatch");
return oldNotEmpty && newIsValid && newDoesMatch;
}
/**
* @return Old password field value.
*/
public String getOldPasswordValue() {
return getPasswordElement(PASSWORD_OLD).getValue();
}
/**
* @return New password field value.
*/
public String getNewPasswordValue() {
return getPasswordElement(PASSWORD_NEW1).getValue();
}
}