9
9
use Magento \Customer \Model \Url as CustomerUrl ;
10
10
use Magento \Framework \App \RequestInterface ;
11
11
use Magento \Framework \Controller \ResultFactory ;
12
+ use Magento \Framework \Stdlib \Cookie \CookieMetadataFactory ;
12
13
use Magento \Framework \Url \HostChecker ;
13
14
use Magento \Framework \UrlInterface ;
14
15
use Magento \Store \Model \ScopeInterface ;
@@ -69,6 +70,11 @@ class Redirect
69
70
*/
70
71
protected $ cookieManager ;
71
72
73
+ /**
74
+ * @var CookieMetadataFactory
75
+ */
76
+ protected $ cookieMetadataFactory ;
77
+
72
78
/**
73
79
* @var HostChecker
74
80
*/
@@ -88,6 +94,7 @@ class Redirect
88
94
* @param DecoderInterface $urlDecoder
89
95
* @param CustomerUrl $customerUrl
90
96
* @param ResultFactory $resultFactory
97
+ * @param CookieMetadataFactory $cookieMetadataFactory
91
98
* @param HostChecker|null $hostChecker
92
99
*/
93
100
public function __construct (
@@ -99,6 +106,7 @@ public function __construct(
99
106
DecoderInterface $ urlDecoder ,
100
107
CustomerUrl $ customerUrl ,
101
108
ResultFactory $ resultFactory ,
109
+ CookieMetadataFactory $ cookieMetadataFactory ,
102
110
HostChecker $ hostChecker = null
103
111
) {
104
112
$ this ->request = $ request ;
@@ -109,6 +117,7 @@ public function __construct(
109
117
$ this ->urlDecoder = $ urlDecoder ;
110
118
$ this ->customerUrl = $ customerUrl ;
111
119
$ this ->resultFactory = $ resultFactory ;
120
+ $ this ->cookieMetadataFactory = $ cookieMetadataFactory ;
112
121
$ this ->hostChecker = $ hostChecker ?: ObjectManager::getInstance ()->get (HostChecker::class);
113
122
}
114
123
@@ -279,7 +288,11 @@ public function getRedirectCookie()
279
288
*/
280
289
public function setRedirectCookie ($ route )
281
290
{
282
- $ this ->getCookieManager ()->setPublicCookie (self ::LOGIN_REDIRECT_URL , $ route );
291
+ $ cookieMetadata = $ this ->cookieMetadataFactory ->createPublicCookieMetadata ()
292
+ ->setHttpOnly (true )
293
+ ->setDuration (3600 )
294
+ ->setPath ($ this ->storeManager ->getStore ()->getStorePath ());
295
+ $ this ->getCookieManager ()->setPublicCookie (self ::LOGIN_REDIRECT_URL , $ route , $ cookieMetadata );
283
296
}
284
297
285
298
/**
@@ -289,6 +302,8 @@ public function setRedirectCookie($route)
289
302
*/
290
303
public function clearRedirectCookie ()
291
304
{
292
- $ this ->getCookieManager ()->deleteCookie (self ::LOGIN_REDIRECT_URL );
305
+ $ cookieMetadata = $ this ->cookieMetadataFactory ->createPublicCookieMetadata ()
306
+ ->setPath ($ this ->storeManager ->getStore ()->getStorePath ());
307
+ $ this ->getCookieManager ()->deleteCookie (self ::LOGIN_REDIRECT_URL , $ cookieMetadata );
293
308
}
294
309
}
0 commit comments