-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKnownUserHandler.php
More file actions
80 lines (70 loc) · 3.37 KB
/
KnownUserHandler.php
File metadata and controls
80 lines (70 loc) · 3.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
namespace Queueit\KnownUser;
require_once( __DIR__ .'/IntegrationInfoProvider.php');
require_once( __DIR__ .'/../knownuserv3/Models.php');
require_once( __DIR__ .'/../knownuserv3/KnownUser.php');
class KnownUserHandler
{
public function handleRequest($customerId, $secretKey, $observer)
{
$action = $observer->getEvent()->getControllerAction();
/** @var Mage_Core_Controller_Request_Http $request */
$request = $action->getRequest();
try
{
$queueittoken = $request->getQuery('queueittoken', '');
$configProvider = new IntegrationInfoProvider();
$configText = $configProvider->getIntegrationInfo(true);
$fullUrl = $this->getFullRequestUri();
$result = \QueueIT\KnownUserV3\SDK\KnownUser::validateRequestByIntegrationConfig($fullUrl,
$queueittoken, $configText,$customerId, $secretKey);
if($result->doRedirect())
{
$response = $action->getResponse();
$response->setHeader('Expires', 'Fri, 01 Jan 1990 00:00:00 GMT');
$response->setHeader('Cache-Control', 'no-store, no-cache, must-revalidate, max-age=0');
$response->setHeader('Pragma', 'no-cache');
$response->setRedirect($result->redirectUrl)->sendResponse();
return;
}
if(!empty($queueittoken))
{
$redirectUrl = $fullUrl;
//Request can continue - we remove queueittoken form querystring parameter to avoid sharing of user specific token
if(strpos($fullUrl,"&queueittoken=")!==false)
{
$redirectUrl = str_replace("&queueittoken=".$queueittoken,"",$fullUrl);
}
else if(strpos($fullUrl,"?queueittoken=".$queueittoken."&")!==false)
{
$redirectUrl = str_replace("queueittoken=".$queueittoken."&","", $fullUrl);
}
else if(strpos($fullUrl,"?queueittoken=".$queueittoken)!==false)
{
$redirectUrl = str_replace("?queueittoken=".$queueittoken,"", $fullUrl);
}
$action->getResponse()->setRedirect( $redirectUrl)->sendResponse();
return;
}
}
catch(\Exception $e)
{
$objectManager = \Magento\Framework\App\ObjectManager::getInstance(); // Instance of object manager
$logger = $objectManager->get("Psr\Log\LoggerInterface");
$logger->debug("Queueit-knownUser: Exception while validation user request". $e);
//log the exception
}
}
private function getFullRequestUri()
{
// Get HTTP/HTTPS (the possible values for this vary from server to server)
$myUrl = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] && !in_array(strtolower($_SERVER['HTTPS']),array('off','no'))) ? 'https' : 'http';
// Get domain portion
$myUrl .= '://'.$_SERVER['HTTP_HOST'];
// Get path to script
$myUrl .= $_SERVER['REQUEST_URI'];
// Add path info, if any
if (!empty($_SERVER['PATH_INFO'])) $myUrl .= $_SERVER['PATH_INFO'];
return $myUrl;
}
}