Jump to content

Override Prestashop 1.7 Login System


MMax

Recommended Posts

Hello,

I am developing a PrestaShop website for a client which have multiple web apps. All these web apps (on different domains) are included into a "Single-Sign-On" system, with an authentication api on a separate domain.

I need to include this login system into PrestaShop and do the login automatically if the user is already logged in on any of the other web apps.

Can anyone tell me how to properly override the PrestaShop login system to do this ?

I know I have to override this, and call it from a JavaScript or external php file, but will PrestaShop allow me to do that ?

public function submit()
    {
        if ($this->validate()) {
            Hook::exec('actionAuthenticationBefore');

            $customer = new Customer();
            $authentication = $customer->getByEmail(
                $this->getValue('email'),
                $this->getValue('password')
            );

            if (isset($authentication->active) && !$authentication->active) {
                $this->errors[''][] = $this->translator->trans('Your account isn\'t available at this time, please contact us', [], 'Shop.Notifications.Error');
            } elseif (!$authentication || !$customer->id || $customer->is_guest) {
                $this->errors[''][] = $this->translator->trans('Authentication failed.', [], 'Shop.Notifications.Error');
            } else {
                $this->context->updateCustomer($customer);

                Hook::exec('actionAuthentication', ['customer' => $this->context->customer]);

                // Login information have changed, so we check if the cart rules still apply
                CartRule::autoRemoveFromCart($this->context);
                CartRule::autoAddToCart($this->context);
            }
        }

        return !$this->hasErrors();
    }

PS: I already overrided some classes, but the login seems to be a more complicated step, as it should use an externale login, and then use the PrestaShop account informations

Link to comment
Share on other sites

I finally found a solution.

The PrestaShop 1.7 system is very restricted, so trying to access it from outside is not the good way.

The good way is to create a new Controller inside PrestaShop, and access the newly created controller from the outside.

I created a controller in prestashop/controllers/front/[ControllerName].php

Then, it is accessible at prestashopurl/index.php?controller=[ControllerName]

  • Like 1
Link to comment
Share on other sites

  • 5 years later...
On 2/13/2018 at 3:05 PM, MMax said:

I finally found a solution.

The PrestaShop 1.7 system is very restricted, so trying to access it from outside is not the good way.

The good way is to create a new Controller inside PrestaShop, and access the newly created controller from the outside.

I created a controller in prestashop/controllers/front/[ControllerName].php

Then, it is accessible at prestashopurl/index.php?controller=[ControllerName]

Hello, 

Have you found how to enable sso between your sites ? 

I am looking for a sso solution to enable my customers to only log once on the main site and be able to browse all other sites from the same multistores environment. 

Thanks

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...