13
13
use Magento \Customer \Model \Account \Redirect as AccountRedirect ;
14
14
use Magento \Framework \App \Config \ScopeConfigInterface ;
15
15
use Magento \Framework \Exception \LocalizedException ;
16
+ use Magento \Framework \Stdlib \CookieManagerInterface ;
17
+ use Magento \Framework \Stdlib \Cookie \CookieMetadataFactory ;
16
18
17
19
/**
18
20
* Login controller
@@ -58,6 +60,16 @@ class Login extends \Magento\Framework\App\Action\Action
58
60
*/
59
61
protected $ scopeConfig ;
60
62
63
+ /**
64
+ * @var CookieManagerInterface
65
+ */
66
+ private $ cookieManager ;
67
+
68
+ /**
69
+ * @var CookieMetadataFactory
70
+ */
71
+ private $ cookieMetadataFactory ;
72
+
61
73
/**
62
74
* Initialize Login controller
63
75
*
@@ -67,21 +79,27 @@ class Login extends \Magento\Framework\App\Action\Action
67
79
* @param AccountManagementInterface $customerAccountManagement
68
80
* @param \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory
69
81
* @param \Magento\Framework\Controller\Result\RawFactory $resultRawFactory
82
+ * @param CookieManagerInterface $cookieManager
83
+ * @param CookieMetadataFactory $cookieMetadataFactory
70
84
*/
71
85
public function __construct (
72
86
\Magento \Framework \App \Action \Context $ context ,
73
87
\Magento \Customer \Model \Session $ customerSession ,
74
88
\Magento \Framework \Json \Helper \Data $ helper ,
75
89
AccountManagementInterface $ customerAccountManagement ,
76
90
\Magento \Framework \Controller \Result \JsonFactory $ resultJsonFactory ,
77
- \Magento \Framework \Controller \Result \RawFactory $ resultRawFactory
91
+ \Magento \Framework \Controller \Result \RawFactory $ resultRawFactory ,
92
+ CookieManagerInterface $ cookieManager = null ,
93
+ CookieMetadataFactory $ cookieMetadataFactory = null
78
94
) {
79
95
parent ::__construct ($ context );
80
96
$ this ->customerSession = $ customerSession ;
81
97
$ this ->helper = $ helper ;
82
98
$ this ->customerAccountManagement = $ customerAccountManagement ;
83
99
$ this ->resultJsonFactory = $ resultJsonFactory ;
84
100
$ this ->resultRawFactory = $ resultRawFactory ;
101
+ $ this ->cookieManager = $ cookieManager ?: ObjectManager::getInstance ()->get (CookieManagerInterface::class);
102
+ $ this ->cookieMetadataFactory = $ cookieMetadataFactory ?: ObjectManager::getInstance ()->get (CookieMetadataFactory::class);
85
103
}
86
104
87
105
/**
@@ -169,6 +187,11 @@ public function execute()
169
187
$ this ->customerSession ->setCustomerDataAsLoggedIn ($ customer );
170
188
$ this ->customerSession ->regenerateId ();
171
189
$ redirectRoute = $ this ->getAccountRedirect ()->getRedirectCookie ();
190
+ if ($ this ->cookieManager ->getCookie ('mage-cache-sessid ' )) {
191
+ $ metadata = $ this ->cookieMetadataFactory ->createCookieMetadata ();
192
+ $ metadata ->setPath ('/ ' );
193
+ $ this ->cookieManager ->deleteCookie ('mage-cache-sessid ' , $ metadata );
194
+ }
172
195
if (!$ this ->getScopeConfig ()->getValue ('customer/startup/redirect_dashboard ' ) && $ redirectRoute ) {
173
196
$ response ['redirectUrl ' ] = $ this ->_redirect ->success ($ redirectRoute );
174
197
$ this ->getAccountRedirect ()->clearRedirectCookie ();
0 commit comments