3 require_once("../config.php");
4 require_once("../auth/$CFG->auth/lib.php");
6 $data = optional_param('data', '', PARAM_CLEAN
); // Formatted as: secret/username
8 $p = optional_param('p', '', PARAM_ALPHANUM
); // Old parameter: secret
9 $s = optional_param('s', '', PARAM_CLEAN
); // Old parameter: username
11 if (!empty($data) ||
(!empty($p) && !empty($s))) {
14 $dataelements = explode('/',$data);
15 $usersecret = $dataelements[0];
16 $username = $dataelements[1];
22 $user = get_complete_user_data('username', $username );
26 if ($user->confirmed
) {
27 print_header(get_string("alreadyconfirmed"), get_string("alreadyconfirmed"), "", "");
28 echo "<center><h3>".get_string("thanks").", ". fullname($user) . "</h3>\n";
29 echo "<h4>".get_string("alreadyconfirmed")."</h4>\n";
30 echo "<h3> -> <a href=\"$CFG->wwwroot/course/\">".get_string("courses")."</a></h3></center>\n";
35 if ($user->secret
== $usersecret) { // They have provided the secret key to get in
37 if (!set_field("user", "confirmed", 1, "id", $user->id
)) {
38 error("Could not confirm this user!");
40 if (!set_field("user", "firstaccess", time(), "id", $user->id
)) {
41 error("Could not set this user's first access date!");
43 if (isset($CFG->auth_user_create
) and $CFG->auth_user_create
==1 and function_exists('auth_user_activate') ) {
44 if (!auth_user_activate($user->username
)) {
45 error("Could not activate this user!");
49 // The user has confirmed successfully, let's log them in
51 if (!$USER = get_complete_user_data('username', $user->username
)) {
52 error("Something serious is wrong with the database");
55 set_moodle_cookie($USER->username
);
57 if ( ! empty($SESSION->wantsurl
) ) { // Send them where they were going
58 $goto = $SESSION->wantsurl
;
59 unset($SESSION->wantsurl
);
63 print_header(get_string("confirmed"), get_string("confirmed"), "", "");
64 echo "<center><h3>".get_string("thanks").", ". fullname($USER) . "</h3>\n";
65 echo "<h4>".get_string("confirmed")."</h4>\n";
66 echo "<h3> -> <a href=\"$CFG->wwwroot/course/\">".get_string("courses")."</a></h3></center>\n";
71 error("Invalid confirmation data");
75 error(get_string("errorwhenconfirming"));
78 redirect("$CFG->wwwroot/");