Skip to content

Commit

Permalink
ENGCOM-6891: Fix for the issue #24547 Magento\Customer\Model\Account\…
Browse files Browse the repository at this point in the history
…Redirect::setRedirectCookie() not properly working #24612

 - Merge Pull Request #24612 from sashas777/magento2:issue-24547
 - Merged commits:
   1. a15f335
   2. 664056f
   3. 5188efd
   4. 3cf8f22
   5. 7597003
   6. 9413892
   7. 9f2bbc2
   8. bfa636f
   9. 6446aed
   10. 162ca60
   11. 16da706
   12. 2c24ef9
   13. a514803
   14. bfeadd7
   15. cd5ef3c
   16. dc416a9
   17. 41ce59e
   18. f021f1e
   19. 511e16a
  • Loading branch information
magento-engcom-team committed Feb 13, 2020
2 parents 293cd41 + 511e16a commit a7ba3fc
Show file tree
Hide file tree
Showing 2 changed files with 196 additions and 71 deletions.
54 changes: 43 additions & 11 deletions app/code/Magento/Customer/Model/Account/Redirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,28 @@

use Magento\Customer\Model\Session;
use Magento\Customer\Model\Url as CustomerUrl;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\App\RequestInterface;
use Magento\Framework\Controller\Result\Forward as ResultForward;
use Magento\Framework\Controller\Result\Redirect as ResultRedirect;
use Magento\Framework\Controller\ResultFactory;
use Magento\Framework\Stdlib\Cookie\CookieMetadataFactory;
use Magento\Framework\Stdlib\CookieManagerInterface;
use Magento\Framework\Url\DecoderInterface;
use Magento\Framework\Url\HostChecker;
use Magento\Framework\UrlInterface;
use Magento\Store\Model\ScopeInterface;
use Magento\Store\Model\StoreManagerInterface;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\Controller\Result\Redirect as ResultRedirect;
use Magento\Framework\Controller\Result\Forward as ResultForward;
use Magento\Framework\Url\DecoderInterface;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\Stdlib\CookieManagerInterface;

/**
* Account Redirect
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.CookieAndSessionMisuse)
*/
class Redirect
{

/** URL to redirect user on successful login or registration */
const LOGIN_REDIRECT_URL = 'login_redirect';

Expand Down Expand Up @@ -64,10 +68,15 @@ class Redirect
*/
protected $resultFactory;

/**
* @var CookieMetadataFactory
*/
protected $cookieMetadataFactory;

/**
* @var CookieManagerInterface
*/
protected $cookieManager;
private $cookieManager;

/**
* @var HostChecker
Expand All @@ -80,6 +89,7 @@ class Redirect
private $session;

/**
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
* @param RequestInterface $request
* @param Session $customerSession
* @param ScopeConfigInterface $scopeConfig
Expand All @@ -88,6 +98,7 @@ class Redirect
* @param DecoderInterface $urlDecoder
* @param CustomerUrl $customerUrl
* @param ResultFactory $resultFactory
* @param CookieMetadataFactory $cookieMetadataFactory
* @param HostChecker|null $hostChecker
*/
public function __construct(
Expand All @@ -99,6 +110,7 @@ public function __construct(
DecoderInterface $urlDecoder,
CustomerUrl $customerUrl,
ResultFactory $resultFactory,
CookieMetadataFactory $cookieMetadataFactory,
HostChecker $hostChecker = null
) {
$this->request = $request;
Expand All @@ -108,6 +120,7 @@ public function __construct(
$this->url = $url;
$this->urlDecoder = $urlDecoder;
$this->customerUrl = $customerUrl;
$this->cookieMetadataFactory = $cookieMetadataFactory;
$this->resultFactory = $resultFactory;
$this->hostChecker = $hostChecker ?: ObjectManager::getInstance()->get(HostChecker::class);
}
Expand Down Expand Up @@ -238,7 +251,8 @@ private function applyRedirect($url)
/**
* Get Cookie manager. For release backward compatibility.
*
* @deprecated 100.0.10
* @deprecated 100.0.10 This is legacy method to pass login_redirect cookie
* @see Magento/Checkout/view/frontend/web/js/sidebar.js
* @return CookieManagerInterface
*/
protected function getCookieManager()
Expand All @@ -252,7 +266,8 @@ protected function getCookieManager()
/**
* Set cookie manager. For unit tests.
*
* @deprecated 100.0.10
* @deprecated 100.0.10 This is legacy method to pass login_redirect cookie
* @see Magento/Checkout/view/frontend/web/js/sidebar.js
* @param object $value
* @return void
*/
Expand All @@ -264,6 +279,8 @@ public function setCookieManager($value)
/**
* Get redirect route from cookie for case of successful login/registration
*
* @deprecated 100.0.10 This is legacy method to pass login_redirect cookie
* @see Magento/Checkout/view/frontend/web/js/sidebar.js
* @return null|string
*/
public function getRedirectCookie()
Expand All @@ -274,21 +291,36 @@ public function getRedirectCookie()
/**
* Save redirect route to cookie for case of successful login/registration
*
* @deprecated 100.0.10 This is legacy method to pass login_redirect cookie
* @see Magento/Checkout/view/frontend/web/js/sidebar.js
* @param string $route
* @return void
*/
public function setRedirectCookie($route)
{
$this->getCookieManager()->setPublicCookie(self::LOGIN_REDIRECT_URL, $route);
$this->getCookieManager()->setPublicCookie(
self::LOGIN_REDIRECT_URL,
$route,
$this->cookieMetadataFactory->createPublicCookieMetadata()
->setHttpOnly(true)
->setDuration(3600)
->setPath($this->storeManager->getStore()->getStorePath())
);
}

/**
* Clear cookie with requested route
*
* @deprecated 100.0.10 This is legacy method to pass login_redirect cookie
* @see Magento/Checkout/view/frontend/web/js/sidebar.js
* @return void
*/
public function clearRedirectCookie()
{
$this->getCookieManager()->deleteCookie(self::LOGIN_REDIRECT_URL);
$this->getCookieManager()->deleteCookie(
self::LOGIN_REDIRECT_URL,
$this->cookieMetadataFactory->createPublicCookieMetadata()
->setPath($this->storeManager->getStore()->getStorePath())
);
}
}
Loading

0 comments on commit a7ba3fc

Please sign in to comment.