Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for issues #1, #2 and #3 #5

Merged
merged 1 commit into from
Nov 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
This generator uses the Marvel API to generate users from your favorite characters in your Moodle instance.

To generate a user just type the name and press the button. The user will be automatically created in your Moodle instance. This user will be created with the name, profile picture and description.
By default the password for all generated users is 'Passw0rd'.
By default the password for all generated users will be generated randomly, but you have the option to add your own password manually.

You can get your own keys for free signing up at https://developer.marvel.com. All characters generated by this plugin are property of Marvel.

9 changes: 9 additions & 0 deletions classes/form.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,15 @@ public function definition() {
$mform->setDefault('quantity', 3);
$mform->hideIf('quantity', 'type', 'noteq', constants::RANDOM);

// Password.
$group = [];
$group[] =& $mform->createElement('password', 'password');
$group[] =& $mform->createElement('checkbox', 'randompassword', get_string('randompassword', 'tool_powerusers'), null);
$mform->setType('password', PARAM_TEXT);
$mform->addGroup($group, 'passwordgroup', get_string('password', 'moodle'), ' ', false);
$mform->disabledIf('password', 'randompassword', 'eq', 1);
$mform->setDefault('randompassword', 1);

$this->add_action_buttons(false, get_string('generateprogram', 'tool_powerusers'));
}

Expand Down
6 changes: 5 additions & 1 deletion classes/generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ class generator {
public function generate_users(stdClass $data): array {
$created = 0;

$password = (!empty($data->randompassword)) ? generate_password() : trim($data->password);

// Generate users manually entering the name.
if ((int) $data->type === constants::MANUAL) {
$results = marvelapi::get_users($data->name, $data->searchaccuracy);
Expand All @@ -51,6 +53,7 @@ public function generate_users(stdClass $data): array {

foreach ($results as $result) {
$user = marvelapi::get_user_data($result);
$user['password'] = $password;
if ($this->create_user($user)) {
$created++;
}
Expand All @@ -71,6 +74,7 @@ public function generate_users(stdClass $data): array {

$result = reset($results);
$user = marvelapi::get_user_data($result);
$user['password'] = $password;
if ($this->create_user($user)) {
$created++;
}
Expand Down Expand Up @@ -104,7 +108,7 @@ private function create_user(array $record): bool {
$record['alternatename'] = '';
$record['idnumber'] = '';
$record['mnethostid'] = $CFG->mnet_localhost_id;
$record['password'] = hash_internal_user_password('Passw0rd');
$record['password'] = hash_internal_user_password($record['password']);
$record['email'] = $record['username'] . '@example.com';
$record['confirmed'] = 1;
$record['lastip'] = '0.0.0.0';
Expand Down
39 changes: 39 additions & 0 deletions classes/privacy/provider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?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 tool_powerusers\privacy;

defined('MOODLE_INTERNAL') || die();

/**
* Privacy provider implementation for tool powerusers
*
* @package tool_powerusers
* @copyright 2022 David Matamoros <davidmc@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider implements \core_privacy\local\metadata\null_provider {

/**
* Get the language string identifier with the component's language
* file to explain why this plugin stores no data.
*
* @return string
*/
public static function get_reason(): string {
return 'privacy:metadata';
}
}
4 changes: 3 additions & 1 deletion index.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@
require_once(__DIR__ . '/../../../config.php');

require_login();
$systemcontext = context_system::instance();
require_capability('moodle/site:config', $systemcontext);

$url = new moodle_url('/admin/tool/powerusers/index.php');

$pluginname = get_string('pluginname', 'tool_powerusers');
$PAGE->set_context(context_system::instance());
$PAGE->set_context($systemcontext);
$PAGE->set_url($url);
$PAGE->set_pagelayout('report');
$PAGE->set_title($pluginname);
Expand Down
2 changes: 2 additions & 0 deletions lang/en/tool_powerusers.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@
$string['missingprivatekey'] = 'Private key is missing';
$string['missingpublickey'] = 'Public key is missing';
$string['pluginname'] = 'Power users generator';
$string['privacy:metadata'] = 'The tool powerusers plugin does not store any personal data.';
$string['privatekey'] = 'Private key';
$string['privatekey_desc'] = 'Marvel API Private key';
$string['publickey'] = 'Public key';
$string['publickey_desc'] = 'Marvel API Public key';
$string['quantity'] = 'Amount of users to generate';
$string['randompassword'] = 'Random password';
$string['searchaccuracy'] = 'Type of search for name';
$string['searchexactmatch'] = 'Exact match';
$string['searchmanual'] = 'Search manually for a character\'s name';
Expand Down
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
defined('MOODLE_INTERNAL') || die();

$plugin->component = 'tool_powerusers';
$plugin->version = 2022102700;
$plugin->version = 2022110400;
$plugin->requires = 2015111600;
$plugin->release = '1.0.1';
$plugin->maturity = MATURITY_STABLE;
Expand Down