-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix for the issue #24547 Magento\Customer\Model\Account\Redirect::set…
…RedirectCookie() not properly working
- Loading branch information
Showing
5 changed files
with
139 additions
and
15 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
app/code/Magento/Customer/Api/RedirectCookieManagerInterface.php
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
/** | ||
* | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Customer\Api; | ||
|
||
use Magento\Store\Api\Data\StoreInterface; | ||
|
||
/** | ||
* Customer redirect cookie manager interface | ||
* | ||
* @api | ||
*/ | ||
interface RedirectCookieManagerInterface | ||
{ | ||
/** | ||
* Get redirect route from cookie for case of successful login/registration | ||
* | ||
* @return null|string | ||
*/ | ||
public function getRedirectCookie(); | ||
|
||
/** | ||
* Save redirect route to cookie for case of successful login/registration | ||
* | ||
* @param string $route | ||
* @param StoreInterface $store | ||
* @return void | ||
*/ | ||
public function setRedirectCookie($route, StoreInterface $store); | ||
|
||
/** | ||
* Clear cookie with requested route | ||
* | ||
* @param StoreInterface $store | ||
* @return void | ||
*/ | ||
public function clearRedirectCookie(StoreInterface $store); | ||
} |
This file contains 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 characters
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
/** | ||
* | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Customer\Model; | ||
|
||
use Magento\Framework\Stdlib\Cookie\CookieMetadataFactory; | ||
use Magento\Framework\Stdlib\CookieManagerInterface; | ||
use Magento\Store\Api\Data\StoreInterface; | ||
use Magento\Customer\Api\RedirectCookieManagerInterface; | ||
|
||
class RedirectCookieManager implements RedirectCookieManagerInterface | ||
{ | ||
/** | ||
* Cookie name | ||
*/ | ||
const COOKIE_NAME = 'login_redirect'; | ||
|
||
/** | ||
* @var CookieMetadataFactory | ||
*/ | ||
protected $cookieMetadataFactory; | ||
|
||
/** | ||
* @var CookieManagerInterface | ||
*/ | ||
protected $cookieManager; | ||
|
||
/** | ||
* @param CookieMetadataFactory $cookieMetadataFactory | ||
* @param CookieManagerInterface $cookieManager | ||
*/ | ||
public function __construct( | ||
CookieMetadataFactory $cookieMetadataFactory, | ||
CookieManagerInterface $cookieManager | ||
) { | ||
$this->cookieMetadataFactory = $cookieMetadataFactory; | ||
$this->cookieManager = $cookieManager; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getRedirectCookie() | ||
{ | ||
return $this->cookieManager->getCookie(self::COOKIE_NAME, null); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function setRedirectCookie($route, StoreInterface $store) | ||
{ | ||
$cookieMetadata = $this->cookieMetadataFactory->createPublicCookieMetadata() | ||
->setHttpOnly(true) | ||
->setDuration(3600) | ||
->setPath($store->getStorePath()); | ||
$this->cookieManager->setPublicCookie(self::COOKIE_NAME, $route, $cookieMetadata); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function clearRedirectCookie(StoreInterface $store) | ||
{ | ||
$cookieMetadata = $this->cookieMetadataFactory->createPublicCookieMetadata() | ||
->setPath($store->getStorePath()); | ||
$this->cookieManager->deleteCookie(self::COOKIE_NAME, $cookieMetadata); | ||
} | ||
} |
This file contains 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 characters
This file contains 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 characters