mirror of
https://framagit.org/tykayn/date-poll-api
synced 2023-08-25 08:23:11 +02:00
try to send example template html
This commit is contained in:
parent
8f8eda6109
commit
bdd0325c82
@ -5,12 +5,12 @@ namespace App\Controller;
|
|||||||
use App\Entity\Comment;
|
use App\Entity\Comment;
|
||||||
use App\Entity\Owner;
|
use App\Entity\Owner;
|
||||||
use App\Entity\Poll;
|
use App\Entity\Poll;
|
||||||
|
use DateTime;
|
||||||
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\Route;
|
use FOS\RestBundle\Controller\Annotations\Route;
|
||||||
use JMS\Serializer\SerializerBuilder;
|
use JMS\Serializer\SerializerBuilder;
|
||||||
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;
|
||||||
|
|
||||||
@ -19,8 +19,7 @@ use Symfony\Component\HttpFoundation\Request;
|
|||||||
* @package App\Controller
|
* @package App\Controller
|
||||||
* @Route("/api/v1",name="api_")
|
* @Route("/api/v1",name="api_")
|
||||||
*/
|
*/
|
||||||
class CommentController extends AbstractController {
|
class CommentController extends FramadateController {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Get(
|
* @Get(
|
||||||
@ -71,7 +70,7 @@ class CommentController extends AbstractController {
|
|||||||
$foundOwner = new Owner();
|
$foundOwner = new Owner();
|
||||||
$foundOwner->setPseudo( $data[ 'owner' ][ 'email' ] )
|
$foundOwner->setPseudo( $data[ 'owner' ][ 'email' ] )
|
||||||
->setEmail( $data[ 'owner' ][ 'email' ] )
|
->setEmail( $data[ 'owner' ][ 'email' ] )
|
||||||
->setModifierToken( uniqid() );
|
->setModifierToken( uniqid( '', true ) );
|
||||||
}
|
}
|
||||||
// anti flood
|
// anti flood
|
||||||
$seconds_limit_lastpost = 5;
|
$seconds_limit_lastpost = 5;
|
||||||
@ -84,7 +83,7 @@ class CommentController extends AbstractController {
|
|||||||
|
|
||||||
|
|
||||||
// check time of last comment
|
// check time of last comment
|
||||||
$now = new \DateTime();
|
$now = new DateTime();
|
||||||
$now = $now->format( 'Y-m-d H:i:s' );
|
$now = $now->format( 'Y-m-d H:i:s' );
|
||||||
$date_first = strtotime( $lastCommentOfOwner[ 0 ]->getCreatedAt()->format( 'Y-m-d H:i:s' ) );
|
$date_first = strtotime( $lastCommentOfOwner[ 0 ]->getCreatedAt()->format( 'Y-m-d H:i:s' ) );
|
||||||
$date_second = strtotime( $now );
|
$date_second = strtotime( $now );
|
||||||
@ -107,7 +106,7 @@ class CommentController extends AbstractController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
$comment->setOwner( $foundOwner )
|
$comment->setOwner( $foundOwner )
|
||||||
->setCreatedAt( new \DateTime() )
|
->setCreatedAt( new DateTime() )
|
||||||
->setPoll( $poll );
|
->setPoll( $poll );
|
||||||
$foundOwner->addComment( $comment );
|
$foundOwner->addComment( $comment );
|
||||||
|
|
||||||
@ -116,6 +115,8 @@ class CommentController extends AbstractController {
|
|||||||
$em->persist( $comment );
|
$em->persist( $comment );
|
||||||
$em->flush();
|
$em->flush();
|
||||||
|
|
||||||
|
$this->mail_service->sendCommentNotification($comment);
|
||||||
|
|
||||||
return $this->json( [
|
return $this->json( [
|
||||||
'message' => 'you created a comment',
|
'message' => 'you created a comment',
|
||||||
'data' => [
|
'data' => [
|
||||||
|
@ -6,7 +6,7 @@ use App\Entity\Owner;
|
|||||||
use App\Service\MailService;
|
use App\Service\MailService;
|
||||||
use FOS\RestBundle\Controller\Annotations\Get;
|
use FOS\RestBundle\Controller\Annotations\Get;
|
||||||
use FOS\RestBundle\Controller\Annotations\Route;
|
use FOS\RestBundle\Controller\Annotations\Route;
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
use Swift_Mailer;
|
||||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -14,15 +14,12 @@ use Symfony\Component\HttpFoundation\JsonResponse;
|
|||||||
* @package App\Controller
|
* @package App\Controller
|
||||||
* @Route("/api/v1",name="api_")
|
* @Route("/api/v1",name="api_")
|
||||||
*/
|
*/
|
||||||
class DefaultController extends AbstractController {
|
class DefaultController extends FramadateController {
|
||||||
/**
|
/**
|
||||||
* @var MailService
|
* @var MailService
|
||||||
*/
|
*/
|
||||||
private $mail_service;
|
protected $mail_service;
|
||||||
|
|
||||||
public function __construct( MailService $mail_service ) {
|
|
||||||
$this->mail_service = $mail_service;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send a mail with all the data to one user
|
* Send a mail with all the data to one user
|
||||||
@ -32,11 +29,11 @@ class DefaultController extends AbstractController {
|
|||||||
* )
|
* )
|
||||||
*
|
*
|
||||||
* @param $email
|
* @param $email
|
||||||
* @param \Swift_Mailer $mailer
|
* @param Swift_Mailer $mailer
|
||||||
*
|
*
|
||||||
* @return JsonResponse
|
* @return JsonResponse
|
||||||
*/
|
*/
|
||||||
public function sendPollsToUser( $email, \Swift_Mailer $mailer ) {
|
public function sendPollsToUser( $email, Swift_Mailer $mailer ) {
|
||||||
$repository = $this->getDoctrine()->getRepository( Owner::class );
|
$repository = $this->getDoctrine()->getRepository( Owner::class );
|
||||||
|
|
||||||
// find user by email
|
// find user by email
|
||||||
|
12
src/Controller/FramadateController.php
Normal file
12
src/Controller/FramadateController.php
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controller;
|
||||||
|
|
||||||
|
use App\Service\MailService;
|
||||||
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
|
|
||||||
|
class FramadateController extends AbstractController {
|
||||||
|
public function __construct( MailService $mail_service ) {
|
||||||
|
$this->mail_service = $mail_service;
|
||||||
|
}
|
||||||
|
}
|
@ -4,14 +4,13 @@ namespace App\Controller;
|
|||||||
|
|
||||||
use FOS\RestBundle\Controller\Annotations\Get;
|
use FOS\RestBundle\Controller\Annotations\Get;
|
||||||
use FOS\RestBundle\Controller\Annotations\Route;
|
use FOS\RestBundle\Controller\Annotations\Route;
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class DefaultController
|
* Class DefaultController
|
||||||
* @package App\Controller
|
* @package App\Controller
|
||||||
* @Route("/",name="homepage")
|
* @Route("/",name="homepage")
|
||||||
*/
|
*/
|
||||||
class IndexController extends AbstractController {
|
class IndexController extends FramadateController {
|
||||||
/**
|
/**
|
||||||
* @Get(path ="/",
|
* @Get(path ="/",
|
||||||
* name = "get_default")
|
* name = "get_default")
|
||||||
|
@ -12,7 +12,7 @@ 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 Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
use Swift_Mailer;
|
||||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
|
||||||
@ -21,7 +21,8 @@ use Symfony\Component\HttpFoundation\Request;
|
|||||||
* @package App\Controller
|
* @package App\Controller
|
||||||
* @Route("/api/v1/poll",name="api_")
|
* @Route("/api/v1/poll",name="api_")
|
||||||
*/
|
*/
|
||||||
class PollController extends AbstractController {
|
class PollController extends FramadateController {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Get(
|
* @Get(
|
||||||
@ -138,7 +139,7 @@ class PollController extends AbstractController {
|
|||||||
*
|
*
|
||||||
* @return JsonResponse
|
* @return JsonResponse
|
||||||
*/
|
*/
|
||||||
public function newPollAction( Request $request, \Swift_Mailer $mailer, MailService $mail_service ) {
|
public function newPollAction( Request $request, Swift_Mailer $mailer, MailService $mail_service ) {
|
||||||
|
|
||||||
$data = $request->getContent();
|
$data = $request->getContent();
|
||||||
|
|
||||||
@ -250,24 +251,29 @@ class PollController extends AbstractController {
|
|||||||
*
|
*
|
||||||
* @param Owner $admin_user
|
* @param Owner $admin_user
|
||||||
* @param Poll $poll
|
* @param Poll $poll
|
||||||
* @param \Swift_Mailer $mailer
|
* @param Swift_Mailer $mailer
|
||||||
*
|
*
|
||||||
* @return int
|
* @return int
|
||||||
|
* not that the email tktest_commentateur@tktest.com does not really exist
|
||||||
*/
|
*/
|
||||||
// public function sendCreationMailAction( Owner $admin_user, Poll $poll, \Swift_Mailer $mailer) {
|
// public function sendCreationMailAction( Owner $admin_user, Poll $poll, \Swift_Mailer $mailer) {
|
||||||
public function testSendCreationMailAction( MailService $mail_service, $emailChoice = 'creation_vote' ) {
|
public function testSendCreationMailAction(
|
||||||
|
MailService $mail_service,
|
||||||
|
$emailChoice = 'tktest_commentateur@tktest.com'
|
||||||
|
) {
|
||||||
$em = $this->getDoctrine()->getRepository( Owner::class );
|
$em = $this->getDoctrine()->getRepository( Owner::class );
|
||||||
$foundOwner = $em->findOneByEmail( $emailChoice );
|
$foundOwner = $em->findOneByEmail( $emailChoice );
|
||||||
if($foundOwner){
|
if ( $foundOwner ) {
|
||||||
$poll = $foundOwner->getPolls()[ 0 ];
|
$poll = $foundOwner->getPolls()[ 0 ];
|
||||||
$comment = $foundOwner->getComments()[ 0 ];
|
$comment = $foundOwner->getComments()[ 0 ];
|
||||||
|
|
||||||
$sent = $mail_service->sendCreationMailAction( $foundOwner, $poll );
|
$sent = $mail_service->sendCreationMailAction( $foundOwner, $poll );
|
||||||
if($sent){
|
if ( $sent ) {
|
||||||
return $this->json(["message"=>"test email sent!"],200);
|
return $this->json( [ "message" => "test email sent!" ], 200 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $this->json(["message"=>"user with this email was not found"],400);
|
|
||||||
|
return $this->json( [ "message" => "user with this email was not found" ], 400 );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -332,6 +338,7 @@ class PollController extends AbstractController {
|
|||||||
|
|
||||||
$em->flush();
|
$em->flush();
|
||||||
|
|
||||||
|
|
||||||
return $this->json( [
|
return $this->json( [
|
||||||
'message' => 'clean routine has been done, here are the numbers of polls deleted: ' . count( $foundPolls ),
|
'message' => 'clean routine has been done, here are the numbers of polls deleted: ' . count( $foundPolls ),
|
||||||
'data' => [
|
'data' => [
|
||||||
|
@ -11,7 +11,6 @@ use FOS\RestBundle\Controller\Annotations\Delete;
|
|||||||
use FOS\RestBundle\Controller\Annotations\Patch;
|
use FOS\RestBundle\Controller\Annotations\Patch;
|
||||||
use FOS\RestBundle\Controller\Annotations\Post;
|
use FOS\RestBundle\Controller\Annotations\Post;
|
||||||
use FOS\RestBundle\Controller\Annotations\Route;
|
use FOS\RestBundle\Controller\Annotations\Route;
|
||||||
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;
|
||||||
|
|
||||||
@ -20,7 +19,7 @@ use Symfony\Component\HttpFoundation\Request;
|
|||||||
* @package App\Controller
|
* @package App\Controller
|
||||||
* @Route("/api/v1",name="api_")
|
* @Route("/api/v1",name="api_")
|
||||||
*/
|
*/
|
||||||
class VoteController extends AbstractController {
|
class VoteController extends FramadateController {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* add a vote stack on a poll
|
* add a vote stack on a poll
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
namespace App\Service;
|
namespace App\Service;
|
||||||
|
|
||||||
|
|
||||||
|
use App\Entity\Comment;
|
||||||
use App\Entity\Owner;
|
use App\Entity\Owner;
|
||||||
use App\Entity\Poll;
|
use App\Entity\Poll;
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
@ -13,6 +14,7 @@ use Symfony\Bridge\Twig\Mime\TemplatedEmail;
|
|||||||
use Symfony\Component\Mailer\Mailer;
|
use Symfony\Component\Mailer\Mailer;
|
||||||
use Symfony\Component\Mailer\Transport\Smtp\EsmtpTransport;
|
use Symfony\Component\Mailer\Transport\Smtp\EsmtpTransport;
|
||||||
use Symfony\Component\Mime\Address;
|
use Symfony\Component\Mime\Address;
|
||||||
|
use Symfony\Component\Mime\Email;
|
||||||
|
|
||||||
class MailService {
|
class MailService {
|
||||||
|
|
||||||
@ -89,6 +91,19 @@ class MailService {
|
|||||||
'title' => 'Framadate | Mes sondages',
|
'title' => 'Framadate | Mes sondages',
|
||||||
'email_template' => 'emails/owner-list.html.twig',
|
'email_template' => 'emails/owner-list.html.twig',
|
||||||
];
|
];
|
||||||
|
$this->sendMailWithVars( $config );
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function sendCommentNotification( Comment $comment ) {
|
||||||
|
|
||||||
|
$config = [
|
||||||
|
'comment' => $comment,
|
||||||
|
'owner' => $comment->getOwner(),
|
||||||
|
'title' => 'Framadate | commentaire de '.$comment->getOwner()->getPseudo(). ' _ sondage '. $comment->getPoll()->getTitle(),
|
||||||
|
'email_template' => 'emails/comment-notification.html.twig',
|
||||||
|
];
|
||||||
|
|
||||||
return $this->sendMailWithVars( $config );
|
return $this->sendMailWithVars( $config );
|
||||||
}
|
}
|
||||||
@ -124,13 +139,27 @@ class MailService {
|
|||||||
'creation_vote' => 'Framadate | Vote de "' . $config['owner']->getPseudo() . '" - sondage ' . $config['poll']->getTitle(),
|
'creation_vote' => 'Framadate | Vote de "' . $config['owner']->getPseudo() . '" - sondage ' . $config['poll']->getTitle(),
|
||||||
];
|
];
|
||||||
|
|
||||||
$email = ( new TemplatedEmail() )
|
// $email = ( new Email() )
|
||||||
->from( new Address( $config[ 'from' ] ) )
|
// ->from( new Address( $config[ 'from' ] ) )
|
||||||
// ->setHeaders( [new Header('charset', 'UTF-8' )])
|
//// ->setHeaders( [new Header('charset', 'UTF-8' )])
|
||||||
->subject( $config[ 'title' ] )
|
// ->subject( $config[ 'title' ] )
|
||||||
->to( $config[ 'owner' ]->getEmail() )
|
// ->to( $config[ 'owner' ]->getEmail() )
|
||||||
->htmlTemplate( $config[ 'email_template' ] )
|
// ->htmlTemplate( $config[ 'email_template' ] )
|
||||||
->context( $config );
|
// ->context( $config );
|
||||||
|
$email = (new TemplatedEmail())
|
||||||
|
->from('fabien@example.com')
|
||||||
|
->to(new Address('ryan@example.com'))
|
||||||
|
->subject('Thanks for signing up!')
|
||||||
|
|
||||||
|
// path of the Twig template to render
|
||||||
|
->htmlTemplate('emails/footer.html.twig')
|
||||||
|
|
||||||
|
// pass variables (name => value) to the template
|
||||||
|
->context([
|
||||||
|
'expiration_date' => new \DateTime('+7 days'),
|
||||||
|
'username' => 'foo',
|
||||||
|
])
|
||||||
|
;
|
||||||
|
|
||||||
// send email
|
// send email
|
||||||
return $this->
|
return $this->
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
{#[Framadate][Réservé à l'auteur] Sondage: TESSSSSSSSSST#}
|
{#[Framadate][Réservé à l'auteur] Sondage: TESSSSSSSSSST#}
|
||||||
{% extends 'email-base.html.twig' %}
|
{% extends 'email-base-plaintext.html.twig' %}
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<h1>
|
<h1>
|
||||||
|
|
||||||
|
@ -1,6 +0,0 @@
|
|||||||
{#[Framadate] Notification d'un sondage : TESSSSSSSSSST#}
|
|
||||||
smoi vient de rédiger un commentaire.
|
|
||||||
Vous pouvez retrouver votre sondage avec le lien suivant : https://framadate.org/NGutN7jB9vtoGOEjCfUJWBwr/admin
|
|
||||||
|
|
||||||
Merci de votre confiance.
|
|
||||||
Framadate
|
|
@ -1,5 +1,5 @@
|
|||||||
{#[Framadate] Notification d'un sondage : TESSSSSSSSSST#}
|
{#[Framadate] Notification d'un sondage : TESSSSSSSSSST#}
|
||||||
{% extends 'email-base.html.twig' %}
|
{% extends 'email-base-plaintext.html.twig' %}
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<strong>
|
<strong>
|
||||||
{{ owner.pseudo }}
|
{{ owner.pseudo }}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
{#[Framadate][Pour diffusion aux sondés] Sondage: TESSSSSSSSSST#}
|
{#[Framadate][Pour diffusion aux sondés] Sondage: TESSSSSSSSSST#}
|
||||||
{% extends 'email-base.html.twig' %}
|
{% extends 'email-base-plaintext.html.twig' %}
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
{#[Framadate][expiration] Sondage: TESSSSSSSSSST#}
|
{#[Framadate][expiration] Sondage: TESSSSSSSSSST#}
|
||||||
{% extends 'email-base.html.twig' %}
|
{% extends 'email-base-plaintext.html.twig' %}
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
{#[Framadate] Participation au sondage : TESSSSSSSSSST#}
|
{#[Framadate] Participation au sondage : TESSSSSSSSSST#}
|
||||||
{% extends 'email-base.html.twig' %}
|
{% extends 'email-base-plaintext.html.twig' %}
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<strong>
|
<strong>
|
||||||
{{ poll.owner.pseudo }} ,
|
{{ poll.owner.pseudo }} ,
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
{#[Framadate][Réservé à l'auteur] Sondage: TESSSSSSSSSST#}
|
{#[Framadate][Réservé à l'auteur] Sondage: TESSSSSSSSSST#}
|
||||||
{% extends 'email-base.html.twig' %}
|
{% extends 'email-base-plaintext.html.twig' %}
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
|
||||||
<h2>
|
<h2>
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
{#[Framadate] Notification d'un sondage : TESSSSSSSSSST#}
|
{#[Framadate] Notification d'un sondage : TESSSSSSSSSST#}
|
||||||
{% extends 'email-base.html.twig' %}
|
{% extends 'email-base-plaintext.html.twig' %}
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<strong>
|
<strong>
|
||||||
{{ owner.pseudo }}
|
{{ owner.pseudo }}
|
||||||
|
Loading…
Reference in New Issue
Block a user