7
7
8
8
use Magento \Customer \Model \Session ;
9
9
use Magento \Customer \Model \Url as CustomerUrl ;
10
+ use Magento \Framework \App \Config \ScopeConfigInterface ;
11
+ use Magento \Framework \App \ObjectManager ;
10
12
use Magento \Framework \App \RequestInterface ;
13
+ use Magento \Framework \Controller \Result \Forward as ResultForward ;
14
+ use Magento \Framework \Controller \Result \Redirect as ResultRedirect ;
11
15
use Magento \Framework \Controller \ResultFactory ;
16
+ use Magento \Framework \Stdlib \Cookie \CookieMetadataFactory ;
17
+ use Magento \Framework \Stdlib \CookieManagerInterface ;
18
+ use Magento \Framework \Url \DecoderInterface ;
12
19
use Magento \Framework \Url \HostChecker ;
13
20
use Magento \Framework \UrlInterface ;
14
21
use Magento \Store \Model \ScopeInterface ;
15
22
use Magento \Store \Model \StoreManagerInterface ;
16
- use Magento \Framework \App \Config \ScopeConfigInterface ;
17
- use Magento \Framework \Controller \Result \Redirect as ResultRedirect ;
18
- use Magento \Framework \Controller \Result \Forward as ResultForward ;
19
- use Magento \Framework \Url \DecoderInterface ;
20
- use Magento \Framework \App \ObjectManager ;
21
- use Magento \Framework \Stdlib \CookieManagerInterface ;
22
23
23
24
/**
25
+ * Account Redirect
24
26
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
27
+ * @SuppressWarnings(PHPMD.CookieAndSessionMisuse)
25
28
*/
26
29
class Redirect
27
30
{
31
+
28
32
/** URL to redirect user on successful login or registration */
29
33
const LOGIN_REDIRECT_URL = 'login_redirect ' ;
30
34
@@ -64,10 +68,15 @@ class Redirect
64
68
*/
65
69
protected $ resultFactory ;
66
70
71
+ /**
72
+ * @var CookieMetadataFactory
73
+ */
74
+ protected $ cookieMetadataFactory ;
75
+
67
76
/**
68
77
* @var CookieManagerInterface
69
78
*/
70
- protected $ cookieManager ;
79
+ private $ cookieManager ;
71
80
72
81
/**
73
82
* @var HostChecker
@@ -80,6 +89,7 @@ class Redirect
80
89
private $ session ;
81
90
82
91
/**
92
+ * @SuppressWarnings(PHPMD.ExcessiveParameterList)
83
93
* @param RequestInterface $request
84
94
* @param Session $customerSession
85
95
* @param ScopeConfigInterface $scopeConfig
@@ -88,6 +98,7 @@ class Redirect
88
98
* @param DecoderInterface $urlDecoder
89
99
* @param CustomerUrl $customerUrl
90
100
* @param ResultFactory $resultFactory
101
+ * @param CookieMetadataFactory $cookieMetadataFactory
91
102
* @param HostChecker|null $hostChecker
92
103
*/
93
104
public function __construct (
@@ -99,6 +110,7 @@ public function __construct(
99
110
DecoderInterface $ urlDecoder ,
100
111
CustomerUrl $ customerUrl ,
101
112
ResultFactory $ resultFactory ,
113
+ CookieMetadataFactory $ cookieMetadataFactory ,
102
114
HostChecker $ hostChecker = null
103
115
) {
104
116
$ this ->request = $ request ;
@@ -108,6 +120,7 @@ public function __construct(
108
120
$ this ->url = $ url ;
109
121
$ this ->urlDecoder = $ urlDecoder ;
110
122
$ this ->customerUrl = $ customerUrl ;
123
+ $ this ->cookieMetadataFactory = $ cookieMetadataFactory ;
111
124
$ this ->resultFactory = $ resultFactory ;
112
125
$ this ->hostChecker = $ hostChecker ?: ObjectManager::getInstance ()->get (HostChecker::class);
113
126
}
@@ -238,7 +251,8 @@ private function applyRedirect($url)
238
251
/**
239
252
* Get Cookie manager. For release backward compatibility.
240
253
*
241
- * @deprecated 100.0.10
254
+ * @deprecated 100.0.10 This is legacy method to pass login_redirect cookie
255
+ * @see Magento/Checkout/view/frontend/web/js/sidebar.js
242
256
* @return CookieManagerInterface
243
257
*/
244
258
protected function getCookieManager ()
@@ -252,7 +266,8 @@ protected function getCookieManager()
252
266
/**
253
267
* Set cookie manager. For unit tests.
254
268
*
255
- * @deprecated 100.0.10
269
+ * @deprecated 100.0.10 This is legacy method to pass login_redirect cookie
270
+ * @see Magento/Checkout/view/frontend/web/js/sidebar.js
256
271
* @param object $value
257
272
* @return void
258
273
*/
@@ -264,6 +279,8 @@ public function setCookieManager($value)
264
279
/**
265
280
* Get redirect route from cookie for case of successful login/registration
266
281
*
282
+ * @deprecated 100.0.10 This is legacy method to pass login_redirect cookie
283
+ * @see Magento/Checkout/view/frontend/web/js/sidebar.js
267
284
* @return null|string
268
285
*/
269
286
public function getRedirectCookie ()
@@ -274,21 +291,36 @@ public function getRedirectCookie()
274
291
/**
275
292
* Save redirect route to cookie for case of successful login/registration
276
293
*
294
+ * @deprecated 100.0.10 This is legacy method to pass login_redirect cookie
295
+ * @see Magento/Checkout/view/frontend/web/js/sidebar.js
277
296
* @param string $route
278
297
* @return void
279
298
*/
280
299
public function setRedirectCookie ($ route )
281
300
{
282
- $ this ->getCookieManager ()->setPublicCookie (self ::LOGIN_REDIRECT_URL , $ route );
301
+ $ this ->getCookieManager ()->setPublicCookie (
302
+ self ::LOGIN_REDIRECT_URL ,
303
+ $ route ,
304
+ $ this ->cookieMetadataFactory ->createPublicCookieMetadata ()
305
+ ->setHttpOnly (true )
306
+ ->setDuration (3600 )
307
+ ->setPath ($ this ->storeManager ->getStore ()->getStorePath ())
308
+ );
283
309
}
284
310
285
311
/**
286
312
* Clear cookie with requested route
287
313
*
314
+ * @deprecated 100.0.10 This is legacy method to pass login_redirect cookie
315
+ * @see Magento/Checkout/view/frontend/web/js/sidebar.js
288
316
* @return void
289
317
*/
290
318
public function clearRedirectCookie ()
291
319
{
292
- $ this ->getCookieManager ()->deleteCookie (self ::LOGIN_REDIRECT_URL );
320
+ $ this ->getCookieManager ()->deleteCookie (
321
+ self ::LOGIN_REDIRECT_URL ,
322
+ $ this ->cookieMetadataFactory ->createPublicCookieMetadata ()
323
+ ->setPath ($ this ->storeManager ->getStore ()->getStorePath ())
324
+ );
293
325
}
294
326
}
0 commit comments