Jump to content

[SOLVED] Log in Employee from module in PrestaShop


Recommended Posts

I have created a module to sign in Employee from an external site in REST like this:

A JSON Post with Authentication token and login/pass => module validate and answer an url with a JWT token like: https://example.com/module/ps_extern_auth/login_jwt?token=FyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJ3d3cuY2FtYS16b25lLmZyIiwiZXhwIjoxNjQzOTA4NjIyLCJlbWFpbCI6ImcubGF0b3JyZUBldmVybGF0cy5jb20iLCJzdWIiOiI0NiJ9.lojt_J1LzeOWYYFCHn5xIuEka-FaEw5OOGk25VXAfNk

When this JWT token is validated, I write this code to login employee:

            $this->context->employee->remote_addr = ip2long(Tools::getRemoteAddr());
            // Update cookie
            $cookie = Context::getContext()->cookie;
            $cookie->id_employee = $this->context->employee->id;
            $cookie->email = $this->context->employee->email;
            $cookie->profile = $this->context->employee->id_profile;
            $cookie->passwd = $this->context->employee->passwd;
            $cookie->remote_addr = $this->context->employee->remote_addr;
            $cookie->write();

Which is the code get from AdminLoginController.php If I var_dump $cookie, I have correct informations. But then, when the employee go to /admin123456/index.php?controller=AdminProducts He is redirected to login page (He's not logged in).

Do I forget something? Thanks for your help.

PrestaShop 1.6 / PHP 7

Edited by GuimDotcom
Solved (see edit history)
Link to comment
Share on other sites

  • GuimDotcom changed the title to [SOLVED] Log in Employee from module in PrestaShop

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...