Skip to content

Commit 6606402

Browse files
committed
[Forwardport] magento/magento2#:13040 Customer Login/Logout Issue
1 parent fa906ed commit 6606402

File tree

2 files changed

+121
-15
lines changed

2 files changed

+121
-15
lines changed

app/code/Magento/Customer/Model/Account/Redirect.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ class Redirect
7474
*/
7575
private $hostChecker;
7676

77+
/**
78+
* @var Session
79+
*/
80+
private $session;
81+
7782
/**
7883
* @param RequestInterface $request
7984
* @param Session $customerSession
@@ -206,6 +211,10 @@ protected function processLoggedCustomer()
206211
$referer = $this->request->getParam(CustomerUrl::REFERER_QUERY_PARAM_NAME);
207212
if ($referer) {
208213
$referer = $this->urlDecoder->decode($referer);
214+
preg_match('/logoutSuccess\//', $referer, $matches, PREG_OFFSET_CAPTURE);
215+
if (!empty($matches)) {
216+
$referer = str_replace('logoutSuccess/', '', $referer);
217+
}
209218
if ($this->hostChecker->isOwnOrigin($referer)) {
210219
$this->applyRedirect($referer);
211220
}

app/code/Magento/Customer/Test/Unit/Model/Account/RedirectTest.php

Lines changed: 112 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -147,15 +147,15 @@ protected function setUp()
147147
$this->model = $objectManager->getObject(
148148
\Magento\Customer\Model\Account\Redirect::class,
149149
[
150-
'request' => $this->request,
151-
'customerSession' => $this->customerSession,
152-
'scopeConfig' => $this->scopeConfig,
153-
'storeManager' => $this->storeManager,
154-
'url' => $this->url,
155-
'urlDecoder' => $this->urlDecoder,
156-
'customerUrl' => $this->customerUrl,
157-
'resultFactory' => $this->resultFactory,
158-
'hostChecker' => $this->hostChecker
150+
'request' => $this->request,
151+
'customerSession' => $this->customerSession,
152+
'scopeConfig' => $this->scopeConfig,
153+
'storeManager' => $this->storeManager,
154+
'url' => $this->url,
155+
'urlDecoder' => $this->urlDecoder,
156+
'customerUrl' => $this->customerUrl,
157+
'resultFactory' => $this->resultFactory,
158+
'hostChecker' => $this->hostChecker,
159159
]
160160
);
161161
}
@@ -272,6 +272,10 @@ public function testGetRedirect(
272272
->with(ResultFactory::TYPE_REDIRECT)
273273
->willReturn($this->resultRedirect);
274274

275+
$this->hostChecker->expects($this->any())
276+
->method('isOwnOrigin')
277+
->willReturn(true);
278+
275279
$this->model->getRedirect();
276280
}
277281

@@ -296,16 +300,109 @@ public function getRedirectDataProvider()
296300
*/
297301
return [
298302
// Logged In, Redirect by Referer
299-
[1, 2, 'referer', 'base', '', '', 'account', '', '', '', true, false],
300-
[1, 2, 'http://referer.com/', 'http://base.com/', '', '', 'account', '', '', 'dashboard', true, false],
303+
[
304+
'customer_id' => 1,
305+
'last_customer_id' => 2,
306+
'referer' => 'referer',
307+
'base_url' => 'base',
308+
'before_auth_url' => '',
309+
'after_auth_url' => '',
310+
'account_url' => 'account',
311+
'login_url' => '',
312+
'logout_url' => '',
313+
'dashboard_url' => '',
314+
'is_customer_logged_id_flag' => true,
315+
'redirect_to_dashboard_flag' => false,
316+
],
317+
[
318+
'customer_id' => 1,
319+
'last_customer_id' => 2,
320+
'referer' => 'http://referer.com/',
321+
'base_url' => 'http://base.com/',
322+
'before_auth_url' => '',
323+
'after_auth_url' => '',
324+
'account_url' => 'account',
325+
'login_url' => '',
326+
'logout_url' => '',
327+
'dashboard_url' => 'dashboard',
328+
'is_customer_logged_id_flag' => true,
329+
'redirect_to_dashboard_flag' => false,
330+
],
301331
// Logged In, Redirect by AfterAuthUrl
302-
[1, 2, 'referer', 'base', '', 'defined', 'account', '', '', '', true, true],
332+
[
333+
'customer_id' => 1,
334+
'last_customer_id' => 2,
335+
'referer' => 'referer',
336+
'base_url' => 'base',
337+
'before_auth_url' => '',
338+
'after_auth_url' => 'defined',
339+
'account_url' => 'account',
340+
'login_url' => '',
341+
'logout_url' => '',
342+
'dashboard_url' => '',
343+
'is_customer_logged_id_flag' => true,
344+
'redirect_to_dashboard_flag' => true,
345+
],
303346
// Not logged In, Redirect by LoginUrl
304-
[1, 2, 'referer', 'base', '', '', 'account', 'login', '', '', false, true],
347+
[
348+
'customer_id' => 1,
349+
'last_customer_id' => 2,
350+
'referer' => 'referer',
351+
'base_url' => 'base',
352+
'before_auth_url' => '',
353+
'after_auth_url' => '',
354+
'account_url' => 'account',
355+
'login_url' => 'login',
356+
'logout_url' => '',
357+
'dashboard_url' => '',
358+
'is_customer_logged_id_flag' => false,
359+
'redirect_to_dashboard_flag' => true,
360+
],
305361
// Logout, Redirect to Dashboard
306-
[1, 2, 'referer', 'base', 'logout', '', 'account', 'login', 'logout', 'dashboard', false, true],
362+
[
363+
'customer_id' => 1,
364+
'last_customer_id' => 2,
365+
'referer' => 'referer',
366+
'base_url' => 'base',
367+
'before_auth_url' => 'logout',
368+
'after_auth_url' => '',
369+
'account_url' => 'account',
370+
'login_url' => 'login',
371+
'logout_url' => 'logout',
372+
'dashboard_url' => 'dashboard',
373+
'is_customer_logged_id_flag' => false,
374+
'redirect_to_dashboard_flag' => true,
375+
],
376+
// Logout, Without Redirect to Dashboard
377+
[
378+
'customer_id' => 1,
379+
'last_customer_id' => 2,
380+
'referer' => 'http://base.com/customer/account/logoutSuccess/',
381+
'base_url' => 'http://base.com/',
382+
'before_auth_url' => 'http://base.com/',
383+
'after_auth_url' => 'http://base.com/customer/account/',
384+
'account_url' => 'account',
385+
'login_url' => 'login',
386+
'logout_url' => 'logout',
387+
'dashboard_url' => 'dashboard',
388+
'is_customer_logged_id_flag' => true,
389+
'redirect_to_dashboard_flag' => false,
390+
],
307391
// Default redirect
308-
[1, 2, 'referer', 'base', 'defined', '', 'account', 'login', 'logout', 'dashboard', true, true],
392+
[
393+
'customer_id' => 1,
394+
'last_customer_id' => 2,
395+
'referer' => 'referer',
396+
'base_url' => 'base',
397+
'before_auth_url' => 'defined',
398+
'after_auth_url' => '',
399+
'account_url' => 'account',
400+
'login_url' => 'login',
401+
'logout_url' => 'logout',
402+
'dashboard_url' => 'dashboard',
403+
'is_customer_logged_id_flag' => true,
404+
'redirect_to_dashboard_flag' => true,
405+
],
309406
];
310407
}
311408

0 commit comments

Comments
 (0)