Package org.olat.registration

Source Code of org.olat.registration.PwChangeForm

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

import org.olat.core.gui.components.form.Form;
import org.olat.core.gui.formelements.PasswordElement;
import org.olat.core.gui.formelements.TitleElement;
import org.olat.core.gui.translator.Translator;
import org.olat.core.id.Identity;
import org.olat.login.auth.OLATAuthManager;
import org.olat.user.UserManager;

/**
* Description:
*
* @author Sabina Jeger
*/
public class PwChangeForm extends Form {

  private static final String PASSWORD_NEW1 = "passwordnew1";
  private static final String PASSWORD_NEW2 = "passwordnew2";

  /**
   * Password change form.
   * @param name
   */
  public PwChangeForm(String name, Translator translator) {
    super(name, translator);
    init();
  }

  /**
   * PreferencesForm definition
   */
  public void init() {
    addFormElement("heading1", new TitleElement("form.password.enter.new"));
    addFormElement(PASSWORD_NEW1, new PasswordElement("form.password.new1", 255));
    getPasswordElement(PASSWORD_NEW1).setMandatory(true);
    addFormElement(PASSWORD_NEW2, new PasswordElement("form.password.new2", 255));
    getPasswordElement(PASSWORD_NEW2).setMandatory(true);
    addSubmitKey("submit.speichernUndpwchange","submit.speichernUndpwchange");
    setCancelKey("submit.cancel");
  }

  /**
   * @see org.olat.core.gui.components.Form#validate(org.olat.core.gui.UserRequest)
   */
  public boolean validate() {
    // 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("form.password.error.characters");
    // validate that both passwords are the same
    boolean newDoesMatch = getPasswordElement(PASSWORD_NEW2).isEqual(getPasswordElement(PASSWORD_NEW1).getValue(),
        "form.password.error.nomatch");
    return newIsValid && newDoesMatch;
  }

  /**
   * Saves the form data in the user object and the database
   *
   * @param doer The current identity.
   * @param s The identity to change the password.
   */
  public boolean saveFormData(Identity s) {
    String newPwd = getPasswordElement(PASSWORD_NEW1).getValue();
    return OLATAuthManager.changePasswordByPasswordForgottenLink(s, newPwd)
  }
}
TOP

Related Classes of org.olat.registration.PwChangeForm

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.