From 3d4500b846a042108366668f63873ac06c58ba65 Mon Sep 17 00:00:00 2001 From: andibraeu Date: Sun, 14 Jun 2015 15:05:09 +0200 Subject: [PATCH] updated forms to protect them from spamming --- .../Controller/EventController.php | 27 ++++++++++--------- .../Controller/RepeatingEventController.php | 3 +++ .../views/Event/event_form.html.twig | 17 +++++++++++- .../repeating_event_form.html.twig | 17 +++++++++++- 4 files changed, 50 insertions(+), 14 deletions(-) diff --git a/src/Hackspace/Bundle/CalciferBundle/Controller/EventController.php b/src/Hackspace/Bundle/CalciferBundle/Controller/EventController.php index 79ccc0d..d477cad 100755 --- a/src/Hackspace/Bundle/CalciferBundle/Controller/EventController.php +++ b/src/Hackspace/Bundle/CalciferBundle/Controller/EventController.php @@ -156,16 +156,17 @@ class EventController extends Controller { $entity = new Event(); - $em = $this->saveEvent($request, $entity); - - - $errors = $entity->isValid(); - if ($errors === true) { - $em = $this->getDoctrine()->getManager(); - $em->persist($entity); - $em->flush(); - - return $this->redirect($this->generateUrl('_show', array('slug' => $entity->slug))); + if (! $request->get('origin')) { + $em = $this->saveEvent($request, $entity); + $errors = $entity->isValid(); + if ( $errors === true ) { + $em = $this->getDoctrine()->getManager(); + $em->persist($entity); + $em->flush(); + return $this->redirect($this->generateUrl('_show', array('slug' => $entity->slug))); + } + } else { + return $this->redirect($this->generateUrl('')); } return array( @@ -284,16 +285,18 @@ class EventController extends Controller throw $this->createNotFoundException('Unable to find Event entity.'); } - $em = $this->saveEvent($request, $entity); $errors = $entity->isValid(); - if ($errors === true) { + if ($errors === true && (! $request->get('origin'))) { + $em = $this->saveEvent($request, $entity); $em = $this->getDoctrine()->getManager(); $em->persist($entity); $em->flush(); return $this->redirect($this->generateUrl('_show', array('slug' => $entity->slug))); + } else { + return $this->redirect($this->generateUrl('')); } return array( diff --git a/src/Hackspace/Bundle/CalciferBundle/Controller/RepeatingEventController.php b/src/Hackspace/Bundle/CalciferBundle/Controller/RepeatingEventController.php index 28b1341..50ad4fb 100755 --- a/src/Hackspace/Bundle/CalciferBundle/Controller/RepeatingEventController.php +++ b/src/Hackspace/Bundle/CalciferBundle/Controller/RepeatingEventController.php @@ -178,6 +178,9 @@ class RepeatingEventController extends Controller private function saveRepeatingEvent(Request $request, RepeatingEvent $entity) { + if ( $request->get('origin')) { + return false; + } $location = $request->get('location'); $location_lat = $request->get('location_lat'); $location_lon = $request->get('location_lon'); diff --git a/src/Hackspace/Bundle/CalciferBundle/Resources/views/Event/event_form.html.twig b/src/Hackspace/Bundle/CalciferBundle/Resources/views/Event/event_form.html.twig index e584fe3..c502296 100755 --- a/src/Hackspace/Bundle/CalciferBundle/Resources/views/Event/event_form.html.twig +++ b/src/Hackspace/Bundle/CalciferBundle/Resources/views/Event/event_form.html.twig @@ -147,7 +147,22 @@ +
+ +
+ + +
+ +
+
+
- \ No newline at end of file + diff --git a/src/Hackspace/Bundle/CalciferBundle/Resources/views/RepeatingEvent/repeating_event_form.html.twig b/src/Hackspace/Bundle/CalciferBundle/Resources/views/RepeatingEvent/repeating_event_form.html.twig index f258b28..fb8e121 100755 --- a/src/Hackspace/Bundle/CalciferBundle/Resources/views/RepeatingEvent/repeating_event_form.html.twig +++ b/src/Hackspace/Bundle/CalciferBundle/Resources/views/RepeatingEvent/repeating_event_form.html.twig @@ -157,8 +157,23 @@
Du kannst hier kommasepariert Tags angeben.
+
+ +
+ + +
+ +
+
+
- \ No newline at end of file +