disable csrf_protection on first step new event form

This commit is contained in:
Tchama 2019-02-08 17:29:00 +01:00
parent 2ff22a73fa
commit b2b6cb6d6a

View File

@ -3,7 +3,7 @@
/*
* Chill is a software for social workers
*
* Copyright (C) 2014-2015, Champs Libres Cooperative SCRLFS,
* Copyright (C) 2014-2019, Champs Libres Cooperative SCRLFS,
* <http://www.champs-libres.coop>, <info@champs-libres.coop>
*
* This program is free software: you can redistribute it and/or modify
@ -36,7 +36,6 @@ use Symfony\Component\Security\Core\Role\Role;
use Symfony\Component\Form\Extension\Core\Type\FormType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Chill\EventBundle\Form\Type\PickCenterType;
use Chill\MainBundle\Entity\Center;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\FormFactoryInterface;
@ -62,11 +61,13 @@ class EventController extends Controller
* @var FormFactoryInterface
*/
protected $formFactoryInterface;
/**
* EventController constructor.
*
* @param EventDispatcherInterface $eventDispatcher
* @param AuthorizationHelper $authorizationHelper
* @param FormFactoryInterface $formFactoryInterface
*/
public function __construct(
EventDispatcherInterface $eventDispatcher,
@ -95,7 +96,9 @@ class EventController extends Controller
{
$role = new Role('CHILL_EVENT_CREATE');
/** @var Center $centers */
/**
* @var Center $centers
*/
$centers = $this->authorizationHelper->getReachableCenters($this->getUser(), $role);
if (count($centers) === 1)
@ -106,7 +109,9 @@ class EventController extends Controller
}
$form = $this->formFactoryInterface
->createNamedBuilder(null)
->createNamedBuilder(null, FormType::class, null, array(
'csrf_protection' => false
))
->setMethod('GET')
->setAction(
$this->generateUrl('chill_event__event_new'))
@ -114,8 +119,7 @@ class EventController extends Controller
'class' => Center::class,
'choices' => $centers,
'placeholder' => '',
'label' => 'To which centre should the event be associated ?',
'csrf_protection' => false // works ?!
'label' => 'To which centre should the event be associated ?'
))
->add('submit', SubmitType::class, array(
'label' => 'Next step'
@ -132,8 +136,7 @@ class EventController extends Controller
* Creates a form to create a Event entity.
*
* @param Event $entity The entity
*
* @return \Symfony\Component\Form\Form The form
* @return \Symfony\Component\Form\FormInterface
*/
private function createCreateForm(Event $entity)
{
@ -188,13 +191,15 @@ class EventController extends Controller
/**
* Finds and displays a Event entity.
*
* @param $event_id
* @return \Symfony\Component\HttpFoundation\Response
*/
public function showAction($event_id)
{
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository('ChillEventBundle:Event')->find($event_id);
if (!$entity) {
throw $this->createNotFoundException('Unable to find Event entity.');
}
@ -212,7 +217,8 @@ class EventController extends Controller
/**
* create a form to add a participation with a person
*
*
* @param Event $event
* @return \Symfony\Component\Form\FormInterface
*/
protected function createAddParticipationByPersonForm(Event $event)
@ -251,6 +257,8 @@ class EventController extends Controller
/**
* Displays a form to edit an existing Event entity.
*
* @param $event_id
* @return \Symfony\Component\HttpFoundation\Response
*/
public function editAction($event_id)
{
@ -271,12 +279,11 @@ class EventController extends Controller
}
/**
* Creates a form to edit a Event entity.
*
* @param Event $entity The entity
*
* @return \Symfony\Component\Form\Form The form
*/
* Creates a form to edit a Event entity.
*
* @param Event $entity
* @return \Symfony\Component\Form\FormInterface
*/
private function createEditForm(Event $entity)
{
$form = $this->createForm(EventType::class, $entity, array(
@ -292,9 +299,13 @@ class EventController extends Controller
return $form;
}
/**
* Edits an existing Event entity.
*
* @param Request $request
* @param $event_id
* @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
*/
public function updateAction(Request $request, $event_id)
{
@ -326,7 +337,9 @@ class EventController extends Controller
/**
* List events subscriptions for a person
*
* @param $person_id
* @return \Symfony\Component\HttpFoundation\Response
*/
public function listByPersonAction($person_id)
{
@ -356,7 +369,9 @@ class EventController extends Controller
->setParameter(':person_id', $person_id)
->getSingleScalarResult();
/* @var $paginatorFactory \Chill\MainBundle\Pagination\PaginatorFactory */
/**
* @var $paginatorFactory \Chill\MainBundle\Pagination\PaginatorFactory
*/
$paginatorFactory = $this->get('chill_main.paginator_factory');
$paginator = $paginatorFactory->create($total);