From a05f966cfde0ef6f9c0b488bd5f69c68001d7389 Mon Sep 17 00:00:00 2001 From: Dmitriy Simushev Date: Thu, 29 May 2014 11:44:18 +0000 Subject: [PATCH] Add 'operatorAuthenticate' event --- .../Authentication/AuthenticationManager.php | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/mibew/libs/classes/Mibew/Authentication/AuthenticationManager.php b/src/mibew/libs/classes/Mibew/Authentication/AuthenticationManager.php index d79c0af1..31a714e2 100644 --- a/src/mibew/libs/classes/Mibew/Authentication/AuthenticationManager.php +++ b/src/mibew/libs/classes/Mibew/Authentication/AuthenticationManager.php @@ -17,6 +17,7 @@ namespace Mibew\Authentication; +use Mibew\EventDispatcher; use Mibew\Http\CookieFactory; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; @@ -34,6 +35,13 @@ class AuthenticationManager /** * Extracts operator's data from the passed in request object. * + * Triggers 'operatorAuthenticate' event if operator is not authenticated by + * the system and pass to it an associative array with following items: + * - 'operator': if a plugin has extracted operator from the request it + * should set operator's data to this field. + * - 'request': {@link Request}, incoming request. Can be used by a plugin + * to extract an operator. + * * @param Request $request A request to extract operator from. * @return array|bool Associative array with operator's data or boolean * false if there is no operator related with the request. @@ -62,6 +70,19 @@ class AuthenticationManager } } + // Provide an ability for plugins to authenticate operator + $args = array( + 'operator' => false, + 'request' => $request, + ); + $dispatcher = EventDispatcher::getInstance(); + $dispatcher->triggerEvent('operatorAuthenticate', $args); + + if (!empty($args['operator'])) { + $_SESSION[SESSION_PREFIX . 'operator'] = $args['operator']; + return $args['operator']; + } + // Operator's data cannot be extracted from the request. return false; }