[ Index ] |
PHP Cross Reference of moodle-2.8 |
[Summary view] [Print] [Text view]
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 * Set password form definition. 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 26 defined('MOODLE_INTERNAL') || die(); 27 28 require_once($CFG->libdir.'/formslib.php'); 29 30 /** 31 * Set forgotten password form definition. 32 * 33 * @package core 34 * @subpackage auth 35 * @copyright 2006 Petr Skoda {@link http://skodak.org} 36 * @copyright 2013 Peter Bulmer 37 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 38 */ 39 class login_set_password_form extends moodleform { 40 41 /** 42 * Define the set password form. 43 */ 44 public function definition() { 45 global $USER, $CFG; 46 // Prepare a string showing whether the site wants login password autocompletion to be available to user. 47 if (empty($CFG->loginpasswordautocomplete)) { 48 $autocomplete = 'autocomplete="on"'; 49 } else { 50 $autocomplete = ''; 51 } 52 53 $mform = $this->_form; 54 $mform->setDisableShortforms(true); 55 $mform->addElement('header', 'setpassword', get_string('setpassword'), ''); 56 57 // Include the username in the form so browsers will recognise that a password is being set. 58 $mform->addElement('text', 'username', '', 'style="display: none;" ' . $autocomplete); 59 $mform->setType('username', PARAM_RAW); 60 // Token gives authority to change password. 61 $mform->addElement('hidden', 'token', ''); 62 $mform->setType('token', PARAM_ALPHANUM); 63 64 // Visible elements. 65 $mform->addElement('static', 'username2', get_string('username')); 66 67 if (!empty($CFG->passwordpolicy)) { 68 $mform->addElement('static', 'passwordpolicyinfo', '', print_password_policy()); 69 } 70 $mform->addElement('password', 'password', get_string('newpassword'), $autocomplete); 71 $mform->addRule('password', get_string('required'), 'required', null, 'client'); 72 $mform->setType('password', PARAM_RAW); 73 74 $strpasswordagain = get_string('newpassword') . ' (' . get_string('again') . ')'; 75 $mform->addElement('password', 'password2', $strpasswordagain, $autocomplete); 76 $mform->addRule('password2', get_string('required'), 'required', null, 'client'); 77 $mform->setType('password2', PARAM_RAW); 78 79 $this->add_action_buttons(true); 80 } 81 82 /** 83 * Perform extra password change validation. 84 * @param array $data submitted form fields. 85 * @param array $files submitted with the form. 86 * @return array errors occuring during validation. 87 */ 88 public function validation($data, $files) { 89 global $USER; 90 $errors = parent::validation($data, $files); 91 92 // Ignore submitted username. 93 if ($data['password'] !== $data['password2']) { 94 $errors['password'] = get_string('passwordsdiffer'); 95 $errors['password2'] = get_string('passwordsdiffer'); 96 return $errors; 97 } 98 99 $errmsg = ''; // Prevents eclipse warnings. 100 if (!check_password_policy($data['password'], $errmsg)) { 101 $errors['password'] = $errmsg; 102 $errors['password2'] = $errmsg; 103 return $errors; 104 } 105 106 return $errors; 107 } 108 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:29:05 2014 | Cross-referenced by PHPXref 0.7.1 |