Fixes for Bug MDL-8617 "Implement groupings & course modules..."
[moodle-pu.git] / login / confirm.php
blobbef52d37f4223a6f48be417d71f49e66ff7eeb35
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 (!method_exists($authplugin, 'user_create')) {
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 $authplugin = get_auth_plugin($CFG->registerauth);
31 $confirmed = $authplugin->user_confirm($username, $usersecret);
33 if ($confirmed == AUTH_CONFIRM_ALREADY) {
34 $user = get_complete_user_data('username', $username);
35 print_header(get_string("alreadyconfirmed"), get_string("alreadyconfirmed"), "", "");
36 echo "<center><h3>".get_string("thanks").", ". fullname($user) . "</h3>\n";
37 echo "<h4>".get_string("alreadyconfirmed")."</h4>\n";
38 echo "<h3> -> <a href=\"$CFG->wwwroot/course/\">".get_string("courses")."</a></h3></center>\n";
39 print_footer();
40 exit;
42 if ($confirmed == AUTH_CONFIRM_OK) {
43 // Activate new user if necessary
44 $authplugin = get_auth_plugin($CFG->registerauth);
45 if (method_exists($authplugin, 'user_activate')) {
46 if (!$authplugin->user_activate($username)) {
47 error('Could not activate this user!');
51 // The user has confirmed successfully, let's log them in
53 if (!$USER = get_complete_user_data('username', $username)) {
54 error("Something serious is wrong with the database");
57 set_moodle_cookie($USER->username);
59 if ( ! empty($SESSION->wantsurl) ) { // Send them where they were going
60 $goto = $SESSION->wantsurl;
61 unset($SESSION->wantsurl);
62 redirect("$goto");
65 print_header(get_string("confirmed"), get_string("confirmed"), "", "");
66 echo "<center><h3>".get_string("thanks").", ". fullname($USER) . "</h3>\n";
67 echo "<h4>".get_string("confirmed")."</h4>\n";
68 echo "<h3> -> <a href=\"$CFG->wwwroot/course/\">".get_string("courses")."</a></h3></center>\n";
69 print_footer();
70 exit;
71 } else {
72 error("Invalid confirmation data");
74 } else {
75 error(get_string("errorwhenconfirming"));
78 redirect("$CFG->wwwroot/");