Skip to content

Commit

Permalink
IntegrationInfoController can now be called when all routes are prote…
Browse files Browse the repository at this point in the history
…cted.
  • Loading branch information
sp0x committed Jan 5, 2021
1 parent dc8df89 commit fe54671
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 38 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.idea
ignored
13 changes: 8 additions & 5 deletions src/app/code/community/Queueit/Knownuser/Helper/Data.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

class Queueit_Knownuser_Helper_Data extends Mage_Core_Helper_Abstract
{
/** Cache Tag */
Expand Down Expand Up @@ -102,13 +103,15 @@ public function getIntegrationinfo($useCache = true)

public function updateIntegrationInfo($integrationInfo, $hash)
{
if ($integrationInfo && $hash && $this->validateHash($integrationInfo, $hash)) {
Mage::getModel('queueit_knownuser/integrationinfo')
->setInfo($integrationInfo)
->save();
$this->cleanQueueitCache();
$hashIsValid = $integrationInfo && $hash && $this->validateHash($integrationInfo, $hash);
if (!$hashIsValid) {
return;
}

Mage::getModel('queueit_knownuser/integrationinfo')
->setInfo($integrationInfo)
->save();
$this->cleanQueueitCache();
}

/**
Expand Down
68 changes: 40 additions & 28 deletions src/app/code/community/Queueit/Knownuser/Model/Observer.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

class Queueit_Knownuser_Model_Observer
{
const MAGENTO_SDK_VERSION = "1.3.2";
const MAGENTO_SDK_VERSION = "1.3.3";
/**
* Temporary storage of the cookie value, easier for validation.
*
Expand All @@ -21,17 +21,38 @@ public function controllerActionPredispatch($observer)
if (!$helper->getIsEnabled() || !$helper->getCustomerId() || !$helper->getSecretKey()) {
return;
}
if ($this->isActionFromIntegrationInfoController($observer)) {
return;
}

$action = $observer->getEvent()->getControllerAction();
/** @var Mage_Core_Controller_Request_Http $request */
$request = $action->getRequest();
$this->handleRequest($request, $action);

}

private function getPluginVersion()
/**
* @param Varien_Event_Observer $observer
* @return bool
*/
private function isActionFromIntegrationInfoController($observer)
{
/** @var Varien_Event $event */
$event = $observer->getEvent();
if ($event == null) {
return false;
}
$action = $event->getControllerAction();
if ($action == null) {
return false;
}

return $action instanceof Queueit_Knownuser_IntegrationinfoController;
}

private function getPluginVersion()
{
return '&kupver=magento1_'.Queueit_Knownuser_Model_Observer::MAGENTO_SDK_VERSION;
return '&kupver=magento1_' . Queueit_Knownuser_Model_Observer::MAGENTO_SDK_VERSION;
}

/**
Expand All @@ -46,7 +67,7 @@ public function handleRequest(Mage_Core_Controller_Request_Http $request, Mage_C

try {
$fullUrl = $this->getCurrentUrl();
$currentUrlWithoutQueueitToken = preg_replace ( "/([\\?&])(" ."queueittoken". "=[^&]*)/i" , "" , $fullUrl);
$currentUrlWithoutQueueitToken = preg_replace("/([\\?&])(" . "queueittoken" . "=[^&]*)/i", "", $fullUrl);

$result = \QueueIT\KnownUserV3\SDK\KnownUser::validateRequestByIntegrationConfig(
$currentUrlWithoutQueueitToken,
Expand All @@ -57,23 +78,20 @@ public function handleRequest(Mage_Core_Controller_Request_Http $request, Mage_C
);

if ($result->doRedirect()) {
$response = $action->getResponse();
if(!$result->isAjaxResult)
{
$response->setRedirect($result->redirectUrl. $this->getPluginVersion());
}
else
{
$response->setHeader('HTTP/1.0', 200, true);
$response->setHeader($result->getAjaxQueueRedirectHeaderKey() , $result->getAjaxRedirectUrl(). urlencode($this->getPluginVersion()));
}

$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');
$action->setFlag('', $action::FLAG_NO_DISPATCH, true);
$request->setDispatched(true);
return;
$response = $action->getResponse();
if (!$result->isAjaxResult) {
$response->setRedirect($result->redirectUrl . $this->getPluginVersion());
} else {
$response->setHeader('HTTP/1.0', 200, true);
$response->setHeader($result->getAjaxQueueRedirectHeaderKey(), $result->getAjaxRedirectUrl() . urlencode($this->getPluginVersion()));
}

$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');
$action->setFlag('', $action::FLAG_NO_DISPATCH, true);
$request->setDispatched(true);
return;
}


Expand All @@ -88,15 +106,12 @@ public function handleRequest(Mage_Core_Controller_Request_Http $request, Mage_C
}



} catch (Exception $e) {
Mage::logException($e);
}
}




/**
* Pull mechanism until backend for push mechanism is finished
*
Expand Down Expand Up @@ -128,7 +143,6 @@ public function updateConfig($observer)
}



/**
* @return Queueit_Knownuser_Helper_Data
*/
Expand All @@ -138,8 +152,6 @@ protected function getHelper()
}




/**
* Strange method for getting the url, but makes sure it doesn't conflict with the other checks
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function updateAction()

if ($integrationInfo && $hash && $this->getHelper()->validateHash($integrationInfo, $hash)) {
$helper = Mage::helper('queueit_knownuser');
$configText = $helper->updateIntegrationInfo($integrationInfo, $hash);
$helper->updateIntegrationInfo($integrationInfo, $hash);
$this->getResponse()->setHeader('HTTP/1.0', 200, true);

return;
Expand All @@ -30,4 +30,4 @@ protected function getHelper()
{
return Mage::helper('queueit_knownuser');
}
}
}
6 changes: 3 additions & 3 deletions src/app/code/community/Queueit/Knownuser/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<config>
<modules>
<Queueit_Knownuser>
<version>1.3.1</version>
<version>1.3.3</version>
</Queueit_Knownuser>
</modules>
<global>
Expand Down Expand Up @@ -119,7 +119,7 @@
</adminhtml>
</routers>
</admin>



</config>

</config>

0 comments on commit fe54671

Please sign in to comment.