mirror of
https://framagit.org/tykayn/date-poll-api
synced 2023-08-25 08:23:11 +02:00
53 lines
1.2 KiB
PHP
53 lines
1.2 KiB
PHP
|
<?php
|
||
|
|
||
|
|
||
|
namespace App\Service;
|
||
|
|
||
|
|
||
|
use App\Entity\Owner;
|
||
|
|
||
|
class MailService {
|
||
|
|
||
|
|
||
|
public function sendCreationMailAction( $foundOwner, $newpoll, \Swift_Mailer $mailer ) {
|
||
|
$em = $this->getDoctrine()->getRepository( Owner::class );
|
||
|
$admin_user = $em->find( 1 );
|
||
|
$poll = $admin_user->getPolls()[ 0 ];
|
||
|
|
||
|
|
||
|
// anti spam , limit to every minute
|
||
|
$lastSend = $admin_user->getRequestedPollsDate();
|
||
|
$now = new \DateTime();
|
||
|
|
||
|
if ( date_diff( $lastSend, $now ) < 60 ) {
|
||
|
// too soon!
|
||
|
die( 'too soon!' );
|
||
|
}
|
||
|
$admin_user->setRequestedPollsDate( $now );
|
||
|
$em->persist( $admin_user );
|
||
|
$em->flush();
|
||
|
|
||
|
$templateVars = [
|
||
|
'owner' => $admin_user,
|
||
|
'poll' => $poll,
|
||
|
'url' => $poll->getCustomUrl(),
|
||
|
'title' => 'Création de sondage - ' . $poll->getTitle(),
|
||
|
'email_template' => 'emails/creation-mail.html.twig',
|
||
|
];
|
||
|
|
||
|
$message = ( new Swift_Message( 'Framadate - mes sondages' ) )
|
||
|
->setFrom( 'ne-pas-repondre@framadate-api.cipherbliss.com' )
|
||
|
->setTo( $admin_user->getEmail() )
|
||
|
->setBody(
|
||
|
$this->renderView(
|
||
|
$templateVars[ 'email_template' ],
|
||
|
$templateVars
|
||
|
)
|
||
|
);
|
||
|
|
||
|
// send email
|
||
|
return $mailer->send( $message );
|
||
|
|
||
|
}
|
||
|
}
|