From 18d251270bfc64e996f4526d97acc6e126155a01 Mon Sep 17 00:00:00 2001 From: Tykayn Date: Tue, 8 Jun 2021 12:09:29 +0200 Subject: [PATCH] limit owner list of poll emails if it were asked less than 10 seconds ago --- src/Controller/EmailsController.php | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/Controller/EmailsController.php b/src/Controller/EmailsController.php index 4e21a70..f59c4f7 100644 --- a/src/Controller/EmailsController.php +++ b/src/Controller/EmailsController.php @@ -5,7 +5,6 @@ namespace App\Controller; use App\Entity\Owner; use App\Entity\Poll; use JMS\Serializer\Type\Exception\Exception; -use Psr\Log\LoggerInterface; use Swift_Mailer; use Swift_Message; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; @@ -59,6 +58,25 @@ class EmailsController extends AbstractController { if ( ! isset( $config[ 'poll' ] ) ) { $config[ 'poll' ] = new Poll(); } + if ( $config[ 'email_template' ] === 'owner_list' ) { + + // refuse to send all its poll list to an owner by email if it were asked less than 10 seconds ago + + $requested = $config[ 'owner' ]->getRequestedPollsDate(); //from database + + $today_time = strtotime( date( "Y-m-d" ) ); + $expire_time = strtotime( $requested ); + if ( $expire_time - $today_time < 10 ) { + throw new \HttpException( "you asked for this email less than 10 seconds ago. wait a little.", 403 ); + } + + $config[ 'owner' ]->setRequestedPollsDate( new \DateTime() ); + } + $em = $this->getDoctrine()->getManager(); + $em->persist( $config[ 'owner' ] ); + $em->flush(); + + $emailChoicesTemplates = [ 'creation_poll' => 'creation-mail.html.twig', 'edit_poll' => 'modification-notification-mail.html.twig',