在模块前端控制器ajax操作中验证员工

时间:2015-08-09 13:48:37

标签: prestashop prestashop-1.6 prestashop-1.5

在Prestashop 1.5中,我需要授予在模块前端控制器中仅对员工执行某些ajax操作的权限。

Context::getContext()->employee

仅在管理上下文中可用,因此在模块前端控制器中始终为空。

我应该如何在模块前端控制器环境中对员工进行认证?

2 个答案:

答案 0 :(得分:4)

In the previous versions of PrestaShop you could use Cookie->isLoggedBack() however this method is now deprecated (moved to Employee->isLoggedBack() which works only in the Admin Panel).

A proper way of checking if an employee is logged to the Admin Panel whether you are in a front-end or back-end controller can now be:

$cookie = new Cookie('psAdmin', '', (int)Configuration::get('PS_COOKIE_LIFETIME_BO'));
$employee = new Employee((int)$cookie->id_employee);

if (Validate::isLoadedObject($employee) && $employee->checkPassword((int)$cookie->id_employee, $cookie->passwd)
&& (!isset($cookie->remote_addr) || $cookie->remote_addr == ip2long(Tools::getRemoteAddr()) || !Configuration::get('PS_COOKIE_CHECKIP')))
        die('Logged In, Your code here');
    else
        die('User is not logged in');

答案 1 :(得分:-1)

尝试:

$context = Context::getContext();
$context->employee->id = 1;
相关问题