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 8462688 commit 247cfe6
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
53 changes: 53 additions & 0 deletions app/code/Magento/Customer/Model/Plugin/CustomerFlushFormKey.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php
/**
* Copyright © 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;
}

/**
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
* @param FlushFormKey $subject
* @param callable $proceed
* @param $args
*/
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 @@ -323,6 +323,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 247cfe6

Please sign in to comment.