diff --git a/app/services.php b/app/services.php index f68a3734e8..74cd4c07d1 100644 --- a/app/services.php +++ b/app/services.php @@ -158,7 +158,7 @@ return [ 'server_plugins' => ['class' => Plugins::class, 'arguments' => ['@dbi']], 'server_privileges' => [ 'class' => Privileges::class, - 'arguments' => ['@template', '@dbi', '@relation', '@relation_cleanup', '@server_plugins'], + 'arguments' => ['@template', '@dbi', '@relation', '@relation_cleanup', '@server_plugins', '@config'], ], 'server_privileges_account_locking' => [ 'class' => AccountLocking::class, diff --git a/app/services_controllers.php b/app/services_controllers.php index 874ac5a3b3..f0df786faf 100644 --- a/app/services_controllers.php +++ b/app/services_controllers.php @@ -700,6 +700,7 @@ return [ '$relation' => '@relation', '$dbi' => '@dbi', '$userPrivilegesFactory' => '@' . UserPrivilegesFactory::class, + '$config' => '@config', ], ], Server\ReplicationController::class => [ diff --git a/resources/js/src/modules/functions.ts b/resources/js/src/modules/functions.ts index e282ca87f6..fa116c6607 100644 --- a/resources/js/src/modules/functions.ts +++ b/resources/js/src/modules/functions.ts @@ -1974,6 +1974,10 @@ export function checkPassword ($theForm) { return true; } +export function shouldShowEmptyPasswordWarning (form): boolean { + return (form.find('#nopass_1').is(':checked') && form.data('allowNoPassword') === 0); +} + export function onloadChangePasswordEvents (): void { /* Handler for hostname type */ $(document).on('change', '#select_pred_hostname', function () { @@ -2067,25 +2071,35 @@ export function onloadChangePasswordEvents (): void { */ var thisValue = $(this).val(); - var $msgbox = ajaxShowMessage(window.Messages.strProcessingRequest); - $theForm.append(''); + var submitForm = function () { + var $msgbox = ajaxShowMessage(window.Messages.strProcessingRequest); + $theForm.append(''); - $.post($theForm.attr('action'), $theForm.serialize() + CommonParams.get('arg_separator') + 'change_pw=' + thisValue, function (data) { - if (typeof data === 'undefined' || data.success !== true) { - ajaxShowMessage(data.error, false); + $.post($theForm.attr('action'), $theForm.serialize() + CommonParams.get('arg_separator') + 'change_pw=' + thisValue, function (data) { + if (typeof data === 'undefined' || data.success !== true) { + ajaxShowMessage(data.error, false); - return; - } + return; + } - var $pageContent = $('#page_content'); - $pageContent.prepend(data.message); - highlightSql($pageContent); - $('#change_password_dialog').hide().remove(); - $('#edit_user_dialog').dialog('close').remove(); - ajaxRemoveMessage($msgbox); - }); // end $.post() + var $pageContent = $('#page_content'); + $pageContent.prepend(data.message); + highlightSql($pageContent); + $('#change_password_dialog').hide().remove(); + $('#edit_user_dialog').dialog('close').remove(); + ajaxRemoveMessage($msgbox); + }); // end $.post() - $('#changePasswordModal').modal('hide'); + $('#changePasswordModal').modal('hide'); + }; + + if (shouldShowEmptyPasswordWarning($theForm)) { + $(this).confirm(window.Messages.strPasswordEmptyWhenAllowNoPasswordIsEnabled, '', function () { + submitForm(); + }); + } else { + submitForm(); + } }); $.get($(this).attr('href'), { 'ajax_request': true }, function (data) { diff --git a/resources/js/src/server/privileges.ts b/resources/js/src/server/privileges.ts index 09ced013f8..9acfe92118 100644 --- a/resources/js/src/server/privileges.ts +++ b/resources/js/src/server/privileges.ts @@ -1,6 +1,13 @@ import $ from 'jquery'; import { AJAX } from '../modules/ajax.ts'; -import { checkPassword, checkPasswordStrength, checkboxesSel, displayPasswordGenerateButton, getSqlEditor } from '../modules/functions.ts'; +import { + checkPassword, + checkPasswordStrength, + checkboxesSel, + displayPasswordGenerateButton, + getSqlEditor, + shouldShowEmptyPasswordWarning +} from '../modules/functions.ts'; import { CommonParams } from '../modules/common.ts'; import { Navigation } from '../modules/navigation.ts'; import { ajaxRemoveMessage, ajaxShowMessage } from '../modules/ajax-message.ts'; @@ -475,6 +482,26 @@ const CheckAddUser = { } }; +const CheckEmptyPasswordWhenAllowNoPasswordIsEnabled = { + handleEvent: function () { + const theForm = this; + + if (shouldShowEmptyPasswordWarning($(theForm))) { + $(this).confirm(window.Messages.strPasswordEmptyWhenAllowNoPasswordIsEnabled, '', function () { + theForm.submit(); + + return true; + }); + + return false; + } else { + theForm.submit(); + + return true; + } + } +}; + const selectPasswordRadioWhenChangingPassword = () => { $('#nopass_0').prop('checked', true); }; @@ -561,4 +588,5 @@ AJAX.registerOnload('server/privileges.js', function () { $('#addUsersForm').on('submit', CheckAddUser.handleEvent); $('#copyUserForm').on('submit', CheckAddUser.handleEvent); + $('#change_password_form').on('submit', CheckEmptyPasswordWhenAllowNoPasswordIsEnabled.handleEvent); }); diff --git a/resources/templates/server/privileges/change_password.twig b/resources/templates/server/privileges/change_password.twig index 3e9dd5ac26..0ea362851b 100644 --- a/resources/templates/server/privileges/change_password.twig +++ b/resources/templates/server/privileges/change_password.twig @@ -1,5 +1,5 @@