Skip to content

Commit 110f7fc

Browse files
committed
Add config "generate_random_login" when importing users by csv BT#13944
1 parent f754acb commit 110f7fc

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

main/admin/user_import.php

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,13 @@ function validate_data($users, $checkUniqueEmail = false)
5353
$errors[] = $user;
5454
}
5555
// 2.2. Check whether the username was used twice in import file.
56-
if (isset($usernames[$user['UserName']])) {
56+
if (isset($usernames[$username])) {
5757
$user['error'] = get_lang('UserNameUsedTwice');
5858
$errors[] = $user;
5959
}
60-
$usernames[$user['UserName']] = 1;
60+
$usernames[$username] = 1;
6161
// 2.3. Check whether username is already occupied.
62-
if (!UserManager::is_username_available($user['UserName'])) {
62+
if (!UserManager::is_username_available($username)) {
6363
$user['error'] = get_lang('UserNameNotAvailable');
6464
$errors[] = $user;
6565
}
@@ -260,8 +260,21 @@ function save_data($users)
260260
*/
261261
function parse_csv_data($file)
262262
{
263-
$users = Import :: csvToArray($file);
263+
$users = Import::csvToArray($file);
264+
$allowRandom = api_get_configuration_value('generate_random_login');
265+
if ($allowRandom) {
266+
$factory = new RandomLib\Factory;
267+
$generator = $factory->getLowStrengthGenerator();
268+
$chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
269+
}
270+
264271
foreach ($users as $index => $user) {
272+
if (isset($user['UserName'])) {
273+
if ($allowRandom) {
274+
$username = $generator->generateString(10, $chars);
275+
$user['UserName'] = $username;
276+
}
277+
}
265278
if (isset($user['Courses'])) {
266279
$user['Courses'] = explode('|', trim($user['Courses']));
267280
}
@@ -485,7 +498,7 @@ function parse_xml_data($file)
485498
}
486499
}
487500

488-
Display :: display_header($tool_name);
501+
Display::display_header($tool_name);
489502

490503
$form = new FormValidator('user_import', 'post', api_get_self());
491504
$form->addElement('header', '', $tool_name);

main/install/configuration.dist.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -732,6 +732,12 @@
732732
// Allow teachers, drhs and admins to access blocked LP's because a prerequisite.
733733
//$_configuration['allow_teachers_to_access_blocked_lp_by_prerequisite'] = false;
734734

735+
// Allow connect skills with course tools
736+
//$_configuration['allow_skill_rel_items'] = false;
737+
738+
// Generate random login when importing users
739+
//$_configuration['generate_random_login'] = false;
740+
735741
// ------ Custom DB changes
736742
// Add user activation by confirmation email
737743
// This option prevents the new user to login in the platform if your account is not confirmed via email

0 commit comments

Comments
 (0)