Small upgrade to fix some guest->mnethostid. MDL-10375
[pfb-moodle.git] / login / confirm.php
blob1cc6db998a3143b4d9222f41643e7d4071ff4afe
1 <?php // $Id$
3 require_once("../config.php");
5 $data = optional_param('data', '', PARAM_CLEAN); // Formatted as: secret/username
7 $p = optional_param('p', '', PARAM_ALPHANUM); // Old parameter: secret
8 $s = optional_param('s', '', PARAM_CLEAN); // Old parameter: username
10 if (empty($CFG->registerauth)) {
11 error("Sorry, you may not use this page.");
13 $authplugin = get_auth_plugin($CFG->registerauth);
15 if (!$authplugin->can_confirm()) {
16 error("Sorry, you may not use this page.");
19 if (!empty($data) || (!empty($p) && !empty($s))) {
21 if (!empty($data)) {
22 $dataelements = explode('/',$data);
23 $usersecret = $dataelements[0];
24 $username = $dataelements[1];
25 } else {
26 $usersecret = $p;
27 $username = $s;
30 $confirmed = $authplugin->user_confirm($username, $usersecret);
32 if ($confirmed == AUTH_CONFIRM_ALREADY) {
33 $user = get_complete_user_data('username', $username);
34 print_header(get_string("alreadyconfirmed"), get_string("alreadyconfirmed"), "", "");
35 print_box_start('generalbox centerpara boxwidthnormal boxaligncenter');
36 echo "<h3>".get_string("thanks").", ". fullname($user) . "</h3>\n";
37 echo "<p>".get_string("alreadyconfirmed")."</p>\n";
38 print_single_button("$CFG->wwwroot/course/", null, get_string('courses'));
39 print_box_end();
40 print_footer();
41 exit;
43 } else if ($confirmed == AUTH_CONFIRM_OK) {
45 // The user has confirmed successfully, let's log them in
47 if (!$USER = get_complete_user_data('username', $username)) {
48 error("Something serious is wrong with the database");
51 set_moodle_cookie($USER->username);
53 if ( ! empty($SESSION->wantsurl) ) { // Send them where they were going
54 $goto = $SESSION->wantsurl;
55 unset($SESSION->wantsurl);
56 redirect($goto);
59 print_header(get_string("confirmed"), get_string("confirmed"), "", "");
60 print_box_start('generalbox centerpara boxwidthnormal boxaligncenter');
61 echo "<h3>".get_string("thanks").", ". fullname($USER) . "</h3>\n";
62 echo "<p>".get_string("confirmed")."</p>\n";
63 print_single_button("$CFG->wwwroot/course/", null, get_string('courses'));
64 print_box_end();
65 print_footer();
66 exit;
67 } else {
68 error("Invalid confirmation data");
70 } else {
71 error(get_string("errorwhenconfirming"));
74 redirect("$CFG->wwwroot/");