From 03fd498c8b76395a77b9108067018873c7470019 Mon Sep 17 00:00:00 2001 From: Karmalakas Date: Fri, 22 Nov 2024 19:29:03 +0200 Subject: [PATCH 1/4] Add an option to disable password reset --- .editorconfig | 17 ---------------- blueprints.yaml | 12 +++++++++++ .../Controllers/Login/LoginController.php | 20 +++++++++++++++++++ languages/en.yaml | 2 ++ languages/lt.yaml | 2 ++ .../templates/partials/login-form.html.twig | 7 ++++++- 6 files changed, 42 insertions(+), 18 deletions(-) delete mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 6375a81e6..000000000 --- a/.editorconfig +++ /dev/null @@ -1,17 +0,0 @@ -# EditorConfig is awesome: https://EditorConfig.org - -# top-most EditorConfig file -root = true - -# Unix-style newlines with a newline ending every file -[*] -charset = utf-8 -end_of_line = lf -trim_trailing_whitespace = true -insert_final_newline = true -indent_style = space -indent_size = 2 - -# 4 space indentation -[*.php] -indent_size = 4 diff --git a/blueprints.yaml b/blueprints.yaml index 921e11e3c..40724f27a 100644 --- a/blueprints.yaml +++ b/blueprints.yaml @@ -72,6 +72,18 @@ form: validate: type: bool + password_reset_enabled: + type: toggle + label: PLUGIN_ADMIN.PASSWORD_RESET_TITLE + help: PLUGIN_ADMIN.PASSWORD_RESET_HELP + default: 1 + highlight: 1 + options: + 1: PLUGIN_ADMIN.YES + 0: PLUGIN_ADMIN.NO + validate: + type: bool + route: type: text label: PLUGIN_ADMIN.ADMIN_PATH diff --git a/classes/plugin/Controllers/Login/LoginController.php b/classes/plugin/Controllers/Login/LoginController.php index 2c7bc2f46..dcf22d7f5 100644 --- a/classes/plugin/Controllers/Login/LoginController.php +++ b/classes/plugin/Controllers/Login/LoginController.php @@ -58,6 +58,10 @@ public function displayLogin(): ResponseInterface */ public function displayForgot(): ResponseInterface { + if (!$this->isResetEnabled()) { + return $this->displayLogin(); + } + $this->page = $this->createPage('forgot'); $this->form = $this->getForm('admin-login-forgot', ['reset' => true]); @@ -73,6 +77,10 @@ public function displayForgot(): ResponseInterface */ public function displayReset(?string $username = null, ?string $token = null): ResponseInterface { + if (!$this->isResetEnabled()) { + return $this->displayLogin(); + } + if ('' === (string)$username || '' === (string)$token) { $this->setMessage($this->translate('PLUGIN_ADMIN.RESET_INVALID_LINK'), 'error'); @@ -639,4 +647,16 @@ private function getAccounts(): UserCollectionInterface { return $this->grav['accounts']; } + + /** + * @return bool + */ + private function isResetEnabled(): bool + { + $config = $this->getConfig(); + + return + $config['plugins']['admin']['password_reset_enabled'] !== false + && $config['plugins']['email']['mailer']['engine'] !== 'none'; + } } diff --git a/languages/en.yaml b/languages/en.yaml index 2f3ec863a..9715cacf5 100644 --- a/languages/en.yaml +++ b/languages/en.yaml @@ -1153,3 +1153,5 @@ PLUGIN_ADMIN: LEGACY_MEDIA_MUTATION: "Legacy Media Manipulation Compatibility" LEGACY_MEDIA_MUTATION_HELP: "Enable this setting only if image manipulation broke after Grav update." BACKWARD_COMPATIBILITY: "Backward Compatibility" + PASSWORD_RESET_TITLE: "Password reset" + PASSWORD_RESET_HELP: "Enable password reset for the admin accounts" diff --git a/languages/lt.yaml b/languages/lt.yaml index 05fd7de0b..95d941b35 100644 --- a/languages/lt.yaml +++ b/languages/lt.yaml @@ -356,3 +356,5 @@ PLUGIN_ADMIN: ERROR_SYSTEM: "Sistemos klaida" CONFIGURATION: "Konfigūracija" DASHBOARD: "Darbastalis" + PASSWORD_RESET_TITLE: "Slaptažodžio atstatymas" + PASSWORD_RESET_HELP: "Įjungti slaptažodžio atstatymą visoms admin paskyroms" diff --git a/themes/grav/templates/partials/login-form.html.twig b/themes/grav/templates/partials/login-form.html.twig index 7f24d1ea9..3b90a9661 100755 --- a/themes/grav/templates/partials/login-form.html.twig +++ b/themes/grav/templates/partials/login-form.html.twig @@ -16,7 +16,12 @@ {% endembed %}
- {{ 'PLUGIN_ADMIN.LOGIN_BTN_FORGOT'|t }} + {% if + config.plugins.admin.password_reset_enabled is not same as false + and config.plugins.email.mailer.engine != "none" + %} + {{ 'PLUGIN_ADMIN.LOGIN_BTN_FORGOT'|t }} + {% endif %}
From dbd23035e335fcdf634cbb5d69d891635c1fcedf Mon Sep 17 00:00:00 2001 From: Karmalakas Date: Fri, 22 Nov 2024 19:31:00 +0200 Subject: [PATCH 2/4] Restore .editorconfig --- .editorconfig | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 000000000..48c894b9f --- /dev/null +++ b/.editorconfig @@ -0,0 +1,17 @@ +# EditorConfig is awesome: https://EditorConfig.org + +# top-most EditorConfig file +root = true + +# Unix-style newlines with a newline ending every file +[*] +charset = utf-8 +end_of_line = lf +trim_trailing_whitespace = true +insert_final_newline = true +indent_style = space +indent_size = 2 + +# 4 space indentation +[*.php] +indent_size = 4 \ No newline at end of file From ffca9306894a9a1e0fd6678785884e35ebc9a707 Mon Sep 17 00:00:00 2001 From: Karmalakas Date: Fri, 22 Nov 2024 19:31:31 +0200 Subject: [PATCH 3/4] Restore .editorconfig 2 --- .editorconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.editorconfig b/.editorconfig index 48c894b9f..6375a81e6 100644 --- a/.editorconfig +++ b/.editorconfig @@ -14,4 +14,4 @@ indent_size = 2 # 4 space indentation [*.php] -indent_size = 4 \ No newline at end of file +indent_size = 4 From 5e911462e2fc3c809a8f511c6e271f33d75d28e0 Mon Sep 17 00:00:00 2001 From: Karmalakas Date: Sat, 23 Nov 2024 00:23:47 +0200 Subject: [PATCH 4/4] Add Spanish translation --- languages/es.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/languages/es.yaml b/languages/es.yaml index 586737011..14bdcfbde 100644 --- a/languages/es.yaml +++ b/languages/es.yaml @@ -1151,3 +1151,5 @@ PLUGIN_ADMIN: LEGACY_MEDIA_MUTATION: "Compatibilidad con la Manipulación de Medios Heredados" LEGACY_MEDIA_MUTATION_HELP: "Active está opción sólo si la manipulación de la imagen se interrumpió después de una actualización de Grav." BACKWARD_COMPATIBILITY: "Compatibilidad con versiones anteriores" + PASSWORD_RESET_TITLE: "Restablecer contraseña" + PASSWORD_RESET_HELP: "Habilitar restablecimiento de contraseña para las cuentas de administrador"