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/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" 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 %}