Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/login/forgot_password_form.php
Go to the documentation of this file.
00001 <?php
00002 
00003 // This file is part of Moodle - http://moodle.org/
00004 //
00005 // Moodle is free software: you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation, either version 3 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // Moodle is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00017 
00027 defined('MOODLE_INTERNAL') || die();
00028 
00029 require_once $CFG->libdir.'/formslib.php';
00030 
00031 class login_forgot_password_form extends moodleform {
00032 
00033     function definition() {
00034         $mform    = $this->_form;
00035 
00036         $mform->addElement('header', '', get_string('searchbyusername'), '');
00037 
00038         $mform->addElement('text', 'username', get_string('username'));
00039         $mform->setType('username', PARAM_RAW);
00040 
00041         $submitlabel = get_string('search');
00042         $mform->addElement('submit', 'submitbutton', $submitlabel);
00043 
00044         $mform->addElement('header', '', get_string('searchbyemail'), '');
00045 
00046         $mform->addElement('text', 'email', get_string('email'));
00047         $mform->setType('email', PARAM_RAW);
00048 
00049         $submitlabel = get_string('search');
00050         $mform->addElement('submit', 'submitbutton', $submitlabel);
00051     }
00052 
00053     function validation($data, $files) {
00054         global $CFG, $DB;
00055 
00056         $errors = parent::validation($data, $files);
00057 
00058         if ((!empty($data['username']) and !empty($data['email'])) or (empty($data['username']) and empty($data['email']))) {
00059             $errors['username'] = get_string('usernameoremail');
00060             $errors['email']    = get_string('usernameoremail');
00061 
00062         } else if (!empty($data['email'])) {
00063             if (!validate_email($data['email'])) {
00064                 $errors['email'] = get_string('invalidemail');
00065 
00066             } else if ($DB->count_records('user', array('email'=>$data['email'])) > 1) {
00067                 $errors['email'] = get_string('forgottenduplicate');
00068 
00069             } else {
00070                 if ($user = get_complete_user_data('email', $data['email'])) {
00071                     if (empty($user->confirmed)) {
00072                         $errors['email'] = get_string('confirmednot');
00073                     }
00074                 }
00075                 if (!$user and empty($CFG->protectusernames)) {
00076                     $errors['email'] = get_string('emailnotfound');
00077                 }
00078             }
00079 
00080         } else {
00081             if ($user = get_complete_user_data('username', $data['username'])) {
00082                 if (empty($user->confirmed)) {
00083                     $errors['email'] = get_string('confirmednot');
00084                 }
00085             }
00086             if (!$user and empty($CFG->protectusernames)) {
00087                 $errors['username'] = get_string('usernamenotfound');
00088             }
00089         }
00090 
00091         return $errors;
00092     }
00093 
00094 }
 All Data Structures Namespaces Files Functions Variables Enumerations