File: confirm.php

package info (click to toggle)
moodle 1.6.3-2%2Betch3
  • links: PTS
  • area: main
  • in suites: etch
  • size: 37,172 kB
  • ctags: 51,688
  • sloc: php: 231,916; sql: 5,631; xml: 2,688; sh: 1,185; perl: 638; makefile: 48; pascal: 36
file content (80 lines) | stat: -rw-r--r-- 3,196 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php // $Id: confirm.php,v 1.21.8.2 2006/09/20 21:46:50 skodak Exp $

    require_once("../config.php");
    require_once("../auth/$CFG->auth/lib.php");

    $data = optional_param('data', '', PARAM_CLEAN);  // Formatted as:  secret/username

    $p = optional_param('p', '', PARAM_ALPHANUM);     // Old parameter:  secret
    $s = optional_param('s', '', PARAM_CLEAN);        // Old parameter:  username

    if (!empty($data) || (!empty($p) && !empty($s))) {    

        if (!empty($data)) {
            $dataelements = explode('/',$data);
            $usersecret = $dataelements[0];
            $username   = $dataelements[1];
        } else {
            $usersecret = $p;
            $username   = $s;
        }

        $user = get_complete_user_data('username', $username );

        if (!empty($user)) {

            if ($user->confirmed) {
                print_header(get_string("alreadyconfirmed"), get_string("alreadyconfirmed"), "", "");
                echo "<center><h3>".get_string("thanks").", ". fullname($user) . "</h3>\n";
                echo "<h4>".get_string("alreadyconfirmed")."</h4>\n";
                echo "<h3> -> <a href=\"$CFG->wwwroot/course/\">".get_string("courses")."</a></h3></center>\n";
                print_footer();
                exit;
            }

            if ($user->secret == $usersecret) {   // They have provided the secret key to get in

                if (!set_field("user", "confirmed", 1, "id", $user->id)) {
                    error("Could not confirm this user!");
                }
                if (!set_field("user", "firstaccess", time(), "id", $user->id)) {
                    error("Could not set this user's first access date!");
                }
                if (isset($CFG->auth_user_create) and $CFG->auth_user_create==1 and function_exists('auth_user_activate') ) {
                    if (!auth_user_activate($user->username)) {
                         error("Could not activate this user!");
                    }
                }

                // The user has confirmed successfully, let's log them in
                
                if (!$USER = get_complete_user_data('username', $user->username)) {
                    error("Something serious is wrong with the database");
                }

                set_moodle_cookie($USER->username);

                if ( ! empty($SESSION->wantsurl) ) {   // Send them where they were going
                    $goto = $SESSION->wantsurl;
                    unset($SESSION->wantsurl);
                    redirect("$goto");
                }
 
                print_header(get_string("confirmed"), get_string("confirmed"), "", "");
                echo "<center><h3>".get_string("thanks").", ". fullname($USER) . "</h3>\n";
                echo "<h4>".get_string("confirmed")."</h4>\n";
                echo "<h3> -> <a href=\"$CFG->wwwroot/course/\">".get_string("courses")."</a></h3></center>\n";
                print_footer();
                exit;

            } else {
                error("Invalid confirmation data");
            }
        }
    } else {
        error(get_string("errorwhenconfirming"));
    }

    redirect("$CFG->wwwroot/");

?>