-
-
Save IbrahimS2/13d0276dfda99b86dd4cea8ecd602056 to your computer and use it in GitHub Desktop.
Revisions
-
Hailong revised this gist
Apr 15, 2019 . 1 changed file with 86 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,86 @@ <?php namespace Auctane\Api\Controller\Auctane; use Exception; use Magento\Framework\App\CsrfAwareActionInterface; use Magento\Framework\App\Request\InvalidRequestException; use Magento\Framework\App\RequestInterface; class Index extends \Magento\Framework\App\Action\Action implements CsrfAwareActionInterface { /** * @inheritDoc */ public function createCsrfValidationException( RequestInterface $request ): ?InvalidRequestException { return null; } /** * @inheritDoc */ public function validateForCsrf(RequestInterface $request): ?bool { return true; } /** * Default function * * @return void */ public function execute() { $authUser = $this->getRequest()->getParam('SS-UserName'); $authPassword = $this->getRequest()->getParam('SS-Password'); // \Magento\Store\Model\StoreManagerInterface $storeManager $storeManager = $this->_objectManager->get( 'Magento\Store\Model\StoreManagerInterface' ); $storeId = $storeManager->getStore()->getId(); $storageInterface = $this->_objectManager->get( '\Magento\Backend\Model\Auth\Credential\StorageInterface' ); $userAuthentication = $storageInterface->authenticate( $authUser, $authPassword ); $dataHelper = $this->_objectManager->get('Auctane\Api\Helper\Data'); if (!$userAuthentication) { header(sprintf('WWW-Authenticate: Basic realm=ShipStation')); $result = $dataHelper->fault(401, 'Authentication failed'); header('Content-Type: text/xml; charset=UTF-8'); $this->getResponse()->setBody($result); return false; } //Get the requested action $action = $this->getRequest()->getParam('action'); try { switch ($action) { case 'export': $export = $this->_objectManager->get( 'Auctane\Api\Model\Action\Export' ); $result = $export->process($this->getRequest(), $storeId); break; case 'shipnotify': $shipNotify = $this->_objectManager->get( 'Auctane\Api\Model\Action\ShipNotify' ); $result = $shipNotify->process($this->getRequest()); // if there hasn't been an error then "200 OK" is given break; } } catch (Exception $fault) { $result = $dataHelper->fault($fault->getCode(), $fault->getMessage()); } $this->getResponse()->setBody($result); } } -
Hailong created this gist
Apr 14, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,47 @@ From 15db78fd75a7fc473d72157cb952f36739b125c7 Mon Sep 17 00:00:00 2001 From: Hailong Zhao <[email protected]> Date: Sat, 13 Apr 2019 23:13:58 -0400 Subject: [PATCH] Fix ShipStation plugin. --- .../Auctane/Api/Controller/Auctane/Index.php | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/app/code/Auctane/Api/Controller/Auctane/Index.php b/app/code/Auctane/Api/Controller/Auctane/Index.php index 53f9664f..a3319f17 100644 --- a/app/code/Auctane/Api/Controller/Auctane/Index.php +++ b/app/code/Auctane/Api/Controller/Auctane/Index.php @@ -2,9 +2,29 @@ namespace Auctane\Api\Controller\Auctane; use Exception; +use Magento\Framework\App\CsrfAwareActionInterface; +use Magento\Framework\App\Request\InvalidRequestException; +use Magento\Framework\App\RequestInterface; -class Index extends \Magento\Framework\App\Action\Action +class Index extends \Magento\Framework\App\Action\Action implements CsrfAwareActionInterface { + /** + * @inheritDoc + */ + public function createCsrfValidationException( + RequestInterface $request + ): ?InvalidRequestException { + return null; + } + + /** + * @inheritDoc + */ + public function validateForCsrf(RequestInterface $request): ?bool + { + return true; + } + /** * Default function * -- 2.20.1 (Apple Git-117)