Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for the issue #24547 Magento\Customer\Model\Account\Redirect::setRedirectCookie() not properly working #24612

Merged
merged 19 commits into from
Feb 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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