Skip to content

New option to enable/disable forgot button in login form - #304

Closed
pmoreno-rodriguez wants to merge 1 commit into
getgrav:developfrom
pmoreno-rodriguez:develop
Closed

pmoreno-rodriguez wants to merge 1 commit into
getgrav:developfrom
pmoreno-rodriguez:develop

Conversation

@pmoreno-rodriguez

Copy link
Copy Markdown
Contributor

With this option, the user can make use of the Forgot button in the login form.
I have translated almost all language files and fixed the tooltip in the "Remember Me" option.

@pamtbaau

Copy link
Copy Markdown

IMHO, this PR isn't needed because the functionality is already available.

As you can see, template user/plugins/login/templates/partials/login.html.twig (line 58, 59, 60) has already implemented a condition to test whether the "Forgot" button should be displayed. Your code is adding an unnecessary if wrapper.

To disable the Forgot button on restricted/private front-end pages you can simply override the default value for route_forget by clearing or nullifying the value for route_forget in user/config/plugins/login.yaml:

route_forgot:     # <= this maps to line 59: {% set forgot_route = grav.login.getRoute('forgot') %}

When browsing to page with restricted access you'll see the following login:
{578C2E6B-5AA8-47B3-91F2-4400DB03A895}

@pamtbaau

pamtbaau commented Nov 21, 2024 •

Copy link
Copy Markdown

To remove the "Forget" button in Admin login, follow the following steps:

  • In child theme, add the following in user/themes/childtheme/childtheme.php
    use RocketTheme\Toolbox\Event\Event;
    
    public static function getSubscribedEvents() {
          return [
              'onThemeInitialized'    => ['onThemeInitialized', 0],
              ...
          ];
    }
    
    public function onThemeInitialized() {
        if ($this->isAdmin()) {
            $this->enable([
                'onAdminTwigTemplatePaths'  => ['onAdminTwigTemplatePaths', 0],
            ]);
        }
    }
    
    public function onAdminTwigTemplatePaths(Event $event): void {
        $paths = $event['paths'];
        $paths[] = __DIR__ . DS . 'admin/templates';
        $event['paths'] = $paths;
    }
    
  • Copy file user/plugins/admin/themes/grav/templates/partials/login-form.html.twig into folder user/themes/childtheme/admin/templates/partials and remove line 19:
    <a class="button secondary" href="{{ admin_route('/forgot') }}"><i class="fa fa-exclamation-circle"></i> {{ 'PLUGIN_ADMIN.LOGIN_BTN_FORGOT'|t }}</a>
    

The Admin login page now looks like:
{ABC2B10C-D0BA-4267-BE51-B81F47AB2AD6}

@pmoreno-rodriguez

Copy link
Copy Markdown
Contributor Author

Hi @pamtbaau.

I'm very glad to have your wise recommendations again.
This is an example of not reading the code carefully, something that happens to me sometimes.
However, in the help of the Login plugin there should be a few more lines specifying these options.
Maybe I'll give it a go.
For now, I'll withdraw this PR

@pmoreno-rodriguez

Copy link
Copy Markdown
Contributor Author

This PR is not necessary. I'm going to close it

@eleftrik

Copy link
Copy Markdown

To remove the "Forget" button in Admin login, follow the following steps:

Thanks for your solution.

IMHO a YAML option to remove the forget button on the admin login page would be beneficial, especially for less-technical users / non-developers.

@pmoreno-rodriguez

Copy link
Copy Markdown
Contributor Author

I think the same. Grav has a graphical interface for managing many options, why not add one more?
For now I will leave this PR closed, but I do not rule out integrating @pamtbaau 's option as an alternative in the administration panel in the future. As you say, @eleftrik, less technical users (myself included) appreciate that there are many configuration options for the end user.

@Karmalakas

Copy link
Copy Markdown
Contributor

Created a PR here:
getgrav/grav-plugin-admin#2431

@pmoreno-rodriguez

Copy link
Copy Markdown
Contributor Author

To disable the Forgot button on restricted/private front-end pages you can simply override the default value for route_forget by clearing or nullifying the value for route_forget in user/config/plugins/login.yaml:

route_forgot:     # <= this maps to line 59: {% set forgot_route = grav.login.getRoute('forgot') %}

@pamtbaau , one more question. I understand that an admin could leave the forgot_route set, and by setting forgot_button to false, it would not be displayed, but the forgot_route page route would be saved.

But where should I put forgot_button: false? I guess this line:
{% set forgot_button = form.login.forgot_button ?? true %} I expect it to be defined somewhere in a file. I've tried in user/config/plugins/login.yaml, and in my user/pages/login/login.md page, but I can't get it to work.

@pmoreno-rodriguez

Copy link
Copy Markdown
Contributor Author

This is my login.md:

---
title: Login
cache_control: 'private, no-cache, must-revalidate'
login_redirect_here: false
forms:
    login:
        action: null
        method: post
        forgot_button: false
        fields:
            username:
                type: text
                id: username
                placeholder: PLUGIN_LOGIN.USERNAME_EMAIL
                label: PLUGIN_LOGIN.USERNAME_EMAIL
                autofocus: true
                classes: 'form-control form-control-lg'
                outerclasses: 'form-outline mb-4'
            password:
                type: password
                id: password
                placeholder: PLUGIN_LOGIN.PASSWORD
                label: PLUGIN_LOGIN.PASSWORD
                classes: 'form-control form-control-lg'
                outerclasses: 'form-outline mb-4'
    login-twofa:
        action: null
        method: post
        fields:
            2fa_instructions:
                type: display
                markdown: true
                content: PLUGIN_LOGIN.2FA_INSTRUCTIONS
            2fa_code:
                type: text
                id: twofa-code
                autofocus: true
                placeholder: PLUGIN_LOGIN.2FA_CODE_INPUT
permissions:
    inherit: true
visible: false
---

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants