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
+215
View File
@@ -0,0 +1,215 @@
<?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/>.
/**
* Authentication Plugin: Manual Authentication
* Just does a simple check against the moodle database.
*
* @package auth_manual
* @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
require_once($CFG->libdir.'/authlib.php');
/**
* Manual authentication plugin.
*
* @package auth
* @subpackage manual
* @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class auth_plugin_manual extends auth_plugin_base {
/**
* The name of the component. Used by the configuration.
*/
const COMPONENT_NAME = 'auth_manual';
const LEGACY_COMPONENT_NAME = 'auth/manual';
/**
* Constructor.
*/
public function __construct() {
$this->authtype = 'manual';
$config = get_config(self::COMPONENT_NAME);
$legacyconfig = get_config(self::LEGACY_COMPONENT_NAME);
$this->config = (object)array_merge((array)$legacyconfig, (array)$config);
}
/**
* Old syntax of class constructor. Deprecated in PHP7.
*
* @deprecated since Moodle 3.1
*/
public function auth_plugin_manual() {
debugging('Use of class name as constructor is deprecated', DEBUG_DEVELOPER);
self::__construct();
}
/**
* Returns true if the username and password work and false if they are
* wrong or don't exist. (Non-mnet accounts only!)
*
* @param string $username The username
* @param string $password The password
* @return bool Authentication success or failure.
*/
function user_login($username, $password) {
global $CFG, $DB, $USER;
if (!$user = $DB->get_record('user', array('username'=>$username, 'mnethostid'=>$CFG->mnet_localhost_id))) {
return false;
}
if (!validate_internal_user_password($user, $password)) {
return false;
}
if ($password === 'changeme') {
// force the change - this is deprecated and it makes sense only for manual auth,
// because most other plugins can not change password easily or
// passwords are always specified by users
set_user_preference('auth_forcepasswordchange', true, $user->id);
}
return true;
}
/**
* Updates the user's password.
*
* Called when the user password is updated.
*
* @param object $user User table object
* @param string $newpassword Plaintext password
* @return boolean result
*/
function user_update_password($user, $newpassword) {
$user = get_complete_user_data('id', $user->id);
set_user_preference('auth_manual_passwordupdatetime', time(), $user->id);
// This will also update the stored hash to the latest algorithm
// if the existing hash is using an out-of-date algorithm (or the
// legacy md5 algorithm).
return update_internal_user_password($user, $newpassword);
}
function prevent_local_passwords() {
return false;
}
/**
* Returns true if this authentication plugin is 'internal'.
*
* @return bool
*/
function is_internal() {
return true;
}
/**
* Returns true if this authentication plugin can change the user's
* password.
*
* @return bool
*/
function can_change_password() {
return true;
}
/**
* Returns the URL for changing the user's pw, or empty if the default can
* be used.
*
* @return moodle_url
*/
function change_password_url() {
return null;
}
/**
* Returns true if plugin allows resetting of internal password.
*
* @return bool
*/
function can_reset_password() {
return true;
}
/**
* Returns true if plugin can be manually set.
*
* @return bool
*/
function can_be_manually_set() {
return true;
}
/**
* Return number of days to user password expires.
*
* If user password does not expire, it should return 0 or a positive value.
* If user password is already expired, it should return negative value.
*
* @param mixed $username username (with system magic quotes)
* @return integer
*/
public function password_expire($username) {
$result = 0;
if (!empty($this->config->expirationtime)) {
$user = core_user::get_user_by_username($username, 'id,timecreated');
$lastpasswordupdatetime = get_user_preferences('auth_manual_passwordupdatetime', $user->timecreated, $user->id);
$expiretime = $lastpasswordupdatetime + $this->config->expirationtime * DAYSECS;
$now = time();
$result = ($expiretime - $now) / DAYSECS;
if ($expiretime > $now) {
$result = ceil($result);
} else {
$result = floor($result);
}
}
return $result;
}
/**
* Confirm the new user as registered. This should normally not be used,
* but it may be necessary if the user auth_method is changed to manual
* before the user is confirmed.
*
* @param string $username
* @param string $confirmsecret
*/
function user_confirm($username, $confirmsecret = null) {
global $DB;
$user = get_complete_user_data('username', $username);
if (!empty($user)) {
if ($user->confirmed) {
return AUTH_CONFIRM_ALREADY;
} else {
$DB->set_field("user", "confirmed", 1, array("id"=>$user->id));
return AUTH_CONFIRM_OK;
}
} else {
return AUTH_CONFIRM_ERROR;
}
}
}
+72
View File
@@ -0,0 +1,72 @@
<?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/>.
/**
* Privacy Subsystem implementation for auth_manual.
*
* @package auth_manual
* @copyright 2018 Carlos Escobedo <carlos@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace auth_manual\privacy;
defined('MOODLE_INTERNAL') || die();
use \core_privacy\local\request\writer;
use \core_privacy\local\metadata\collection;
use \core_privacy\local\request\transform;
/**
* Privacy provider for the authentication manual.
*
* @copyright 2018 Carlos Escobedo <carlos@moodle.com>
* @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 meta data about this system.
*
* @param collection $collection The initialised item collection to add items to.
* @return collection A listing of user data stored through this system.
*/
public static function get_metadata(collection $collection): collection {
// There is a one user preference.
$collection->add_user_preference('auth_manual_passwordupdatetime',
'privacy:metadata:preference:passwordupdatetime');
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) {
$lastpasswordupdatetime = get_user_preferences('auth_manual_passwordupdatetime', null, $userid);
if ($lastpasswordupdatetime !== null) {
$time = transform::datetime($lastpasswordupdatetime);
writer::export_user_preference('auth_manual',
'auth_manual_passwordupdatetime',
$time,
get_string('privacy:metadata:preference:passwordupdatetime', 'auth_manual')
);
}
}
}
+44
View File
@@ -0,0 +1,44 @@
<?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/>.
/**
* Manual authentication plugin upgrade code
*
* @package auth_manual
* @copyright 2011 Petr Skoda (http://skodak.org)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/**
* Function to upgrade auth_manual.
* @param int $oldversion the version we are upgrading from
* @return bool result
*/
function xmldb_auth_manual_upgrade($oldversion) {
// Automatically generated Moodle v4.1.0 release upgrade line.
// Put any upgrade step following this.
// Automatically generated Moodle v4.2.0 release upgrade line.
// Put any upgrade step following this.
// Automatically generated Moodle v4.3.0 release upgrade line.
// Put any upgrade step following this.
// Automatically generated Moodle v4.4.0 release upgrade line.
// Put any upgrade step following this.
return true;
}
+34
View File
@@ -0,0 +1,34 @@
<?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/>.
/**
* Strings for component 'auth_manual', language 'en'.
*
* @package auth_manual
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$string['auth_manualdescription'] = 'This method removes any way for users to create their own accounts. All accounts must be manually created by the admin user.';
$string['expiration'] = 'Enable password expiry';
$string['expiration_desc'] = 'Allow passwords to expire after a specified time.';
$string['expiration_warning'] = 'Notification threshold';
$string['expiration_warning_desc'] = 'Number of days before password expiry that a notification is issued.';
$string['passwdexpiretime'] = 'Password duration';
$string['passwdexpiretime_desc'] = 'Length of time for which a password is valid.';
$string['pluginname'] = 'Manual accounts';
$string['passwdexpire_settings'] = 'Password expiry settings';
$string['privacy:metadata:preference:passwordupdatetime'] = 'The date of the last password change.';
+78
View File
@@ -0,0 +1,78 @@
<?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/>.
/**
* Admin settings and defaults
*
* @package auth_manual
* @copyright 2017 Stephen Bourget
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die;
if ($ADMIN->fulltree) {
// Introductory explanation.
$settings->add(new admin_setting_heading('auth_manual/pluginname',
new lang_string('passwdexpire_settings', 'auth_manual'),
new lang_string('auth_manualdescription', 'auth_manual')));
$expirationoptions = array(
new lang_string('no'),
new lang_string('yes'),
);
$settings->add(new admin_setting_configselect('auth_manual/expiration',
new lang_string('expiration', 'auth_manual'),
new lang_string('expiration_desc', 'auth_manual'), 0, $expirationoptions));
$expirationtimeoptions = array(
'30' => new lang_string('numdays', '', 30),
'60' => new lang_string('numdays', '', 60),
'90' => new lang_string('numdays', '', 90),
'120' => new lang_string('numdays', '', 120),
'150' => new lang_string('numdays', '', 150),
'180' => new lang_string('numdays', '', 180),
'365' => new lang_string('numdays', '', 365),
);
$settings->add(new admin_setting_configselect('auth_manual/expirationtime',
new lang_string('passwdexpiretime', 'auth_manual'),
new lang_string('passwdexpiretime_desc', 'auth_manual'), 30, $expirationtimeoptions));
$expirationwarningoptions = array(
'0' => new lang_string('never'),
'1' => new lang_string('numdays', '', 1),
'2' => new lang_string('numdays', '', 2),
'3' => new lang_string('numdays', '', 3),
'4' => new lang_string('numdays', '', 4),
'5' => new lang_string('numdays', '', 5),
'6' => new lang_string('numdays', '', 6),
'7' => new lang_string('numdays', '', 7),
'10' => new lang_string('numdays', '', 10),
'14' => new lang_string('numdays', '', 14),
);
$settings->add(new admin_setting_configselect('auth_manual/expiration_warning',
new lang_string('expiration_warning', 'auth_manual'),
new lang_string('expiration_warning_desc', 'auth_manual'), 0, $expirationwarningoptions));
// Display locking / mapping of profile fields.
$authplugin = get_auth_plugin('manual');
display_auth_lock_options($settings, $authplugin->authtype,
$authplugin->userfields, get_string('auth_fieldlocks_help', 'auth'), false, false);
}
@@ -0,0 +1,28 @@
@auth @auth_manual
Feature: Test manual authentication works.
In order to check manual authentication
As a teacher
I need to go on login page and enter username and password.
Background:
Given the following "users" exist:
| username |
| teacher1 |
@javascript
Scenario: Check login works with javascript.
Given I am on homepage
And I expand navigation bar
And I click on "Log in" "link" in the ".logininfo" "css_element"
When I set the field "Username" to "teacher1"
And I set the field "Password" to "teacher1"
When I press "Log in"
Then I should see "You are logged in as"
Scenario: Check login works without javascript.
Given I am on homepage
And I click on "Log in" "link" in the ".logininfo" "css_element"
When I set the field "Username" to "teacher1"
And I set the field "Password" to "teacher1"
When I press "Log in"
Then I should see "You are logged in as"
+88
View File
@@ -0,0 +1,88 @@
<?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/>.
namespace auth_manual;
use auth_plugin_manual;
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->dirroot.'/auth/manual/auth.php');
/**
* Manual authentication tests class.
*
* @package auth_manual
* @category test
* @copyright 2014 Gilles-Philippe Leblanc <gilles-philippe.leblanc@umontreal.ca>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class manual_test extends \advanced_testcase {
/** @var auth_plugin_manual Keeps the authentication plugin. */
protected $authplugin;
/**
* Setup test data.
*/
protected function setUp(): void {
$this->resetAfterTest(true);
$this->authplugin = new auth_plugin_manual();
set_config('expiration', '1', 'auth_manual');
set_config('expiration_warning', '2', 'auth_manual');
set_config('expirationtime', '30', 'auth_manual');
$this->authplugin->config = get_config(auth_plugin_manual::COMPONENT_NAME);
}
/**
* Test user_update_password method.
*/
public function test_user_update_password(): void {
$user = $this->getDataGenerator()->create_user();
$expectedtime = time();
$passwordisupdated = $this->authplugin->user_update_password($user, 'MyNewPassword*');
// Assert that the actual time should be equal or a little greater than the expected time.
$this->assertGreaterThanOrEqual($expectedtime, get_user_preferences('auth_manual_passwordupdatetime', 0, $user->id));
// Assert that the password was successfully updated.
$this->assertTrue($passwordisupdated);
}
/**
* Test test_password_expire method.
*/
public function test_password_expire(): void {
$userrecord = array();
$expirationtime = 31 * DAYSECS;
$userrecord['timecreated'] = time() - $expirationtime;
$user1 = $this->getDataGenerator()->create_user($userrecord);
$user2 = $this->getDataGenerator()->create_user();
// The user 1 was created 31 days ago and has not changed his password yet, so the password has expirated.
$this->assertLessThanOrEqual(-1, $this->authplugin->password_expire($user1->username));
// The user 2 just came to be created and has not changed his password yet, so the password has not expirated.
$this->assertEquals(30, $this->authplugin->password_expire($user2->username));
$this->authplugin->user_update_password($user1, 'MyNewPassword*');
// The user 1 just updated his password so the password has not expirated.
$this->assertEquals(30, $this->authplugin->password_expire($user1->username));
}
}
@@ -0,0 +1,71 @@
<?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/>.
/**
* Base class for unit tests for auth_manual.
*
* @package auth_manual
* @category test
* @copyright 2018 Carlos Escobedo <carlos@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace auth_manual\privacy;
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->dirroot.'/auth/manual/auth.php');
use core_privacy\local\request\writer;
use core_privacy\local\request\transform;
use auth_manual\privacy\provider;
/**
* Unit tests for the auth_manual implementation of the privacy API.
*
* @copyright 2018 Carlos Escobedo <carlos@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider_test extends \core_privacy\tests\provider_testcase {
/** @var \auth_plugin_manual Keeps the authentication plugin. */
protected $authplugin;
/**
* Basic setup for these tests.
*/
public function setUp(): void {
$this->resetAfterTest(true);
$this->authplugin = new \auth_plugin_manual();
}
/**
* Test to check export_user_preferences.
* returns user preferences data.
*/
public function test_export_user_preferences(): void {
$user = $this->getDataGenerator()->create_user();
$this->authplugin->user_update_password($user, 'MyPrivacytestPassword*');
provider::export_user_preferences($user->id);
$writer = writer::with_context(\context_system::instance());
$prefs = $writer->get_user_preferences('auth_manual');
$time = transform::datetime(get_user_preferences('auth_manual_passwordupdatetime', 0, $user->id));
$this->assertEquals($time, $prefs->auth_manual_passwordupdatetime->value);
$this->assertEquals(get_string('privacy:metadata:preference:passwordupdatetime', 'auth_manual'),
$prefs->auth_manual_passwordupdatetime->description);
}
}
+7
View File
@@ -0,0 +1,7 @@
This files describes API changes in /auth/manual/*,
information provided here is intended especially for developers.
=== 3.3 ===
* The config.html file was migrated to use the admin settings API.
The identifier for configuration data stored in config_plugins table was converted from 'auth/manual' to 'auth_manual'.
+29
View File
@@ -0,0 +1,29 @@
<?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/>.
/**
* Manual authentication plugin version information
*
* @package auth_manual
* @copyright 2011 Petr Skoda (http://skodak.org)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2024042200; // The current plugin version (Date: YYYYMMDDXX).
$plugin->requires = 2024041600; // Requires this Moodle version.
$plugin->component = 'auth_manual'; // Full name of the plugin (used for diagnostics)