Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/login/confirm.php
Go to the documentation of this file.
00001 <?php
00002 
00003 // This file is part of Moodle - http://moodle.org/
00004 //
00005 // Moodle is free software: you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation, either version 3 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // Moodle is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00017 
00027 require('../config.php');
00028 
00029 $data = optional_param('data', '', PARAM_RAW);  // Formatted as:  secret/username
00030 
00031 $p = optional_param('p', '', PARAM_ALPHANUM);   // Old parameter:  secret
00032 $s = optional_param('s', '', PARAM_RAW);        // Old parameter:  username
00033 
00034 $PAGE->set_url('/login/confirm.php');
00035 $PAGE->set_context(get_context_instance(CONTEXT_SYSTEM));
00036 
00037 if (empty($CFG->registerauth)) {
00038     print_error('cannotusepage2');
00039 }
00040 $authplugin = get_auth_plugin($CFG->registerauth);
00041 
00042 if (!$authplugin->can_confirm()) {
00043     print_error('cannotusepage2');
00044 }
00045 
00046 if (!empty($data) || (!empty($p) && !empty($s))) {
00047 
00048     if (!empty($data)) {
00049         $dataelements = explode('/', $data, 2); // Stop after 1st slash. Rest is username. MDL-7647
00050         $usersecret = $dataelements[0];
00051         $username   = $dataelements[1];
00052     } else {
00053         $usersecret = $p;
00054         $username   = $s;
00055     }
00056 
00057     $confirmed = $authplugin->user_confirm($username, $usersecret);
00058 
00059     if ($confirmed == AUTH_CONFIRM_ALREADY) {
00060         $user = get_complete_user_data('username', $username);
00061         $PAGE->navbar->add(get_string("alreadyconfirmed"));
00062         $PAGE->set_title(get_string("alreadyconfirmed"));
00063         $PAGE->set_heading($COURSE->fullname);
00064         echo $OUTPUT->header();
00065         echo $OUTPUT->box_start('generalbox centerpara boxwidthnormal boxaligncenter');
00066         echo "<h3>".get_string("thanks").", ". fullname($user) . "</h3>\n";
00067         echo "<p>".get_string("alreadyconfirmed")."</p>\n";
00068         echo $OUTPUT->single_button("$CFG->wwwroot/course/", get_string('courses'));
00069         echo $OUTPUT->box_end();
00070         echo $OUTPUT->footer();
00071         exit;
00072 
00073     } else if ($confirmed == AUTH_CONFIRM_OK) {
00074 
00075         // The user has confirmed successfully, let's log them in
00076 
00077         if (!$user = get_complete_user_data('username', $username)) {
00078             print_error('cannotfinduser', '', '', s($username));
00079         }
00080 
00081         complete_user_login($user);
00082 
00083         if ( ! empty($SESSION->wantsurl) ) {   // Send them where they were going
00084             $goto = $SESSION->wantsurl;
00085             unset($SESSION->wantsurl);
00086             redirect($goto);
00087         }
00088 
00089         $PAGE->navbar->add(get_string("confirmed"));
00090         $PAGE->set_title(get_string("confirmed"));
00091         $PAGE->set_heading($COURSE->fullname);
00092         echo $OUTPUT->header();
00093         echo $OUTPUT->box_start('generalbox centerpara boxwidthnormal boxaligncenter');
00094         echo "<h3>".get_string("thanks").", ". fullname($USER) . "</h3>\n";
00095         echo "<p>".get_string("confirmed")."</p>\n";
00096         echo $OUTPUT->single_button("$CFG->wwwroot/course/", get_string('courses'));
00097         echo $OUTPUT->box_end();
00098         echo $OUTPUT->footer();
00099         exit;
00100     } else {
00101         print_error('invalidconfirmdata');
00102     }
00103 } else {
00104     print_error("errorwhenconfirming");
00105 }
00106 
00107 redirect("$CFG->wwwroot/");
 All Data Structures Namespaces Files Functions Variables Enumerations