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

FIX #189 - ensure themes are applied for Security::permissionFailure() calls #190

Open
wants to merge 1 commit into
base: 5
Choose a base branch
from
Open
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
6 changes: 6 additions & 0 deletions src/EnablerExtension.php
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is almost there - but I think for this we need to add a new extension hook in framework.

The onBeforeSecurityLogin extension hook is called from Security::preLogin() - but that method is called in two places:

  1. Security::login() - which performs additional work including delegating to alternative authenticators if preLogin() doesn't return a response.
  2. CMSSecurity::preLogin() which should not have the login forms theming.

I think we need to match the pattern that the beforeCallActionHandler and afterCallActionHandler extension hooks follow in Controller::handleAction() - i.e. in Security::login() the following change should be made:

+        $this->extend('beforePreLogin');
+        $preLoginResponse = $this->preLogin();
+        $this->extend('afterPreLogin');
+        if ($preLoginResponse) {
+            return $preLoginResponse;
-        if ($response = $this->preLogin()) {
-            return $response;
         }

Then in this extension implement the following:

    public function beforePreLogin()
    {
        $config = Config::inst();
        SSViewer::set_themes($config->get(EnablerExtension::class, 'login_themes'));
        $this->defaultPageClass = $config->get(Security::class, 'page_class');
        Config::modify()->remove(Security::class, 'page_class');
    }

    public function afterPreLogin()
    {
        Config::inst()->set(Security::class, 'page_class', $this->defaultPageClass);
    }

Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ public function afterCallActionHandler()
Config::inst()->set(Security::class, 'page_class', $this->defaultPageClass);
}

public function onBeforeSecurityLogin()
{
SSViewer::set_themes(Config::inst()->get(EnablerExtension::class, 'login_themes'));
Config::modify()->remove(Security::class, 'page_class');
}

/**
* Returns an RFC1766 compliant locale string, e.g. 'fr-CA'.
*
Expand Down
Loading