Search moodle.org's
Developer Documentation


/login/ -> confirm.php (source)
   1  <?php
   2  
   3  // This file is part of Moodle - http://moodle.org/
   4  //
   5  // Moodle is free software: you can redistribute it and/or modify
   6  // it under the terms of the GNU General Public License as published by
   7  // the Free Software Foundation, either version 3 of the License, or
   8  // (at your option) any later version.
   9  //
  10  // Moodle is distributed in the hope that it will be useful,
  11  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13  // GNU General Public License for more details.
  14  //
  15  // You should have received a copy of the GNU General Public License
  16  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  17  
  18  /**
  19   * Confirm self registered user.
  20   *
  21   * @package    core
  22   * @subpackage auth
  23   * @copyright  1999 Martin Dougiamas  http://dougiamas.com
  24   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  25   */
  26  
  27  require('../config.php');
  28  require_once($CFG->libdir . '/authlib.php');
  29  
  30  $data = optional_param('data', '', PARAM_RAW);  // Formatted as:  secret/username
  31  
  32  $p = optional_param('p', '', PARAM_ALPHANUM);   // Old parameter:  secret
  33  $s = optional_param('s', '', PARAM_RAW);        // Old parameter:  username
  34  $redirect = optional_param('redirect', '', PARAM_LOCALURL);    // Where to redirect the browser once the user has been confirmed.
  35  
  36  $PAGE->set_url('/login/confirm.php');
  37  $PAGE->set_context(context_system::instance());
  38  
  39  if (!$authplugin = signup_get_user_confirmation_authplugin()) {
  40      throw new moodle_exception('confirmationnotenabled');
  41  }
  42  
  43  if (!empty($data) || (!empty($p) && !empty($s))) {
  44  
  45      if (!empty($data)) {
  46          $dataelements = explode('/', $data, 2); // Stop after 1st slash. Rest is username. MDL-7647
  47          $usersecret = $dataelements[0];
  48          $username   = $dataelements[1];
  49      } else {
  50          $usersecret = $p;
  51          $username   = $s;
  52      }
  53  
  54      $confirmed = $authplugin->user_confirm($username, $usersecret);
  55  
  56      if ($confirmed == AUTH_CONFIRM_ALREADY) {
  57          $user = get_complete_user_data('username', $username);
  58          $PAGE->navbar->add(get_string("alreadyconfirmed"));
  59          $PAGE->set_title(get_string("alreadyconfirmed"));
  60          $PAGE->set_heading($COURSE->fullname);
  61          echo $OUTPUT->header();
  62          echo $OUTPUT->box_start('generalbox centerpara boxwidthnormal boxaligncenter');
  63          echo "<p>".get_string("alreadyconfirmed")."</p>\n";
  64          echo $OUTPUT->single_button("$CFG->wwwroot/course/", get_string('courses'));
  65          echo $OUTPUT->box_end();
  66          echo $OUTPUT->footer();
  67          exit;
  68  
  69      } else if ($confirmed == AUTH_CONFIRM_OK) {
  70  
  71          // The user has confirmed successfully, let's log them in
  72  
  73          if (!$user = get_complete_user_data('username', $username)) {
  74              print_error('cannotfinduser', '', '', s($username));
  75          }
  76  
  77          if (!$user->suspended) {
  78              complete_user_login($user);
  79  
  80              \core\session\manager::apply_concurrent_login_limit($user->id, session_id());
  81  
  82              // Check where to go, $redirect has a higher preference.
  83              if (empty($redirect) and !empty($SESSION->wantsurl) ) {
  84                  $redirect = $SESSION->wantsurl;
  85                  unset($SESSION->wantsurl);
  86              }
  87  
  88              if (!empty($redirect)) {
  89                  redirect($redirect);
  90              }
  91          }
  92  
  93          $PAGE->navbar->add(get_string("confirmed"));
  94          $PAGE->set_title(get_string("confirmed"));
  95          $PAGE->set_heading($COURSE->fullname);
  96          echo $OUTPUT->header();
  97          echo $OUTPUT->box_start('generalbox centerpara boxwidthnormal boxaligncenter');
  98          echo "<h3>".get_string("thanks").", ". fullname($USER) . "</h3>\n";
  99          echo "<p>".get_string("confirmed")."</p>\n";
 100          echo $OUTPUT->single_button("$CFG->wwwroot/course/", get_string('courses'));
 101          echo $OUTPUT->box_end();
 102          echo $OUTPUT->footer();
 103          exit;
 104      } else {
 105          print_error('invalidconfirmdata');
 106      }
 107  } else {
 108      print_error("errorwhenconfirming");
 109  }
 110  
 111  redirect("$CFG->wwwroot/");

Search This Site: