first commit

This commit is contained in:
CHIEFSOFT\ameye
2024-09-30 18:11:26 -04:00
commit e592ca6823
27270 changed files with 5002257 additions and 0 deletions
+106
View File
@@ -0,0 +1,106 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Contains helper class for digital consent.
*
* @package core_auth
* @copyright 2018 Mihail Geshoski <mihail@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_auth;
defined('MOODLE_INTERNAL') || die();
/**
* Helper class for digital consent.
*
* @copyright 2018 Mihail Geshoski <mihail@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class digital_consent {
/**
* Returns true if age and location verification is enabled in the site.
*
* @return bool
*/
public static function is_age_digital_consent_verification_enabled() {
global $CFG;
return !empty($CFG->agedigitalconsentverification);
}
/**
* Checks if a user is a digital minor.
*
* @param int $age
* @param string $country The country code (ISO 3166-2)
* @return bool
*/
public static function is_minor($age, $country) {
global $CFG;
$ageconsentmap = $CFG->agedigitalconsentmap;
$agedigitalconsentmap = self::parse_age_digital_consent_map($ageconsentmap);
return array_key_exists($country, $agedigitalconsentmap) ?
$age < $agedigitalconsentmap[$country] : $age < $agedigitalconsentmap['*'];
}
/**
* Parse the agedigitalconsentmap setting into an array.
*
* @param string $ageconsentmap The value of the agedigitalconsentmap setting
* @return array $ageconsentmapparsed
*/
public static function parse_age_digital_consent_map($ageconsentmap) {
$ageconsentmapparsed = array();
$countries = get_string_manager()->get_list_of_countries(true);
$isdefaultvaluepresent = false;
$lines = preg_split('/\r|\n/', $ageconsentmap, -1, PREG_SPLIT_NO_EMPTY);
foreach ($lines as $line) {
$arr = explode(",", $line);
// Handle if there is more or less than one comma separator.
if (count($arr) != 2) {
throw new \moodle_exception('agedigitalconsentmapinvalidcomma', 'error', '', $line);
}
$country = trim($arr[0]);
$age = trim($arr[1]);
// Check if default.
if ($country == "*") {
$isdefaultvaluepresent = true;
}
// Handle if the presented value for country is not valid.
if ($country !== "*" && !array_key_exists($country, $countries)) {
throw new \moodle_exception('agedigitalconsentmapinvalidcountry', 'error', '', $country);
}
// Handle if the presented value for age is not valid.
if (!is_numeric($age)) {
throw new \moodle_exception('agedigitalconsentmapinvalidage', 'error', '', $age);
}
$ageconsentmapparsed[$country] = $age;
}
// Handle if a default value does not exist.
if (!$isdefaultvaluepresent) {
throw new \moodle_exception('agedigitalconsentmapinvaliddefault');
}
return $ageconsentmapparsed;
}
}
+435
View File
@@ -0,0 +1,435 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Auth external API
*
* @package core_auth
* @category external
* @copyright 2016 Juan Leyva <juan@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @since Moodle 3.2
*/
use core_external\external_api;
use core_external\external_function_parameters;
use core_external\external_single_structure;
use core_external\external_value;
use core_external\external_warnings;
defined('MOODLE_INTERNAL') || die;
require_once($CFG->libdir . '/authlib.php');
/**
* Auth external functions
*
* @package core_auth
* @category external
* @copyright 2016 Juan Leyva <juan@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @since Moodle 3.2
*/
class core_auth_external extends external_api {
/**
* Describes the parameters for confirm_user.
*
* @return external_function_parameters
* @since Moodle 3.2
*/
public static function confirm_user_parameters() {
return new external_function_parameters(
array(
'username' => new external_value(core_user::get_property_type('username'), 'User name'),
'secret' => new external_value(core_user::get_property_type('secret'), 'Confirmation secret'),
)
);
}
/**
* Confirm a user account.
*
* @param string $username user name
* @param string $secret confirmation secret (random string) used for validating the confirm request
* @return array warnings and success status (true if the user was confirmed, false if he was already confirmed)
* @since Moodle 3.2
* @throws moodle_exception
*/
public static function confirm_user($username, $secret) {
global $PAGE;
$warnings = array();
$params = self::validate_parameters(
self::confirm_user_parameters(),
array(
'username' => $username,
'secret' => $secret,
)
);
$context = context_system::instance();
$PAGE->set_context($context);
if (!$authplugin = signup_get_user_confirmation_authplugin()) {
throw new moodle_exception('confirmationnotenabled');
}
$confirmed = $authplugin->user_confirm($username, $secret);
if ($confirmed == AUTH_CONFIRM_ALREADY) {
$success = false;
$warnings[] = array(
'item' => 'user',
'itemid' => 0,
'warningcode' => 'alreadyconfirmed',
'message' => s(get_string('alreadyconfirmed'))
);
} else if ($confirmed == AUTH_CONFIRM_OK) {
$success = true;
} else {
throw new moodle_exception('invalidconfirmdata');
}
$result = array(
'success' => $success,
'warnings' => $warnings,
);
return $result;
}
/**
* Describes the confirm_user return value.
*
* @return external_single_structure
* @since Moodle 3.2
*/
public static function confirm_user_returns() {
return new external_single_structure(
array(
'success' => new external_value(PARAM_BOOL, 'True if the user was confirmed, false if he was already confirmed'),
'warnings' => new external_warnings(),
)
);
}
/**
* Describes the parameters for request_password_reset.
*
* @return external_function_parameters
* @since Moodle 3.4
*/
public static function request_password_reset_parameters() {
return new external_function_parameters(
array(
'username' => new external_value(core_user::get_property_type('username'), 'User name', VALUE_DEFAULT, ''),
'email' => new external_value(core_user::get_property_type('email'), 'User email', VALUE_DEFAULT, ''),
)
);
}
/**
* Requests a password reset.
*
* @param string $username user name
* @param string $email user email
* @return array warnings and success status (including notices and errors while processing)
* @since Moodle 3.4
* @throws moodle_exception
*/
public static function request_password_reset($username = '', $email = '') {
global $CFG, $PAGE;
require_once($CFG->dirroot . '/login/lib.php');
$warnings = array();
$params = self::validate_parameters(
self::request_password_reset_parameters(),
array(
'username' => $username,
'email' => $email,
)
);
$context = context_system::instance();
$PAGE->set_context($context); // Needed by format_string calls.
// Check if an alternate forgotten password method is set.
if (!empty($CFG->forgottenpasswordurl)) {
throw new moodle_exception('cannotmailconfirm');
}
$errors = core_login_validate_forgot_password_data($params);
if (!empty($errors)) {
$status = 'dataerror';
$notice = '';
foreach ($errors as $itemname => $message) {
$warnings[] = array(
'item' => $itemname,
'itemid' => 0,
'warningcode' => 'fielderror',
'message' => s($message)
);
}
} else {
list($status, $notice, $url) = core_login_process_password_reset($params['username'], $params['email']);
}
return array(
'status' => $status,
'notice' => $notice,
'warnings' => $warnings,
);
}
/**
* Describes the request_password_reset return value.
*
* @return external_single_structure
* @since Moodle 3.4
*/
public static function request_password_reset_returns() {
return new external_single_structure(
array(
'status' => new external_value(PARAM_ALPHANUMEXT, 'The returned status of the process:
dataerror: Error in the sent data (username or email). More information in warnings field.
emailpasswordconfirmmaybesent: Email sent or not (depends on user found in database).
emailpasswordconfirmnotsent: Failure, user not found.
emailpasswordconfirmnoemail: Failure, email not found.
emailalreadysent: Email already sent.
emailpasswordconfirmsent: User pending confirmation.
emailresetconfirmsent: Email sent.
'),
'notice' => new external_value(PARAM_RAW, 'Important information for the user about the process.'),
'warnings' => new external_warnings(),
)
);
}
/**
* Describes the parameters for the digital minor check.
*
* @return external_function_parameters
* @since Moodle 3.4
*/
public static function is_minor_parameters() {
return new external_function_parameters(
array(
'age' => new external_value(PARAM_INT, 'Age'),
'country' => new external_value(PARAM_ALPHA, 'Country of residence'),
)
);
}
/**
* Requests a check if a user is digital minor.
*
* @param int $age User age
* @param string $country Country of residence
* @return array status (true if the user is a minor, false otherwise)
* @since Moodle 3.4
* @throws moodle_exception
*/
public static function is_minor($age, $country) {
global $CFG, $PAGE;
require_once($CFG->dirroot . '/login/lib.php');
$params = self::validate_parameters(
self::is_minor_parameters(),
array(
'age' => $age,
'country' => $country,
)
);
if (!array_key_exists($params['country'], get_string_manager()->get_list_of_countries())) {
throw new invalid_parameter_exception('Invalid value for country parameter (value: '.
$params['country'] .')');
}
$context = context_system::instance();
$PAGE->set_context($context);
// Check if verification of age and location (minor check) is enabled.
if (!\core_auth\digital_consent::is_age_digital_consent_verification_enabled()) {
throw new moodle_exception('nopermissions', 'error', '',
get_string('agelocationverificationdisabled', 'error'));
}
$status = \core_auth\digital_consent::is_minor($params['age'], $params['country']);
return array(
'status' => $status
);
}
/**
* Describes the is_minor return value.
*
* @return external_single_structure
* @since Moodle 3.4
*/
public static function is_minor_returns() {
return new external_single_structure(
array(
'status' => new external_value(PARAM_BOOL, 'True if the user is considered to be a digital minor,
false if not')
)
);
}
/**
* Describes the parameters for is_age_digital_consent_verification_enabled.
*
* @return external_function_parameters
* @since Moodle 3.3
*/
public static function is_age_digital_consent_verification_enabled_parameters() {
return new external_function_parameters(array());
}
/**
* Checks if age digital consent verification is enabled.
*
* @return array status (true if digital consent verification is enabled, false otherwise.)
* @since Moodle 3.3
* @throws moodle_exception
*/
public static function is_age_digital_consent_verification_enabled() {
global $PAGE;
$context = context_system::instance();
$PAGE->set_context($context);
$status = false;
// Check if verification is enabled.
if (\core_auth\digital_consent::is_age_digital_consent_verification_enabled()) {
$status = true;
}
return array(
'status' => $status
);
}
/**
* Describes the is_age_digital_consent_verification_enabled return value.
*
* @return external_single_structure
* @since Moodle 3.3
*/
public static function is_age_digital_consent_verification_enabled_returns() {
return new external_single_structure(
array(
'status' => new external_value(PARAM_BOOL, 'True if digital consent verification is enabled,
false otherwise.')
)
);
}
/**
* Describes the parameters for resend_confirmation_email.
*
* @return external_function_parameters
* @since Moodle 3.6
*/
public static function resend_confirmation_email_parameters() {
return new external_function_parameters(
array(
'username' => new external_value(core_user::get_property_type('username'), 'Username.'),
'password' => new external_value(core_user::get_property_type('password'), 'Plain text password.'),
'redirect' => new external_value(PARAM_LOCALURL, 'Redirect the user to this site url after confirmation.',
VALUE_DEFAULT, ''),
)
);
}
/**
* Requests resend the confirmation email.
*
* @param string $username user name
* @param string $password plain text password
* @param string $redirect redirect the user to this site url after confirmation
* @return array warnings and success status
* @since Moodle 3.6
* @throws moodle_exception
*/
public static function resend_confirmation_email($username, $password, $redirect = '') {
global $PAGE;
$warnings = array();
$params = self::validate_parameters(
self::resend_confirmation_email_parameters(),
array(
'username' => $username,
'password' => $password,
'redirect' => $redirect,
)
);
$context = context_system::instance();
$PAGE->set_context($context); // Need by internal APIs.
$username = trim(core_text::strtolower($params['username']));
$password = $params['password'];
if (is_restored_user($username)) {
throw new moodle_exception('restoredaccountresetpassword', 'webservice');
}
$user = authenticate_user_login($username, $password);
if (empty($user)) {
throw new moodle_exception('invalidlogin');
}
if ($user->confirmed) {
throw new moodle_exception('alreadyconfirmed');
}
// Check if we should redirect the user once the user is confirmed.
$confirmationurl = null;
if (!empty($params['redirect'])) {
// Pass via moodle_url to fix thinks like admin links.
$redirect = new moodle_url($params['redirect']);
$confirmationurl = new moodle_url('/login/confirm.php', array('redirect' => $redirect->out()));
}
$status = send_confirmation_email($user, $confirmationurl);
return array(
'status' => $status,
'warnings' => $warnings,
);
}
/**
* Describes the resend_confirmation_email return value.
*
* @return external_single_structure
* @since Moodle 3.6
*/
public static function resend_confirmation_email_returns() {
return new external_single_structure(
array(
'status' => new external_value(PARAM_BOOL, 'True if the confirmation email was sent, false otherwise.'),
'warnings' => new external_warnings(),
)
);
}
}
@@ -0,0 +1,62 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Age and location verification mform.
*
* @package core_auth
* @copyright 2018 Mihail Geshoski <mihail@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_auth\form;
defined('MOODLE_INTERNAL') || die();
require_once($CFG->libdir.'/formslib.php');
use moodleform;
/**
* Age and location verification mform class.
*
* @copyright 2018 Mihail Geshoski <mihail@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class verify_age_location_form extends moodleform {
/**
* Defines the form fields.
*/
public function definition() {
global $CFG;
$mform = $this->_form;
$mform->addElement('text', 'age', get_string('whatisyourage'), array('optional' => false));
$mform->setType('age', PARAM_RAW);
$mform->addRule('age', null, 'required', null, 'client');
$mform->addRule('age', null, 'numeric', null, 'client');
$countries = get_string_manager()->get_list_of_countries();
$defaultcountry[''] = get_string('selectacountry');
$countries = array_merge($defaultcountry, $countries);
$mform->addElement('select', 'country', get_string('wheredoyoulive'), $countries);
$mform->addRule('country', null, 'required', null, 'client');
$mform->setDefault('country', $CFG->country);
$this->add_action_buttons(true, get_string('proceed'));
}
}
@@ -0,0 +1,63 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Digital minor renderable.
*
* @package core_auth
* @copyright 2018 Mihail Geshoski <mihail@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_auth\output;
defined('MOODLE_INTERNAL') || die();
use renderable;
use renderer_base;
use templatable;
/**
* Digital minor renderable class.
*
* @copyright 2018 Mihail Geshoski <mihail@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class digital_minor_page implements renderable, templatable {
/**
* Export the page data for the mustache template.
*
* @param renderer_base $output renderer to be used to render the page elements.
* @return stdClass
*/
public function export_for_template(renderer_base $output) {
global $SITE, $CFG;
$sitename = format_string($SITE->fullname);
$supportname = $CFG->supportname;
$supportemail = $CFG->supportemail ?? null;
$context = [
'sitename' => $sitename,
'supportname' => $supportname,
'supportemail' => $supportemail,
'homelink' => new \moodle_url('/')
];
return $context;
}
}
+192
View File
@@ -0,0 +1,192 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Login renderable.
*
* @package core_auth
* @copyright 2016 Frédéric Massart - FMCorz.net
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_auth\output;
use context_system;
use help_icon;
use moodle_url;
use renderable;
use renderer_base;
use stdClass;
use templatable;
/**
* Login renderable class.
*
* @package core_auth
* @copyright 2016 Frédéric Massart - FMCorz.net
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class login implements renderable, templatable {
/** @var bool Whether to auto focus the form fields. */
public $autofocusform;
/** @var bool Whether we can login as guest. */
public $canloginasguest;
/** @var bool Whether we can login by e-mail. */
public $canloginbyemail;
/** @var bool Whether we can sign-up. */
public $cansignup;
/** @var help_icon The cookies help icon. */
public $cookieshelpicon;
/** @var string The error message, if any. */
public $error;
/** @var string The info message, if any. */
public $info;
/** @var moodle_url Forgot password URL. */
public $forgotpasswordurl;
/** @var array Additional identify providers, contains the keys 'url', 'name' and 'icon'. */
public $identityproviders;
/** @var string Login instructions, if any. */
public $instructions;
/** @var moodle_url The form action login URL. */
public $loginurl;
/** @var moodle_url The sign-up URL. */
public $signupurl;
/** @var string The user name to pre-fill the form with. */
public $username;
/** @var string The language selector menu. */
public $languagemenu;
/** @var string The csrf token to limit login to requests that come from the login form. */
public $logintoken;
/** @var string Maintenance message, if Maintenance is enabled. */
public $maintenance;
/** @var string ReCaptcha element HTML. */
public $recaptcha;
/** @var bool Toggle the password visibility icon. */
public $togglepassword;
/** @var bool Toggle the password visibility icon for small screens only. */
public $smallscreensonly;
/**
* Constructor.
*
* @param array $authsequence The enabled sequence of authentication plugins.
* @param string $username The username to display.
*/
public function __construct(array $authsequence, $username = '') {
global $CFG, $OUTPUT, $PAGE;
$this->username = $username;
$languagedata = new \core\output\language_menu($PAGE);
$this->languagemenu = $languagedata->export_for_action_menu($OUTPUT);
$this->canloginasguest = $CFG->guestloginbutton && !isguestuser();
$this->canloginbyemail = !empty($CFG->authloginviaemail);
$this->cansignup = $CFG->registerauth == 'email' || !empty($CFG->registerauth);
if ($CFG->rememberusername == 0) {
$this->cookieshelpicon = new help_icon('cookiesenabledonlysession', 'core');
} else {
$this->cookieshelpicon = new help_icon('cookiesenabled', 'core');
}
$this->autofocusform = !empty($CFG->loginpageautofocus);
$this->forgotpasswordurl = new moodle_url('/login/forgot_password.php');
$this->loginurl = new moodle_url('/login/index.php');
$this->signupurl = new moodle_url('/login/signup.php');
// Authentication instructions.
$this->instructions = $CFG->auth_instructions;
if (is_enabled_auth('none')) {
$this->instructions = get_string('loginstepsnone');
} else if ($CFG->registerauth == 'email' && empty($this->instructions)) {
$this->instructions = get_string('loginsteps', 'core', 'signup.php');
}
if ($CFG->maintenance_enabled == true) {
if (!empty($CFG->maintenance_message)) {
$this->maintenance = $CFG->maintenance_message;
} else {
$this->maintenance = get_string('sitemaintenance', 'admin');
}
}
// Identity providers.
$this->identityproviders = \auth_plugin_base::get_identity_providers($authsequence);
$this->logintoken = \core\session\manager::get_login_token();
// ReCaptcha.
if (login_captcha_enabled()) {
require_once($CFG->libdir . '/recaptchalib_v2.php');
$this->recaptcha = recaptcha_get_challenge_html(RECAPTCHA_API_URL, $CFG->recaptchapublickey);
}
// Toggle password visibility icon.
$this->togglepassword = get_config('core', 'loginpasswordtoggle') == TOGGLE_SENSITIVE_ENABLED ||
get_config('core', 'loginpasswordtoggle') == TOGGLE_SENSITIVE_SMALL_SCREENS_ONLY;
$this->smallscreensonly = get_config('core', 'loginpasswordtoggle') == TOGGLE_SENSITIVE_SMALL_SCREENS_ONLY;
}
/**
* Set the error message.
*
* @param string $error The error message.
*/
public function set_error($error) {
$this->error = $error;
}
/**
* Set the info message.
*
* @param string $info The info message.
*/
public function set_info(string $info): void {
$this->info = $info;
}
public function export_for_template(renderer_base $output) {
$identityproviders = \auth_plugin_base::prepare_identity_providers_for_output($this->identityproviders, $output);
$data = new stdClass();
$data->autofocusform = $this->autofocusform;
$data->canloginasguest = $this->canloginasguest;
$data->canloginbyemail = $this->canloginbyemail;
$data->cansignup = $this->cansignup;
$data->cookieshelpicon = $this->cookieshelpicon->export_for_template($output);
$data->error = $this->error;
$data->info = $this->info;
$data->forgotpasswordurl = $this->forgotpasswordurl->out(false);
$data->hasidentityproviders = !empty($this->identityproviders);
$data->hasinstructions = !empty($this->instructions) || $this->cansignup;
$data->identityproviders = $identityproviders;
list($data->instructions, $data->instructionsformat) = \core_external\util::format_text($this->instructions, FORMAT_MOODLE,
context_system::instance()->id);
$data->loginurl = $this->loginurl->out(false);
$data->signupurl = $this->signupurl->out(false);
$data->username = $this->username;
$data->logintoken = $this->logintoken;
$data->maintenance = format_text($this->maintenance, FORMAT_MOODLE);
$data->languagemenu = $this->languagemenu;
$data->recaptcha = $this->recaptcha;
$data->togglepassword = $this->togglepassword;
$data->smallscreensonly = $this->smallscreensonly;
return $data;
}
}
@@ -0,0 +1,81 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Age and location verification renderable.
*
* @package core_auth
* @copyright 2018 Mihail Geshoski <mihail@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_auth\output;
defined('MOODLE_INTERNAL') || die();
use renderable;
use renderer_base;
use templatable;
require_once($CFG->libdir.'/formslib.php');
/**
* Age and location verification renderable class.
*
* @copyright 2018 Mihail Geshoski <mihail@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class verify_age_location_page implements renderable, templatable {
/** @var \moodleform The form object */
protected $form;
/** @var string Error message */
protected $errormessage;
/**
* Constructor
*
* @param \moodleform $form The form object
* @param string $errormessage The error message.
*/
public function __construct($form, $errormessage = null) {
$this->form = $form;
$this->errormessage = $errormessage;
}
/**
* Export the page data for the mustache template.
*
* @param renderer_base $output renderer to be used to render the page elements.
* @return \stdClass
*/
public function export_for_template(renderer_base $output) {
global $SITE;
$sitename = format_string($SITE->fullname);
$formhtml = $this->form->render();
$error = $this->errormessage;
$context = [
'sitename' => $sitename,
'formhtml' => $formhtml,
'error' => $error
];
return $context;
}
}
+103
View File
@@ -0,0 +1,103 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Data provider.
*
* @package core_auth
* @copyright 2018 Frédéric Massart
* @author Frédéric Massart <fred@branchup.tech>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_auth\privacy;
defined('MOODLE_INTERNAL') || die();
use context;
use core_privacy\local\metadata\collection;
use core_privacy\local\request\transform;
use core_privacy\local\request\writer;
/**
* Data provider class.
*
* @package core_auth
* @copyright 2018 Frédéric Massart
* @author Frédéric Massart <fred@branchup.tech>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider implements
\core_privacy\local\metadata\provider,
\core_privacy\local\request\user_preference_provider {
/**
* Returns metadata.
*
* @param collection $collection The initialised collection to add items to.
* @return collection A listing of user data stored through this system.
*/
public static function get_metadata(collection $collection): collection {
$collection->add_user_preference('auth_forcepasswordchange', 'privacy:metadata:userpref:forcepasswordchange');
$collection->add_user_preference('create_password', 'privacy:metadata:userpref:createpassword');
$collection->add_user_preference('login_failed_count', 'privacy:metadata:userpref:loginfailedcount');
$collection->add_user_preference('login_failed_count_since_success',
'privacy:metadata:userpref:loginfailedcountsincesuccess');
$collection->add_user_preference('login_failed_last', 'privacy:metadata:userpref:loginfailedlast');
$collection->add_user_preference('login_lockout', 'privacy:metadata:userpref:loginlockout');
$collection->add_user_preference('login_lockout_ignored', 'privacy:metadata:userpref:loginlockoutignored');
$collection->add_user_preference('login_lockout_secret', 'privacy:metadata:userpref:loginlockoutsecret');
return $collection;
}
/**
* Export all user preferences for the plugin.
*
* @param int $userid The userid of the user whose data is to be exported.
*/
public static function export_user_preferences(int $userid) {
$yesno = function($v) {
return transform::yesno($v);
};
$datetime = function($v) {
return $v ? transform::datetime($v) : null;
};
$prefs = [
['auth_forcepasswordchange', 'forcepasswordchange', $yesno],
['create_password', 'createpassword', $yesno],
['login_failed_count', 'loginfailedcount', null],
['login_failed_count_since_success', 'loginfailedcountsincesuccess', null],
['login_failed_last', 'loginfailedlast', $datetime],
['login_lockout', 'loginlockout', $datetime],
['login_lockout_ignored', 'loginlockoutignored', $yesno],
['login_lockout_secret', 'loginlockoutsecret', null],
];
foreach ($prefs as $prefdata) {
list($prefname, $langkey, $transformer) = $prefdata;
$value = get_user_preferences($prefname, null, $userid);
if ($value === null) {
continue;
}
writer::export_user_preference('core_auth', $prefname, $transformer ? $transformer($value) : $value,
get_string("privacy:metadata:userpref:{$langkey}", 'core_auth'));
}
}
}