Skip to content

Commit c92ea79

Browse files
committed
Admin: Add checkbox to ask for new password on users update through CSV import - refs BT#21146
1 parent 2d993de commit c92ea79

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

main/admin/user_update_import.php

+20-5
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,12 @@ function validate_data($users)
8585
* @param bool $resetPassword Optional.
8686
* @param bool $sendEmail Optional.
8787
*/
88-
function updateUsers(
88+
function _updateUsers(
8989
$users,
9090
$resetPassword = false,
91-
$sendEmail = false)
92-
{
91+
$sendEmail = false,
92+
$askNewPassword = false
93+
){
9394
$usergroup = new UserGroup();
9495
$extraFieldValue = new ExtraFieldValue('user');
9596
if (is_array($users)) {
@@ -150,6 +151,10 @@ function updateUsers(
150151
if ($resetPassword && $sendEmail == false) {
151152
$sendEmail = true;
152153
}
154+
$extra = [];
155+
if ($askNewPassword) {
156+
$extra['ask_new_password'] = 1;
157+
}
153158

154159
UserManager::update_user(
155160
$user_id,
@@ -167,7 +172,7 @@ function updateUsers(
167172
$active,
168173
$creatorId,
169174
$hrDeptId,
170-
null,
175+
$extra,
171176
$language,
172177
'',
173178
$sendEmail,
@@ -290,6 +295,14 @@ function parse_xml_data($file)
290295
$form->addHeader($tool_name);
291296
$form->addFile('import_file', get_lang('ImportFileLocation'), ['accept' => 'text/csv', 'id' => 'import_file']);
292297
$form->addCheckBox('reset_password', '', get_lang('AutoGeneratePassword'));
298+
if (api_get_configuration_value('force_renew_password_at_first_login') == true) {
299+
$form->addElement(
300+
'checkbox',
301+
'ask_new_password',
302+
'',
303+
get_lang('FirstLoginForceUsersToChangePassword')
304+
);
305+
}
293306

294307
$group = [
295308
$form->createElement('radio', 'sendMail', '', get_lang('Yes'), 1),
@@ -341,7 +354,9 @@ function parse_xml_data($file)
341354
}
342355

343356
$sendEmail = $_POST['sendMail'] ? true : false;
344-
updateUsers($usersToUpdate, isset($formValues['reset_password']), $sendEmail);
357+
$askNewPassword = isset($formValues['ask_new_password']);
358+
359+
_updateUsers($usersToUpdate, isset($formValues['reset_password']), $sendEmail, $askNewPassword);
345360

346361
if (empty($errors)) {
347362
Display::addFlash(

0 commit comments

Comments
 (0)