Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.
   1  <?php
   2  // This file is part of Moodle - http://moodle.org/
   3  //
   4  // Moodle is free software: you can redistribute it and/or modify
   5  // it under the terms of the GNU General Public License as published by
   6  // the Free Software Foundation, either version 3 of the License, or
   7  // (at your option) any later version.
   8  //
   9  // Moodle is distributed in the hope that it will be useful,
  10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12  // GNU General Public License for more details.
  13  //
  14  // You should have received a copy of the GNU General Public License
  15  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  16  
  17  /**
  18   * Verify age and location (digital minor check).
  19   *
  20   * @package    core
  21   * @subpackage auth
  22   * @copyright  2018 Mihail Geshoski <mihail@moodle.com>
  23   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24   */
  25  
  26  require('../config.php');
  27  require_once($CFG->libdir . '/authlib.php');
  28  
  29  $authplugin = signup_is_enabled();
  30  
  31  if (!$authplugin || !\core_auth\digital_consent::is_age_digital_consent_verification_enabled()) {
  32      // Redirect user if signup or digital age of consent verification is disabled.
  33      redirect(new moodle_url('/'), get_string('verifyagedigitalconsentnotpossible', 'error'));
  34  }
  35  
  36  $PAGE->set_context(context_system::instance());
  37  $PAGE->set_url(new moodle_url('/login/verify_age_location.php'));
  38  
  39  if (isloggedin() and !isguestuser()) {
  40      // Prevent signing up when already logged in.
  41      redirect(new moodle_url('/'), get_string('cannotsignup', 'error', fullname($USER)));
  42  }
  43  
  44  $cache = cache::make('core', 'presignup');
  45  $isminor = $cache->get('isminor');
  46  if ($isminor === 'yes') {
  47      // The user that attempts to sign up is a digital minor.
  48      redirect(new moodle_url('/login/digital_minor.php'));
  49  } else if ($isminor === 'no') {
  50      // The user that attempts to sign up has already verified that they are not a digital minor.
  51      redirect(new moodle_url('/login/signup.php'));
  52  }
  53  
  54  $PAGE->navbar->add(get_string('login'));
  55  $PAGE->navbar->add(get_string('agelocationverification'));
  56  
  57  $PAGE->set_pagelayout('login');
  58  $PAGE->set_title(get_string('agelocationverification'));
  59  $sitename = format_string($SITE->fullname);
  60  $PAGE->set_heading($sitename);
  61  
  62  $mform = new \core_auth\form\verify_age_location_form();
  63  $page = new \core_auth\output\verify_age_location_page($mform);
  64  
  65  if ($mform->is_cancelled()) {
  66      redirect(new moodle_url('/login/index.php'));
  67  } else if ($data = $mform->get_data()) {
  68      try {
  69          $isminor = \core_auth\digital_consent::is_minor($data->age, $data->country);
  70          cache::make('core', 'presignup')->set('isminor', $isminor ? 'yes' : 'no');
  71          if ($isminor) {
  72              redirect(new moodle_url('/login/digital_minor.php'));
  73          } else {
  74              redirect(new moodle_url('/login/signup.php'));
  75          }
  76      } catch (moodle_exception $e) {
  77          // Display a user-friendly error message.
  78          $errormessage = get_string('couldnotverifyagedigitalconsent', 'error');
  79          $page = new \core_auth\output\verify_age_location_page($mform, $errormessage);
  80          echo $OUTPUT->header();
  81          echo $OUTPUT->render($page);
  82          echo $OUTPUT->footer();
  83      }
  84  } else {
  85      echo $OUTPUT->header();
  86      echo $OUTPUT->render($page);
  87      echo $OUTPUT->footer();
  88  }