Automatically generated installer lang files
[moodle.git] / login / confirm.php
CommitLineData
8570cff0 1<?php
f9903ed0 2
c30949a9
PS
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.
14//
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/>.
17
18/**
19 * Confirm self registered user.
20 *
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
25 */
26
27require('../config.php');
f9903ed0 28
c4d7d721 29$data = optional_param('data', '', PARAM_RAW); // Formatted as: secret/username
f9903ed0 30
c4d7d721
PS
31$p = optional_param('p', '', PARAM_ALPHANUM); // Old parameter: secret
32$s = optional_param('s', '', PARAM_RAW); // Old parameter: username
8d030053 33
a6855934 34$PAGE->set_url('/login/confirm.php');
c30949a9 35$PAGE->set_context(get_context_instance(CONTEXT_SYSTEM));
8570cff0 36
37if (empty($CFG->registerauth)) {
38 print_error('cannotusepage2');
39}
40$authplugin = get_auth_plugin($CFG->registerauth);
41
42if (!$authplugin->can_confirm()) {
43 print_error('cannotusepage2');
44}
3fe6b721 45
8570cff0 46if (!empty($data) || (!empty($p) && !empty($s))) {
47
48 if (!empty($data)) {
c4d7d721 49 $dataelements = explode('/', $data, 2); // Stop after 1st slash. Rest is username. MDL-7647
8570cff0 50 $usersecret = $dataelements[0];
51 $username = $dataelements[1];
52 } else {
53 $usersecret = $p;
54 $username = $s;
3fe6b721 55 }
56
8570cff0 57 $confirmed = $authplugin->user_confirm($username, $usersecret);
be7ed5f8 58
8570cff0 59 if ($confirmed == AUTH_CONFIRM_ALREADY) {
60 $user = get_complete_user_data('username', $username);
c93fdc7b 61 $PAGE->navbar->add(get_string("alreadyconfirmed"));
8570cff0 62 $PAGE->set_title(get_string("alreadyconfirmed"));
c93fdc7b 63 $PAGE->set_heading($COURSE->fullname);
8570cff0 64 echo $OUTPUT->header();
65 echo $OUTPUT->box_start('generalbox centerpara boxwidthnormal boxaligncenter');
66 echo "<h3>".get_string("thanks").", ". fullname($user) . "</h3>\n";
67 echo "<p>".get_string("alreadyconfirmed")."</p>\n";
5c2ed7e2 68 echo $OUTPUT->single_button("$CFG->wwwroot/course/", get_string('courses'));
8570cff0 69 echo $OUTPUT->box_end();
70 echo $OUTPUT->footer();
71 exit;
72
73 } else if ($confirmed == AUTH_CONFIRM_OK) {
74
75 // The user has confirmed successfully, let's log them in
76
77 if (!$user = get_complete_user_data('username', $username)) {
c4d7d721 78 print_error('cannotfinduser', '', '', s($username));
be7ed5f8 79 }
80
8570cff0 81 complete_user_login($user);
82
83 if ( ! empty($SESSION->wantsurl) ) { // Send them where they were going
84 $goto = $SESSION->wantsurl;
85 unset($SESSION->wantsurl);
86 redirect($goto);
af4542c2 87 }
8570cff0 88
c93fdc7b 89 $PAGE->navbar->add(get_string("confirmed"));
8570cff0 90 $PAGE->set_title(get_string("confirmed"));
c93fdc7b 91 $PAGE->set_heading($COURSE->fullname);
8570cff0 92 echo $OUTPUT->header();
93 echo $OUTPUT->box_start('generalbox centerpara boxwidthnormal boxaligncenter');
94 echo "<h3>".get_string("thanks").", ". fullname($USER) . "</h3>\n";
95 echo "<p>".get_string("confirmed")."</p>\n";
5c2ed7e2 96 echo $OUTPUT->single_button("$CFG->wwwroot/course/", get_string('courses'));
8570cff0 97 echo $OUTPUT->box_end();
98 echo $OUTPUT->footer();
99 exit;
970099c9 100 } else {
8570cff0 101 print_error('invalidconfirmdata');
af4542c2 102 }
8570cff0 103} else {
104 print_error("errorwhenconfirming");
105}
f9903ed0 106
8570cff0 107redirect("$CFG->wwwroot/");