2 // This file is part of Moodle - http://moodle.org/
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.
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.
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/>.
18 * Forgot password routine.
20 * Finds the user and calls the appropriate routine for their authentication type.
24 * @copyright 1999 onwards Martin Dougiamas http://dougiamas.com
25 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
28 require('../config.php');
29 require_once($CFG->libdir
.'/authlib.php');
30 require_once(__DIR__
. '/lib.php');
31 require_once('forgot_password_form.php');
32 require_once('set_password_form.php');
34 $token = optional_param('token', false, PARAM_ALPHANUM
);
36 //HTTPS is required in this page when $CFG->loginhttps enabled
37 $PAGE->https_required();
39 $PAGE->set_url('/login/forgot_password.php');
40 $systemcontext = context_system
::instance();
41 $PAGE->set_context($systemcontext);
44 $strforgotten = get_string('passwordforgotten');
45 $strlogin = get_string('login');
47 $PAGE->navbar
->add($strlogin, get_login_url());
48 $PAGE->navbar
->add($strforgotten);
49 $PAGE->set_title($strforgotten);
50 $PAGE->set_heading($COURSE->fullname
);
52 // if alternatepasswordurl is defined, then we'll just head there
53 if (!empty($CFG->forgottenpasswordurl
)) {
54 redirect($CFG->forgottenpasswordurl
);
57 // if you are logged in then you shouldn't be here!
58 if (isloggedin() and !isguestuser()) {
59 redirect($CFG->wwwroot
.'/index.php', get_string('loginalready'), 5);
63 // This is a new password reset request.
64 // Process the request; identify the user & send confirmation email.
65 core_login_process_password_reset_request();
67 // User clicked on confirmation link in email message
68 // validate the token & set new password
69 core_login_process_password_set($token);