[ Index ]

PHP Cross Reference of moodle-2.8

title

Body

[close]

/login/ -> change_password_form.php (source)

   1  <?php
   2  
   3  // This file is part of Moodle - http://moodle.org/
   4  //
   5  // Moodle is free software: you can redistribute it and/or modify
   6  // it under the terms of the GNU General Public License as published by
   7  // the Free Software Foundation, either version 3 of the License, or
   8  // (at your option) any later version.
   9  //
  10  // Moodle is distributed in the hope that it will be useful,
  11  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13  // GNU General Public License for more details.
  14  //
  15  // You should have received a copy of the GNU General Public License
  16  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  17  
  18  /**
  19   * Change password form definition.
  20   *
  21   * @package    core
  22   * @subpackage auth
  23   * @copyright  2006 Petr Skoda {@link http://skodak.org}
  24   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  25   */
  26  
  27  defined('MOODLE_INTERNAL') || die();
  28  
  29  require_once $CFG->libdir.'/formslib.php';
  30  
  31  class login_change_password_form extends moodleform {
  32  
  33      function definition() {
  34          global $USER, $CFG;
  35  
  36          $mform = $this->_form;
  37          $mform->setDisableShortforms(true);
  38  
  39          $mform->addElement('header', 'changepassword', get_string('changepassword'), '');
  40  
  41          // visible elements
  42          $mform->addElement('static', 'username', get_string('username'), $USER->username);
  43  
  44          if (!empty($CFG->passwordpolicy)){
  45              $mform->addElement('static', 'passwordpolicyinfo', '', print_password_policy());
  46          }
  47          $mform->addElement('password', 'password', get_string('oldpassword'));
  48          $mform->addRule('password', get_string('required'), 'required', null, 'client');
  49          $mform->setType('password', PARAM_RAW);
  50  
  51          $mform->addElement('password', 'newpassword1', get_string('newpassword'));
  52          $mform->addRule('newpassword1', get_string('required'), 'required', null, 'client');
  53          $mform->setType('newpassword1', PARAM_RAW);
  54  
  55          $mform->addElement('password', 'newpassword2', get_string('newpassword').' ('.get_String('again').')');
  56          $mform->addRule('newpassword2', get_string('required'), 'required', null, 'client');
  57          $mform->setType('newpassword2', PARAM_RAW);
  58  
  59  
  60          // hidden optional params
  61          $mform->addElement('hidden', 'id', 0);
  62          $mform->setType('id', PARAM_INT);
  63  
  64          // buttons
  65          if (get_user_preferences('auth_forcepasswordchange')) {
  66              $this->add_action_buttons(false);
  67          } else {
  68              $this->add_action_buttons(true);
  69          }
  70      }
  71  
  72  /// perform extra password change validation
  73      function validation($data, $files) {
  74          global $USER;
  75          $errors = parent::validation($data, $files);
  76  
  77          // ignore submitted username
  78          if (!$user = authenticate_user_login($USER->username, $data['password'], true)) {
  79              $errors['password'] = get_string('invalidlogin');
  80              return $errors;
  81          }
  82  
  83          if ($data['newpassword1'] <> $data['newpassword2']) {
  84              $errors['newpassword1'] = get_string('passwordsdiffer');
  85              $errors['newpassword2'] = get_string('passwordsdiffer');
  86              return $errors;
  87          }
  88  
  89          if ($data['password'] == $data['newpassword1']){
  90              $errors['newpassword1'] = get_string('mustchangepassword');
  91              $errors['newpassword2'] = get_string('mustchangepassword');
  92              return $errors;
  93          }
  94  
  95          $errmsg = '';//prevents eclipse warnings
  96          if (!check_password_policy($data['newpassword1'], $errmsg)) {
  97              $errors['newpassword1'] = $errmsg;
  98              $errors['newpassword2'] = $errmsg;
  99              return $errors;
 100          }
 101  
 102          return $errors;
 103      }
 104  }


Generated: Fri Nov 28 20:29:05 2014 Cross-referenced by PHPXref 0.7.1