PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, October 27, 2022

[FIXED] How to log out an admin user (employee) from back office in Prestashop 1.7?

 October 27, 2022     backoffice, logout, php, prestashop, prestashop-1.7     No comments   

Issue

I am developing a module for PrestaShop and I need to log out a user (employee) from the back office. I see in the back end code that they do it by using

// Find employee
$this->context->employee = new Employee();
$this->context->employee->getByEmail($email, $passwd);
$this->context->employee->logout();

But I can't use it in my module scope since I would need to intercept the credentials from back office login form to create a proper link to the employee, but I can't find a way how. Are there any ways to get these credentials or to log out the user in another way?

P.S. Intercepting user credentials before he logs in and blocking him from logging in until certain point would also satisfy my needs, but it sounds much more complicated and I also can't find a way to do this.


Solution

This code is enough to disconnect an employee:
$this->context->employee->logout();

But, as you can see it's in the context, which mean the code should be executed from the employee you want to disconnect because the session is saved in the local cookie of the employee, in other words, you can't disconnect remotely to an employee, but you can use the hook displayBackOfficeHeader which is called in every browsing page and then disconnect the employee, eg:

public function hookDisplayBackOfficeHeader()
{
    // My validation to disconnect the employee I want
    if ($id_employee == 1) {
        $this->context->employee->logout();
        Tools::redirectAdmin('index.php');
    }
}


Answered By - Rolige
Answer Checked By - Robin (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing