migrated signup.php over to using new formslib
[moodle.git] / login / confirm.php
CommitLineData
9a58f7cb 1<?php // $Id$
f9903ed0 2
af4542c2 3 require_once("../config.php");
5f2c35db 4 require_once("../auth/$CFG->auth/lib.php");
f9903ed0 5
be7ed5f8 6 $data = optional_param('data', '', PARAM_CLEAN); // Formatted as: secret/username
f9903ed0 7
f50c2b4e 8 $p = optional_param('p', '', PARAM_ALPHANUM); // Old parameter: secret
9 $s = optional_param('s', '', PARAM_CLEAN); // Old parameter: username
8d030053 10
be7ed5f8 11 if (!empty($data) || (!empty($p) && !empty($s))) {
12
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 }
21
22 $user = get_complete_user_data('username', $username );
f9903ed0 23
af4542c2 24 if (!empty($user)) {
f9903ed0 25
af4542c2 26 if ($user->confirmed) {
27 print_header(get_string("alreadyconfirmed"), get_string("alreadyconfirmed"), "", "");
777b9e0f 28 echo "<center><h3>".get_string("thanks").", ". fullname($user) . "</h3>\n";
9a58f7cb 29 echo "<h4>".get_string("alreadyconfirmed")."</h4>\n";
30 echo "<h3> -> <a href=\"$CFG->wwwroot/course/\">".get_string("courses")."</a></h3></center>\n";
af4542c2 31 print_footer();
32 exit;
33 }
f9903ed0 34
be7ed5f8 35 if ($user->secret == $usersecret) { // They have provided the secret key to get in
f9903ed0 36
af4542c2 37 if (!set_field("user", "confirmed", 1, "id", $user->id)) {
1d881d92 38 error("Could not confirm this user!");
39 }
af4542c2 40 if (!set_field("user", "firstaccess", time(), "id", $user->id)) {
1d881d92 41 error("Could not set this user's first access date!");
42 }
5f2c35db 43 if (isset($CFG->auth_user_create) and $CFG->auth_user_create==1 and function_exists('auth_user_activate') ) {
894ff63f 44 if (!auth_user_activate($user->username)) {
45 error("Could not activate this user!");
46 }
5f2c35db 47 }
f9903ed0 48
1d881d92 49 // The user has confirmed successfully, let's log them in
5f2c35db 50
7c12949d 51 if (!$USER = get_complete_user_data('username', $user->username)) {
af4542c2 52 error("Something serious is wrong with the database");
53 }
54
55 set_moodle_cookie($USER->username);
56
af4542c2 57 if ( ! empty($SESSION->wantsurl) ) { // Send them where they were going
58 $goto = $SESSION->wantsurl;
8223d271 59 unset($SESSION->wantsurl);
af4542c2 60 redirect("$goto");
61 }
f9903ed0 62
af4542c2 63 print_header(get_string("confirmed"), get_string("confirmed"), "", "");
777b9e0f 64 echo "<center><h3>".get_string("thanks").", ". fullname($USER) . "</h3>\n";
9a58f7cb 65 echo "<h4>".get_string("confirmed")."</h4>\n";
66 echo "<h3> -> <a href=\"$CFG->wwwroot/course/\">".get_string("courses")."</a></h3></center>\n";
af4542c2 67 print_footer();
68 exit;
8553b700 69
af4542c2 70 } else {
71 error("Invalid confirmation data");
72 }
73 }
970099c9 74 } else {
75 error(get_string("errorwhenconfirming"));
af4542c2 76 }
f9903ed0 77
c540442f 78 redirect("$CFG->wwwroot/");
f9903ed0 79
80?>