mirror of
https://framagit.org/tykayn/date-poll-api
synced 2023-08-25 08:23:11 +02:00
limit owner list of poll emails if it were asked less than 10 seconds ago
This commit is contained in:
parent
28ccc52dd6
commit
18d251270b
@ -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',
|
||||
|
Loading…
Reference in New Issue
Block a user