Skip to content

Commit 5368727

Browse files
committed
Generate new FormKey and replace for oldRequestParams
1 parent 9d75bca commit 5368727

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Customer\Model\Plugin;
7+
8+
use Magento\Customer\Model\Session;
9+
use Magento\Framework\Data\Form\FormKey as DataFormKey;
10+
use Magento\PageCache\Observer\FlushFormKey;
11+
12+
class CustomerFlushFormKey
13+
{
14+
/**
15+
* @var Session
16+
*/
17+
private $session;
18+
19+
/**
20+
* @var DataFormKey
21+
*/
22+
private $dataFormKey;
23+
24+
/**
25+
* Initialize dependencies.
26+
*
27+
* @param Session $session
28+
* @param DataFormKey $dataFormKey
29+
*/
30+
public function __construct(Session $session, DataFormKey $dataFormKey)
31+
{
32+
$this->session = $session;
33+
$this->dataFormKey = $dataFormKey;
34+
}
35+
36+
/**
37+
* @param FlushFormKey $subject
38+
* @param callable $proceed
39+
* @param array $args
40+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
41+
*/
42+
public function aroundExecute(FlushFormKey $subject, callable $proceed, ...$args)
43+
{
44+
$currentFormKey = $this->dataFormKey->getFormKey();
45+
$proceed(...$args);
46+
$beforeParams = $this->session->getBeforeRequestParams();
47+
if ($beforeParams['form_key'] == $currentFormKey) {
48+
$beforeParams['form_key'] = $this->dataFormKey->getFormKey();
49+
$this->session->setBeforeRequestParams($beforeParams);
50+
}
51+
}
52+
}

app/code/Magento/Customer/etc/di.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,9 @@
313313
<type name="Magento\Framework\App\Action\AbstractAction">
314314
<plugin name="customerNotification" type="Magento\Customer\Model\Plugin\CustomerNotification"/>
315315
</type>
316+
<type name="Magento\PageCache\Observer\FlushFormKey">
317+
<plugin name="customerFlushFormKey" type="Magento\Customer\Model\Plugin\CustomerFlushFormKey"/>
318+
</type>
316319
<type name="Magento\Customer\Model\Customer\NotificationStorage">
317320
<arguments>
318321
<argument name="cache" xsi:type="object">Magento\Customer\Model\Cache\Type\Notification</argument>

0 commit comments

Comments
 (0)