[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/login/ -> forgot_password_form.php (source)

   1  <?php
   2  // This file is part of Moodle - http://moodle.org/
   3  //
   4  // Moodle is free software: you can redistribute it and/or modify
   5  // it under the terms of the GNU General Public License as published by
   6  // the Free Software Foundation, either version 3 of the License, or
   7  // (at your option) any later version.
   8  //
   9  // Moodle is distributed in the hope that it will be useful,
  10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12  // GNU General Public License for more details.
  13  //
  14  // You should have received a copy of the GNU General Public License
  15  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  16  
  17  /**
  18   * Forgot password page.
  19   *
  20   * @package    core
  21   * @subpackage auth
  22   * @copyright  2006 Petr Skoda {@link http://skodak.org}
  23   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24   */
  25  defined('MOODLE_INTERNAL') || die();
  26  
  27  require_once($CFG->libdir.'/formslib.php');
  28  
  29  /**
  30   * Reset forgotten password form definition.
  31   *
  32   * @package    core
  33   * @subpackage auth
  34   * @copyright  2006 Petr Skoda {@link http://skodak.org}
  35   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  36   */
  37  class login_forgot_password_form extends moodleform {
  38  
  39      /**
  40       * Define the forgot password form.
  41       */
  42      function definition() {
  43          $mform    = $this->_form;
  44          $mform->setDisableShortforms(true);
  45  
  46          $mform->addElement('header', 'searchbyusername', get_string('searchbyusername'), '');
  47  
  48          $mform->addElement('text', 'username', get_string('username'));
  49          $mform->setType('username', PARAM_RAW);
  50  
  51          $submitlabel = get_string('search');
  52          $mform->addElement('submit', 'submitbuttonusername', $submitlabel);
  53  
  54          $mform->addElement('header', 'searchbyemail', get_string('searchbyemail'), '');
  55  
  56          $mform->addElement('text', 'email', get_string('email'));
  57          $mform->setType('email', PARAM_RAW_TRIMMED);
  58  
  59          $submitlabel = get_string('search');
  60          $mform->addElement('submit', 'submitbuttonemail', $submitlabel);
  61      }
  62  
  63      /**
  64       * Validate user input from the forgot password form.
  65       * @param array $data array of submitted form fields.
  66       * @param array $files submitted with the form.
  67       * @return array errors occuring during validation.
  68       */
  69      function validation($data, $files) {
  70          global $CFG, $DB;
  71  
  72          $errors = parent::validation($data, $files);
  73  
  74          if ((!empty($data['username']) and !empty($data['email'])) or (empty($data['username']) and empty($data['email']))) {
  75              $errors['username'] = get_string('usernameoremail');
  76              $errors['email']    = get_string('usernameoremail');
  77  
  78          } else if (!empty($data['email'])) {
  79              if (!validate_email($data['email'])) {
  80                  $errors['email'] = get_string('invalidemail');
  81  
  82              } else if ($DB->count_records('user', array('email'=>$data['email'])) > 1) {
  83                  $errors['email'] = get_string('forgottenduplicate');
  84  
  85              } else {
  86                  if ($user = get_complete_user_data('email', $data['email'])) {
  87                      if (empty($user->confirmed)) {
  88                          $errors['email'] = get_string('confirmednot');
  89                      }
  90                  }
  91                  if (!$user and empty($CFG->protectusernames)) {
  92                      $errors['email'] = get_string('emailnotfound');
  93                  }
  94              }
  95  
  96          } else {
  97              if ($user = get_complete_user_data('username', $data['username'])) {
  98                  if (empty($user->confirmed)) {
  99                      $errors['email'] = get_string('confirmednot');
 100                  }
 101              }
 102              if (!$user and empty($CFG->protectusernames)) {
 103                  $errors['username'] = get_string('usernamenotfound');
 104              }
 105          }
 106  
 107          return $errors;
 108      }
 109  
 110  }


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1