Merge branch 'MDL-79368-main' of https://github.com/roland04/moodle
[moodle.git] / login / verify_age_location.php
blob49644ae091259feb69bbeedb9d3498941f038cd6
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.
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/>.
17 /**
18 * Verify age and location (digital minor check).
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
26 require('../config.php');
27 require_once($CFG->libdir . '/authlib.php');
29 $authplugin = signup_is_enabled();
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'));
36 $PAGE->set_context(context_system::instance());
37 $PAGE->set_url(new moodle_url('/login/verify_age_location.php'));
39 if (isloggedin() and !isguestuser()) {
40 // Prevent signing up when already logged in.
41 redirect(new moodle_url('/'), get_string('cannotsignup', 'error', fullname($USER)));
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'));
54 $PAGE->navbar->add(get_string('login'));
55 $PAGE->navbar->add(get_string('agelocationverification'));
57 $PAGE->set_pagelayout('login');
58 $PAGE->set_title(get_string('agelocationverification'));
59 $sitename = format_string($SITE->fullname);
60 $PAGE->set_heading($sitename);
62 $mform = new \core_auth\form\verify_age_location_form();
63 $page = new \core_auth\output\verify_age_location_page($mform);
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'));
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();
84 } else {
85 echo $OUTPUT->header();
86 echo $OUTPUT->render($page);
87 echo $OUTPUT->footer();