Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an option to disable password reset #2431

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions blueprints.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions classes/plugin/Controllers/Login/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);

Expand All @@ -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');

Expand Down Expand Up @@ -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';
}
}
2 changes: 2 additions & 0 deletions languages/en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
2 changes: 2 additions & 0 deletions languages/es.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
2 changes: 2 additions & 0 deletions languages/lt.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
7 changes: 6 additions & 1 deletion themes/grav/templates/partials/login-form.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@
{% endembed %}

<div class="form-actions primary-accent">
<a class="button secondary" href="{{ admin_route('/forgot') }}"><i class="fa fa-exclamation-circle"></i> {{ 'PLUGIN_ADMIN.LOGIN_BTN_FORGOT'|t }}</a>
{% if
config.plugins.admin.password_reset_enabled is not same as false
and config.plugins.email.mailer.engine != "none"
%}
<a class="button secondary" href="{{ admin_route('/forgot') }}"><i class="fa fa-exclamation-circle"></i> {{ 'PLUGIN_ADMIN.LOGIN_BTN_FORGOT'|t }}</a>
{% endif %}
<button type="submit" class="button primary" name="task" value="login"><i class="fa fa-sign-in"></i> {{ 'PLUGIN_ADMIN.LOGIN_BTN'|t }}</button>
</div>

Expand Down