mirror of
https://framagit.org/tykayn/date-poll-api
synced 2023-08-25 08:23:11 +02:00
⚡ mail having containers
This commit is contained in:
parent
aa06af19c3
commit
da39373a98
@ -5,13 +5,13 @@ namespace App\Controller;
|
|||||||
use App\Entity\Choice;
|
use App\Entity\Choice;
|
||||||
use App\Entity\Owner;
|
use App\Entity\Owner;
|
||||||
use App\Entity\Poll;
|
use App\Entity\Poll;
|
||||||
|
use App\Service\MailService;
|
||||||
use FOS\RestBundle\Controller\Annotations\Delete;
|
use FOS\RestBundle\Controller\Annotations\Delete;
|
||||||
use FOS\RestBundle\Controller\Annotations\Get;
|
use FOS\RestBundle\Controller\Annotations\Get;
|
||||||
use FOS\RestBundle\Controller\Annotations\Post;
|
use FOS\RestBundle\Controller\Annotations\Post;
|
||||||
use FOS\RestBundle\Controller\Annotations\Put;
|
use FOS\RestBundle\Controller\Annotations\Put;
|
||||||
use FOS\RestBundle\Controller\Annotations\Route;
|
use FOS\RestBundle\Controller\Annotations\Route;
|
||||||
use JMS\Serializer\SerializerBuilder;
|
use JMS\Serializer\SerializerBuilder;
|
||||||
use Swift_Message;
|
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
@ -138,7 +138,7 @@ class PollController extends AbstractController {
|
|||||||
*
|
*
|
||||||
* @return JsonResponse
|
* @return JsonResponse
|
||||||
*/
|
*/
|
||||||
public function newPollAction( Request $request, \Swift_Mailer $mailer ) {
|
public function newPollAction( Request $request, \Swift_Mailer $mailer, MailService $mail_service ) {
|
||||||
|
|
||||||
$data = $request->getContent();
|
$data = $request->getContent();
|
||||||
|
|
||||||
@ -226,7 +226,7 @@ class PollController extends AbstractController {
|
|||||||
$precision = 'from an existing user : ' . $foundOwner->getEmail();
|
$precision = 'from an existing user : ' . $foundOwner->getEmail();
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->sendCreationMailAction( $foundOwner, $newpoll, $mailer );
|
$mail_service->sendCreationMailAction( $foundOwner, $newpoll );
|
||||||
|
|
||||||
return $this->json( [
|
return $this->json( [
|
||||||
'message' => 'you created a poll ' . $precision,
|
'message' => 'you created a poll ' . $precision,
|
||||||
@ -242,7 +242,7 @@ class PollController extends AbstractController {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @Get(
|
* @Get(
|
||||||
* path = "/mail/test-mail-poll",
|
* path = "/mail/test-mail-poll/{emailChoice}",
|
||||||
* name = "test-mail-poll",
|
* name = "test-mail-poll",
|
||||||
* )
|
* )
|
||||||
*
|
*
|
||||||
@ -255,34 +255,29 @@ class PollController extends AbstractController {
|
|||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
// public function sendCreationMailAction( Owner $admin_user, Poll $poll, \Swift_Mailer $mailer) {
|
// public function sendCreationMailAction( Owner $admin_user, Poll $poll, \Swift_Mailer $mailer) {
|
||||||
public function sendCreationMailAction( \Swift_Mailer $mailer ) {
|
public function testSendCreationMailAction( MailService $mail_service, $emailChoice = 'creation_comment' ) {
|
||||||
|
|
||||||
$em = $this->getDoctrine()->getRepository( Owner::class );
|
$em = $this->getDoctrine()->getRepository( Owner::class );
|
||||||
$admin_user = $em->find( 1 );
|
$foundOwner = $em->find( 1 );
|
||||||
$poll = $admin_user->getPolls()[ 0 ];
|
$poll = $foundOwner->getPolls()[ 0 ];
|
||||||
|
$comment = $foundOwner->getComments()[ 0 ];
|
||||||
|
|
||||||
|
|
||||||
|
$emailChoicesTemplates = [
|
||||||
|
'creation_poll' => 'creation-mail.html.twig',
|
||||||
|
'creation_comment' => 'comment-notification.html.twig',
|
||||||
|
];
|
||||||
|
|
||||||
|
// $mail_service->sendCreationMailAction( $foundOwner, $poll );
|
||||||
$templateVars = [
|
$templateVars = [
|
||||||
'owner' => $admin_user,
|
'owner' => $foundOwner,
|
||||||
|
'comment' => $comment,
|
||||||
'poll' => $poll,
|
'poll' => $poll,
|
||||||
'url' => $poll->getCustomUrl(),
|
'url' => $poll->getCustomUrl(),
|
||||||
'title' => 'Création de sondage - ' . $poll->getTitle(),
|
'title' => 'Création de sondage - ' . $poll->getTitle(),
|
||||||
'email_template' => 'emails/creation-mail.html.twig',
|
'email_template' => 'emails/' . $emailChoicesTemplates[ $emailChoice ],
|
||||||
];
|
];
|
||||||
|
|
||||||
$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 );
|
|
||||||
return $this->render( $templateVars[ 'email_template' ], $templateVars );
|
return $this->render( $templateVars[ 'email_template' ], $templateVars );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
52
src/Service/MailService.php
Normal file
52
src/Service/MailService.php
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
<?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 );
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -1,11 +1,18 @@
|
|||||||
{#[Framadate][Réservé à l'auteur] Sondage: TESSSSSSSSSST#}
|
{#[Framadate][Réservé à l'auteur] Sondage: TESSSSSSSSSST#}
|
||||||
Ce message ne doit PAS être diffusé aux sondés. Il est réservé à l'auteur du sondage.
|
{% extends 'email-base.html.twig' %}
|
||||||
|
{% block content %}
|
||||||
|
<h1>
|
||||||
|
|
||||||
|
Ce message ne doit PAS être diffusé aux sondés. Il est réservé à l'auteur du sondage.
|
||||||
|
</h1>
|
||||||
<br>
|
<br>
|
||||||
Vous pouvez modifier ce sondage à l'adresse suivante :
|
<h2>
|
||||||
|
Vous pouvez modifier ce sondage à l'adresse suivante :
|
||||||
|
</h2>
|
||||||
<br>
|
<br>
|
||||||
{% include 'partial/admin_link.html.twig' %}
|
{% include 'emails/partial/admin_link.html.twig' %}
|
||||||
<br>
|
<br>
|
||||||
Pour partager votre sondage aux participants, utilisez son lien d'accès public.
|
Pour partager votre sondage aux participants, utilisez son lien d'accès public que vous avez reçu dans un autre email.
|
||||||
<br>
|
<br>
|
||||||
|
|
||||||
{% if poll.password %}
|
{% if poll.password %}
|
||||||
@ -14,3 +21,5 @@ Pour partager votre sondage aux participants, utilisez son lien d'accès public.
|
|||||||
{% else %}
|
{% else %}
|
||||||
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
{% endblock %}
|
||||||
|
@ -1,4 +0,0 @@
|
|||||||
{#[Framadate] Notification d'un sondage : TESSSSSSSSSST#}
|
|
||||||
{{ pseudo }} vient de rédiger un commentaire.
|
|
||||||
<br>
|
|
||||||
Vous pouvez retrouver votre sondage avec le lien suivant : {{ url }}
|
|
21
templates/emails/comment-notification.html.twig
Normal file
21
templates/emails/comment-notification.html.twig
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
{#[Framadate] Notification d'un sondage : TESSSSSSSSSST#}
|
||||||
|
{% extends 'email-base.html.twig' %}
|
||||||
|
{% block content %}
|
||||||
|
<strong>
|
||||||
|
{{ owner.pseudo }}
|
||||||
|
</strong>
|
||||||
|
vient de rédiger un commentaire.
|
||||||
|
<blockquote style="background: #dedede; padding: 1em 2em;">
|
||||||
|
<i>
|
||||||
|
|
||||||
|
{% autoescape %}
|
||||||
|
{{ comment.text }}
|
||||||
|
{% endautoescape %}
|
||||||
|
</i>
|
||||||
|
</blockquote>
|
||||||
|
<br>
|
||||||
|
Vous pouvez retrouver votre sondage avec le lien suivant :
|
||||||
|
{% include 'emails/partial/admin_link.html.twig' %}
|
||||||
|
{% include 'emails/partial/public_link.html.twig' %}
|
||||||
|
|
||||||
|
{% endblock %}
|
@ -6,5 +6,5 @@
|
|||||||
Ce sondage va bientôt expirer dans 1 jour, il ne sera plus possible d'y voter.
|
Ce sondage va bientôt expirer dans 1 jour, il ne sera plus possible d'y voter.
|
||||||
Dans 31 jours il sera supprimé. Vous pouvez exporter ses données à tout moment en vous rendant à ce lien pour l'administrer:
|
Dans 31 jours il sera supprimé. Vous pouvez exporter ses données à tout moment en vous rendant à ce lien pour l'administrer:
|
||||||
|
|
||||||
<a href="{{ url }}">{{ url }}</a>
|
{% include 'emails/partial/admin_link.html.twig' %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
@ -1,4 +1,8 @@
|
|||||||
{#[Framadate] Participation au sondage : TESSSSSSSSSST#}
|
{#[Framadate] Participation au sondage : TESSSSSSSSSST#}
|
||||||
Quelqu'un vient de modifier votre sondage accessible au lien suivant:
|
{% extends 'email-base.html.twig' %}
|
||||||
|
{% block content %}
|
||||||
|
Quelqu'un vient de modifier votre sondage accessible au lien suivant:
|
||||||
<br>
|
<br>
|
||||||
<a href="{{ url }}">{{ url }}</a>
|
{% include 'emails/partial/admin_link.html.twig' %}
|
||||||
|
|
||||||
|
{% endblock %}
|
||||||
|
@ -17,10 +17,7 @@
|
|||||||
<ul style="list-style-type: none">
|
<ul style="list-style-type: none">
|
||||||
{% for poll in polls %}
|
{% for poll in polls %}
|
||||||
<li class="poll-element" style="border: solid 1px #ccc; padding: 1em; margin-top: 1em;">
|
<li class="poll-element" style="border: solid 1px #ccc; padding: 1em; margin-top: 1em;">
|
||||||
|
|
||||||
{% include 'emails/partial/poll.html.twig' %}
|
{% include 'emails/partial/poll.html.twig' %}
|
||||||
|
|
||||||
|
|
||||||
</li>
|
</li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
|
@ -28,12 +28,12 @@
|
|||||||
<span>
|
<span>
|
||||||
lien à donner aux votants:
|
lien à donner aux votants:
|
||||||
</span>
|
</span>
|
||||||
{% include 'public_link.html.twig' %}
|
{% include 'emails/partial/public_link.html.twig' %}
|
||||||
</div>
|
</div>
|
||||||
<div class="admin">
|
<div class="admin">
|
||||||
<span>
|
<span>
|
||||||
administration:
|
administration:
|
||||||
</span>
|
</span>
|
||||||
{% include 'admin_link.html.twig' %}
|
{% include 'emails/partial/admin_link.html.twig' %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
Reference in New Issue
Block a user