migrated signup.php over to using new formslib
[moodle.git] / login / confirm.php
1 <?php // $Id$
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))) {    
13         if (!empty($data)) {
14             $dataelements = explode('/',$data);
15             $usersecret = $dataelements[0];
16             $username   = $dataelements[1];
17         } else {
18             $usersecret = $p;
19             $username   = $s;
20         }
22         $user = get_complete_user_data('username', $username );
24         if (!empty($user)) {
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";
31                 print_footer();
32                 exit;
33             }
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!");
39                 }
40                 if (!set_field("user", "firstaccess", time(), "id", $user->id)) {
41                     error("Could not set this user's first access date!");
42                 }
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!");
46                     }
47                 }
49                 // The user has confirmed successfully, let's log them in
50                 
51                 if (!$USER = get_complete_user_data('username', $user->username)) {
52                     error("Something serious is wrong with the database");
53                 }
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);
60                     redirect("$goto");
61                 }
62  
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";
67                 print_footer();
68                 exit;
70             } else {
71                 error("Invalid confirmation data");
72             }
73         }
74     } else {
75         error(get_string("errorwhenconfirming"));
76     }
78     redirect("$CFG->wwwroot/");
80 ?>