Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/login/change_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_change_password_form extends moodleform {
00032 
00033     function definition() {
00034         global $USER, $CFG;
00035 
00036         $mform = $this->_form;
00037 
00038         $mform->addElement('header', '', get_string('changepassword'), '');
00039 
00040         // visible elements
00041         $mform->addElement('static', 'username', get_string('username'), $USER->username);
00042 
00043         if (!empty($CFG->passwordpolicy)){
00044             $mform->addElement('static', 'passwordpolicyinfo', '', print_password_policy());
00045         }
00046         $mform->addElement('password', 'password', get_string('oldpassword'));
00047         $mform->addRule('password', get_string('required'), 'required', null, 'client');
00048         $mform->setType('password', PARAM_RAW);
00049 
00050         $mform->addElement('password', 'newpassword1', get_string('newpassword'));
00051         $mform->addRule('newpassword1', get_string('required'), 'required', null, 'client');
00052         $mform->setType('newpassword1', PARAM_RAW);
00053 
00054         $mform->addElement('password', 'newpassword2', get_string('newpassword').' ('.get_String('again').')');
00055         $mform->addRule('newpassword2', get_string('required'), 'required', null, 'client');
00056         $mform->setType('newpassword2', PARAM_RAW);
00057 
00058 
00059         // hidden optional params
00060         $mform->addElement('hidden', 'id', 0);
00061         $mform->setType('id', PARAM_INT);
00062 
00063         // buttons
00064         if (get_user_preferences('auth_forcepasswordchange')) {
00065             $this->add_action_buttons(false);
00066         } else {
00067             $this->add_action_buttons(true);
00068         }
00069     }
00070 
00072     function validation($data, $files) {
00073         global $USER;
00074         $errors = parent::validation($data, $files);
00075 
00076         update_login_count();
00077 
00078         // ignore submitted username
00079         if (!$user = authenticate_user_login($USER->username, $data['password'])) {
00080             $errors['password'] = get_string('invalidlogin');
00081             return $errors;
00082         }
00083 
00084         reset_login_count();
00085 
00086         if ($data['newpassword1'] <> $data['newpassword2']) {
00087             $errors['newpassword1'] = get_string('passwordsdiffer');
00088             $errors['newpassword2'] = get_string('passwordsdiffer');
00089             return $errors;
00090         }
00091 
00092         if ($data['password'] == $data['newpassword1']){
00093             $errors['newpassword1'] = get_string('mustchangepassword');
00094             $errors['newpassword2'] = get_string('mustchangepassword');
00095             return $errors;
00096         }
00097 
00098         $errmsg = '';//prevents eclipse warnings
00099         if (!check_password_policy($data['newpassword1'], $errmsg)) {
00100             $errors['newpassword1'] = $errmsg;
00101             $errors['newpassword2'] = $errmsg;
00102             return $errors;
00103         }
00104 
00105         return $errors;
00106     }
00107 }
 All Data Structures Namespaces Files Functions Variables Enumerations