MDL-62660 tool_dataprivacy: Add scheduled task to expire data requests
[moodle.git] / login / confirm.php
blobb46dec2604826e2133de663e6f70c0e146e5632d
1 <?php
3 // This file is part of Moodle - http://moodle.org/
4 //
5 // Moodle is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // Moodle is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 /**
19 * Confirm self registered user.
21 * @package core
22 * @subpackage auth
23 * @copyright 1999 Martin Dougiamas http://dougiamas.com
24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27 require(__DIR__ . '/../config.php');
28 require(__DIR__ . '/lib.php');
29 require_once($CFG->libdir . '/authlib.php');
31 $data = optional_param('data', '', PARAM_RAW); // Formatted as: secret/username
33 $p = optional_param('p', '', PARAM_ALPHANUM); // Old parameter: secret
34 $s = optional_param('s', '', PARAM_RAW); // Old parameter: username
35 $redirect = optional_param('redirect', '', PARAM_LOCALURL); // Where to redirect the browser once the user has been confirmed.
37 $PAGE->set_url('/login/confirm.php');
38 $PAGE->set_context(context_system::instance());
40 if (!$authplugin = signup_get_user_confirmation_authplugin()) {
41 throw new moodle_exception('confirmationnotenabled');
44 if (!empty($data) || (!empty($p) && !empty($s))) {
46 if (!empty($data)) {
47 $dataelements = explode('/', $data, 2); // Stop after 1st slash. Rest is username. MDL-7647
48 $usersecret = $dataelements[0];
49 $username = $dataelements[1];
50 } else {
51 $usersecret = $p;
52 $username = $s;
55 $confirmed = $authplugin->user_confirm($username, $usersecret);
57 if ($confirmed == AUTH_CONFIRM_ALREADY) {
58 $user = get_complete_user_data('username', $username);
59 $PAGE->navbar->add(get_string("alreadyconfirmed"));
60 $PAGE->set_title(get_string("alreadyconfirmed"));
61 $PAGE->set_heading($COURSE->fullname);
62 echo $OUTPUT->header();
63 echo $OUTPUT->box_start('generalbox centerpara boxwidthnormal boxaligncenter');
64 echo "<p>".get_string("alreadyconfirmed")."</p>\n";
65 echo $OUTPUT->single_button(core_login_get_return_url(), get_string('courses'));
66 echo $OUTPUT->box_end();
67 echo $OUTPUT->footer();
68 exit;
70 } else if ($confirmed == AUTH_CONFIRM_OK) {
72 // The user has confirmed successfully, let's log them in
74 if (!$user = get_complete_user_data('username', $username)) {
75 print_error('cannotfinduser', '', '', s($username));
78 if (!$user->suspended) {
79 complete_user_login($user);
81 \core\session\manager::apply_concurrent_login_limit($user->id, session_id());
84 $PAGE->navbar->add(get_string("confirmed"));
85 $PAGE->set_title(get_string("confirmed"));
86 $PAGE->set_heading($COURSE->fullname);
87 echo $OUTPUT->header();
88 echo $OUTPUT->box_start('generalbox centerpara boxwidthnormal boxaligncenter');
89 echo "<h3>".get_string("thanks").", ". fullname($USER) . "</h3>\n";
90 echo "<p>".get_string("confirmed")."</p>\n";
91 echo $OUTPUT->single_button(core_login_get_return_url(), get_string('continue'));
92 echo $OUTPUT->box_end();
93 echo $OUTPUT->footer();
94 exit;
95 } else {
96 print_error('invalidconfirmdata');
98 } else {
99 print_error("errorwhenconfirming");
102 redirect("$CFG->wwwroot/");