Skip to content

Commit

Permalink
Generate new FormKey and replace for oldRequestParams
Browse files Browse the repository at this point in the history
  • Loading branch information
osrecio committed Nov 27, 2017
1 parent 9d75bca commit 5368727
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
52 changes: 52 additions & 0 deletions app/code/Magento/Customer/Model/Plugin/CustomerFlushFormKey.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php
/**
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Customer\Model\Plugin;

use Magento\Customer\Model\Session;
use Magento\Framework\Data\Form\FormKey as DataFormKey;
use Magento\PageCache\Observer\FlushFormKey;

class CustomerFlushFormKey
{
/**
* @var Session
*/
private $session;

/**
* @var DataFormKey
*/
private $dataFormKey;

/**
* Initialize dependencies.
*
* @param Session $session
* @param DataFormKey $dataFormKey
*/
public function __construct(Session $session, DataFormKey $dataFormKey)
{
$this->session = $session;
$this->dataFormKey = $dataFormKey;
}

/**
* @param FlushFormKey $subject
* @param callable $proceed
* @param array $args
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function aroundExecute(FlushFormKey $subject, callable $proceed, ...$args)
{
$currentFormKey = $this->dataFormKey->getFormKey();
$proceed(...$args);
$beforeParams = $this->session->getBeforeRequestParams();
if ($beforeParams['form_key'] == $currentFormKey) {
$beforeParams['form_key'] = $this->dataFormKey->getFormKey();
$this->session->setBeforeRequestParams($beforeParams);
}
}
}
3 changes: 3 additions & 0 deletions app/code/Magento/Customer/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,9 @@
<type name="Magento\Framework\App\Action\AbstractAction">
<plugin name="customerNotification" type="Magento\Customer\Model\Plugin\CustomerNotification"/>
</type>
<type name="Magento\PageCache\Observer\FlushFormKey">
<plugin name="customerFlushFormKey" type="Magento\Customer\Model\Plugin\CustomerFlushFormKey"/>
</type>
<type name="Magento\Customer\Model\Customer\NotificationStorage">
<arguments>
<argument name="cache" xsi:type="object">Magento\Customer\Model\Cache\Type\Notification</argument>
Expand Down

0 comments on commit 5368727

Please sign in to comment.