-
Notifications
You must be signed in to change notification settings - Fork 0
/
KnownUserHandler.php
70 lines (63 loc) · 2.9 KB
/
KnownUserHandler.php
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
<?php
namespace Queueit\KnownUser;
error_reporting(E_ALL);
require_once( __DIR__ .'\IntegrationInfoProvider.php');
require_once( __DIR__ .'\lib\knownuser\Models.php');
require_once( __DIR__ .'\lib\knownuser\KnownUser.php');
class KnownUserHandler
{
public function handleRequest($customerId, $secretKey)
{
try
{
$queueittoken = isset( $_GET["queueittoken"] )? $_GET["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())
{
//Send the user to the queue - either becuase hash was missing or becuase is was invalid
header('Location: '.$result->redirectUrl);
die();
}
if(!empty($queueittoken))
{
//Request can continue - we remove queueittoken form querystring parameter to avoid sharing of user specific token
if(strpos($fullUrl,"&queueittoken=")!==false)
{
header('Location: '.str_replace("&queueittoken=".$queueittoken,"",$fullUrl));
}
else if(strpos($fullUrl,"?queueittoken=".$queueittoken."&")!==false)
{
header('Location: '.str_replace("queueittoken=".$queueittoken,"", $fullUrl));
}
else if(strpos($fullUrl,"?queueittoken=".$queueittoken)!==false)
{
header('Location: '.str_replace("?queueittoken=".$queueittoken,"", $fullUrl));
}
die();
}
}
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;
}
}