Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RTM] Auto-clear the session form data #1550

Merged
merged 2 commits into from
Jun 11, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
42 changes: 42 additions & 0 deletions src/EventListener/ClearFormDataListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

declare(strict_types=1);

/*
* This file is part of Contao.
*
* (c) Leo Feyer
*
* @license LGPL-3.0-or-later
*/

namespace Contao\CoreBundle\EventListener;

use Symfony\Component\HttpKernel\Event\FilterResponseEvent;

class ClearFormDataListener
{
/**
* Clear the Contao form data if not a POST request.
*
* @param FilterResponseEvent $event
*/
public function onKernelResponse(FilterResponseEvent $event): void
{
if (!$event->isMasterRequest()) {
return;
}

$request = $event->getRequest();

if ($request->isMethod('POST')) {
return;
}

if (null === ($session = $request->getSession()) || !$session->isStarted()) {
return;
}

unset($_SESSION['FORM_DATA']);
}
}
6 changes: 6 additions & 0 deletions src/Resources/config/listener.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ services:
# and lower than the header replay header (defaults to 7)
- { name: kernel.event_listener, event: kernel.request, method: onKernelRequest, priority: 6 }

contao.listener.clear_form_data:
class: Contao\CoreBundle\EventListener\ClearFormDataListener
tags:
# The priority must be lower than the one of the Symfony save session listener (defaults to -1000)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the priority must be higher than...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 6847201.

- { name: kernel.event_listener, event: kernel.response, method: onKernelResponse, priority: -768 }

contao.listener.command_scheduler:
class: Contao\CoreBundle\EventListener\CommandSchedulerListener
arguments:
Expand Down