Search moodle.org's
Developer Documentation


/login/ -> signup.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   * user signup page.
  20   *
  21   * @package    core
  22   * @subpackage auth
  23   * @copyright  1999 onwards 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->dirroot . '/user/editlib.php');
  29  require_once($CFG->libdir . '/authlib.php');
  30  
  31  // Try to prevent searching for sites that allow sign-up.
  32  if (!isset($CFG->additionalhtmlhead)) {
  33      $CFG->additionalhtmlhead = '';
  34  }
  35  $CFG->additionalhtmlhead .= '<meta name="robots" content="noindex" />';
  36  
  37  if (!$authplugin = signup_is_enabled()) {
  38      print_error('notlocalisederrormessage', 'error', '', 'Sorry, you may not use this page.');
  39  }
  40  
  41  //HTTPS is required in this page when $CFG->loginhttps enabled
  42  $PAGE->https_required();
  43  
  44  $PAGE->set_url('/login/signup.php');
  45  $PAGE->set_context(context_system::instance());
  46  
  47  // If wantsurl is empty or /login/signup.php, override wanted URL.
  48  // We do not want to end up here again if user clicks "Login".
  49  if (empty($SESSION->wantsurl)) {
  50      $SESSION->wantsurl = $CFG->wwwroot . '/';
  51  } else {
  52      $wantsurl = new moodle_url($SESSION->wantsurl);
  53      if ($PAGE->url->compare($wantsurl, URL_MATCH_BASE)) {
  54          $SESSION->wantsurl = $CFG->wwwroot . '/';
  55      }
  56  }
  57  
  58  if (isloggedin() and !isguestuser()) {
  59      // Prevent signing up when already logged in.
  60      echo $OUTPUT->header();
  61      echo $OUTPUT->box_start();
  62      $logout = new single_button(new moodle_url($CFG->httpswwwroot . '/login/logout.php',
  63          array('sesskey' => sesskey(), 'loginpage' => 1)), get_string('logout'), 'post');
  64      $continue = new single_button(new moodle_url('/'), get_string('cancel'), 'get');
  65      echo $OUTPUT->confirm(get_string('cannotsignup', 'error', fullname($USER)), $logout, $continue);
  66      echo $OUTPUT->box_end();
  67      echo $OUTPUT->footer();
  68      exit;
  69  }
  70  
  71  $mform_signup = $authplugin->signup_form();
  72  
  73  if ($mform_signup->is_cancelled()) {
  74      redirect(get_login_url());
  75  
  76  } else if ($user = $mform_signup->get_data()) {
  77      // Add missing required fields.
  78      $user = signup_setup_new_user($user);
  79  
  80      $authplugin->user_signup($user, true); // prints notice and link to login/index.php
  81      exit; //never reached
  82  }
  83  
  84  // make sure we really are on the https page when https login required
  85  $PAGE->verify_https_required();
  86  
  87  
  88  $newaccount = get_string('newaccount');
  89  $login      = get_string('login');
  90  
  91  $PAGE->navbar->add($login);
  92  $PAGE->navbar->add($newaccount);
  93  
  94  $PAGE->set_pagelayout('login');
  95  $PAGE->set_title($newaccount);
  96  $PAGE->set_heading($SITE->fullname);
  97  
  98  echo $OUTPUT->header();
  99  
 100  echo $OUTPUT->render($mform_signup);
 101  echo $OUTPUT->footer();

Search This Site: