diff --git a/.env b/.env index e6e11b0..889fc6a 100755 --- a/.env +++ b/.env @@ -39,4 +39,6 @@ CORS_ALLOW_ORIGIN=^https?://(localhost|127\.0\.0\.1)(:[0-9]+)?$ # For a generic SMTP server, use: "smtp://localhost:25?encryption=&auth_mode=" # Delivery is disabled by default via "null://localhost" MAILER_URL=null://localhost +# set the support email who will answer users in case of emergency +SUPPORT_EMAIL=admin_framadate@yopmail.com ###< symfony/swiftmailer-bundle ### diff --git a/.gitignore b/.gitignore index 616410a..416a4d1 100755 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,18 @@ ###> symfony/web-server-bundle ### /.web-server-pid ###< symfony/web-server-bundle ### + +# framdate front end funky repository +public/3rdpartylicenses.txt +public/assets/i18n/en.json +public/assets/i18n/fr.json +public/assets/scss/atoms/_buttons.scss +public/assets/scss/atoms/_main.scss +public/assets/scss/useful_classes.scss +public/framadate-scripts-bundled.js +public/main-es2018.js +public/main-es5.js +public/polyfills-es2018.js +public/polyfills-es5.js +public/scripts.js +public/styles.css diff --git a/src/Controller/DefaultController.php b/src/Controller/DefaultController.php index 6933d5f..2eb7664 100755 --- a/src/Controller/DefaultController.php +++ b/src/Controller/DefaultController.php @@ -31,6 +31,8 @@ class DefaultController extends AbstractController { */ public function sendPollsToUser( $email, \Swift_Mailer $mailer ) { $repository = $this->getDoctrine()->getRepository( Owner::class ); + + // find user by email $founduser = $repository->findOneBy( [ 'email' => $email ] ); if ( $founduser ) { @@ -38,6 +40,7 @@ class DefaultController extends AbstractController { $templateVars = [ 'owner' => $founduser, 'polls' => $polls, + 'title' => 'Mes sondages - '.$email, ]; $message = ( new Swift_Message( 'Framadate - mes sondages' ) ) @@ -49,20 +52,24 @@ class DefaultController extends AbstractController { $templateVars ) ); + // send email $mailer->send( $message ); - return $this->render( 'emails/owner-list.html.twig', $templateVars ); + return $this->json( [ + 'message' => 'mail succefully sent to user ' . $email, + 'data' => '', + ], + 200 ); - } else { + + + } else { // user not found case return $this->json( [ 'message' => 'no user found for email ' . $email, 'data' => '', ], 400 ); } - // find user by email - // send email - // user not found case } diff --git a/src/Controller/PollController.php b/src/Controller/PollController.php index 0180cbf..2126d49 100644 --- a/src/Controller/PollController.php +++ b/src/Controller/PollController.php @@ -5,6 +5,7 @@ namespace App\Controller; use App\Entity\Choice; use App\Entity\Owner; use App\Entity\Poll; +use App\Service\MailService; use FOS\RestBundle\Controller\Annotations\Delete; use FOS\RestBundle\Controller\Annotations\Get; use FOS\RestBundle\Controller\Annotations\Post; @@ -137,7 +138,7 @@ class PollController extends AbstractController { * * @return JsonResponse */ - public function newPollAction( Request $request ) { + public function newPollAction( Request $request, \Swift_Mailer $mailer, MailService $mail_service ) { $data = $request->getContent(); @@ -225,6 +226,8 @@ class PollController extends AbstractController { $precision = 'from an existing user : ' . $foundOwner->getEmail(); } + $mail_service->sendCreationMailAction( $foundOwner, $newpoll ); + return $this->json( [ 'message' => 'you created a poll ' . $precision, 'poll' => $newpoll, @@ -237,6 +240,59 @@ class PollController extends AbstractController { } + /** + * @Get( + * path = "/mail/test-mail-poll/{emailChoice}", + * name = "test-mail-poll", + * ) + * + * send the creation mail to owner + * + * @param Owner $admin_user + * @param Poll $poll + * @param \Swift_Mailer $mailer + * + * @return int + */ +// public function sendCreationMailAction( Owner $admin_user, Poll $poll, \Swift_Mailer $mailer) { + public function testSendCreationMailAction( MailService $mail_service, $emailChoice = 'creation_vote' ) { + $em = $this->getDoctrine()->getRepository( Owner::class ); + $foundOwner = $em->find( 1 ); + $poll = $foundOwner->getPolls()[ 0 ]; + $comment = $foundOwner->getComments()[ 0 ]; + + + $emailChoicesTemplates = [ + 'creation_poll' => 'creation-mail.html.twig', + 'edit_poll' => 'modification-notification-mail.html.twig', + 'creation_poll_admin' => 'author-mail.html.twig', + 'owner_list' => 'owner-list.html.twig', + 'expiration' => 'expiration-mail.html.twig', + 'creation_comment' => 'comment-notification.html.twig', + 'creation_vote' => 'vote-notification.html.twig', + ]; + $emailChoicesTitles = [ + 'creation_poll' => 'Framadate | Création de sondage - lien public - ' . $poll->getTitle(), + 'edit_poll' => 'Framadate | Modification de sondage - ' . $poll->getTitle(), + 'creation_poll_admin' => 'Framadate | Création de sondage - lien admin - ', + 'owner_list' => 'Framadate | Vos sondages créés', + 'expiration' => 'Framadate | Notice d\'expiration du sondage '. $poll->getTitle(), + 'creation_comment' => 'Framadate | Commentaire de "' . $foundOwner->getPseudo() . '" - sondage ' . $poll->getTitle(), + 'creation_vote' => 'Framadate | Vote de "' . $foundOwner->getPseudo() . '" - sondage ' . $poll->getTitle(), + ]; + +// $mail_service->sendCreationMailAction( $foundOwner, $poll ); + $templateVars = [ + 'owner' => $foundOwner, + 'comment' => $comment, + 'poll' => $poll, + 'email_template' => 'emails/' . $emailChoicesTemplates[ $emailChoice ], + 'title' => $emailChoicesTitles[ $emailChoice ], + ]; + + return $this->render( $templateVars[ 'email_template' ], $templateVars ); + } + /** * @Delete( diff --git a/src/Service/MailService.php b/src/Service/MailService.php new file mode 100644 index 0000000..698b15d --- /dev/null +++ b/src/Service/MailService.php @@ -0,0 +1,59 @@ +em = $entityManager; + } + + public function sendCreationMailAction( Owner $foundOwner, Poll $newpoll, \Swift_Mailer $mailer ) { + $em = $this->em->getRepository( Owner::class ); + $admin_user = $foundOwner; + $poll = $newpoll; + + + // 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, + '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 ); + + } +} diff --git a/templates/base.html.twig b/templates/base.html.twig index a1b8fd8..34dd070 100755 --- a/templates/base.html.twig +++ b/templates/base.html.twig @@ -2,7 +2,7 @@ - {% block title %}Welcome!{% endblock %} + {% block title %}Framdate{% endblock %} {% block stylesheets %}{% endblock %} diff --git a/templates/email-base.html.twig b/templates/email-base.html.twig new file mode 100644 index 0000000..d61d744 --- /dev/null +++ b/templates/email-base.html.twig @@ -0,0 +1,50 @@ +
+ + +
+ {% block title %} + {% if title is defined %} +

{{ title }}

+ {% else %} +

Framadate - email

+ {% endif %} +
+ {% endblock %} + {% block stylesheets %}{% endblock %} +
+
+ + {% block content %} + {% endblock %} +
+ + +
diff --git a/templates/emails/author-mail.html.twig b/templates/emails/author-mail.html.twig index 3877200..9a154ed 100755 --- a/templates/emails/author-mail.html.twig +++ b/templates/emails/author-mail.html.twig @@ -1,9 +1,25 @@ {#[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 %} +

-Vous pouvez modifier ce sondage à l'adresse suivante : + Ce message ne doit PAS être diffusé aux sondés. Il est réservé à l'auteur du sondage. +

+
+

+ Vous pouvez modifier ce sondage à l'adresse suivante : +

+
+ {% include 'emails/partial/admin_link.html.twig' %} +
+ Pour partager votre sondage aux participants, utilisez son lien d'accès public que vous avez reçu dans un autre email. +
-https://framadate.org/NGutN7jB9vtoGOEjCfUJWBwr/admin + {% if poll.password %} + Ce sondage est protégé par un mot de passe, n'oubliez pas de le communiquer à vos participants. + Vous pouvez changer ce mot de passe via l'administration. + {% else %} -Merci de votre confiance. -Framadate + {% endif %} + +{% endblock %} diff --git a/templates/emails/comment-notification.html.twig b/templates/emails/comment-notification.html.twig new file mode 100644 index 0000000..579ffd3 --- /dev/null +++ b/templates/emails/comment-notification.html.twig @@ -0,0 +1,22 @@ +{#[Framadate] Notification d'un sondage : TESSSSSSSSSST#} +{% extends 'email-base.html.twig' %} +{% block content %} + + {{ owner.pseudo }} + + vient de rédiger un commentaire. +
+ + {% autoescape %} + {{ comment.text }} + {% endautoescape %} + +
+
+ Vous pouvez retrouver votre sondage avec le lien suivant : +
+ {% include 'emails/partial/admin_link.html.twig' %} +
+ {% include 'emails/partial/public_link.html.twig' %} + +{% endblock %} diff --git a/templates/emails/creation-mail.html.twig b/templates/emails/creation-mail.html.twig index 31846b1..081beef 100755 --- a/templates/emails/creation-mail.html.twig +++ b/templates/emails/creation-mail.html.twig @@ -1,11 +1,30 @@ {#[Framadate][Pour diffusion aux sondés] Sondage: TESSSSSSSSSST#} -Ceci est le message qui doit être envoyé aux sondés. -Vous pouvez maintenant transmettre ce message à toutes les personnes susceptibles de participer au vote. +{% extends 'email-base.html.twig' %} +{% block content %} -hah vient de créer un sondage intitulé : "TESSSSSSSSSST". -Merci de bien vouloir participer au sondage à l'adresse suivante : -https://framadate.org/heh-le-test + Suite à la création de votre sondage {{ title }} vous recevez deux emails afin de ne pas transmettre par erreur aux sondés le lien d'administration de votre sondage. +
+ Ce mail est le premier, comportant le message qui doit être envoyé aux sondés.
-Merci de votre confiance. -Framadate + Vous pouvez maintenant transmettre ce message à toutes les personnes susceptibles de participer au vote.
+ +
+
+ +
+ + + {{ owner.pseudo }} ( {{ owner.email }} ) vient de créer un sondage intitulé : " {{ title }} + ". +
+
+ Merci de bien vouloir participer au sondage à l'adresse suivante :
+ +
+ {% include 'emails/partial/public_link.html.twig' %} + +
+
+ +{% endblock %} diff --git a/templates/emails/expiration-mail.html.twig b/templates/emails/expiration-mail.html.twig index 606e250..49adf56 100755 --- a/templates/emails/expiration-mail.html.twig +++ b/templates/emails/expiration-mail.html.twig @@ -1,8 +1,15 @@ {#[Framadate][expiration] Sondage: TESSSSSSSSSST#} -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 àtotmoment en vous rendant à ce lien pour l'administrer. +{% extends 'email-base.html.twig' %} +{% block content %} -https://framadate.org/heh-le-test -Merci de votre confiance. -Framadate + Ce sondage va bientôt expirer dans 1 jour,
+
+ le {{ poll.expiracyDate | date('D Y-m-d') }} +
+ 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: +
+ {% include 'emails/partial/admin_link.html.twig' %} +{% endblock %} diff --git a/templates/emails/footer.html.twig b/templates/emails/footer.html.twig index 0fda947..bb67a38 100755 --- a/templates/emails/footer.html.twig +++ b/templates/emails/footer.html.twig @@ -1,4 +1,24 @@ -Merci de votre confiance. - - Framadate - + diff --git a/templates/emails/modification-notification-mail.html.twig b/templates/emails/modification-notification-mail.html.twig index c2c2b6e..d1b6728 100755 --- a/templates/emails/modification-notification-mail.html.twig +++ b/templates/emails/modification-notification-mail.html.twig @@ -1,5 +1,15 @@ {#[Framadate] Participation au sondage : TESSSSSSSSSST#} -Quelqu'un vient de modifier votre sondage accessible au lien suivant https://framadate.org/NGutN7jB9vtoGOEjCfUJWBwr/admin. +{% extends 'email-base.html.twig' %} +{% block content %} + + {{ poll.owner.pseudo }} , + {{ poll.owner.email }} , + vient de modifier votre sondage accessible au lien suivant: +
+ {% include 'emails/partial/admin_link.html.twig' %} +
+ lien public: +
+ {% include 'emails/partial/public_link.html.twig' %} -Merci de votre confiance. -Framadate +{% endblock %} diff --git a/templates/emails/owner-list.html.twig b/templates/emails/owner-list.html.twig index 3ec9e74..2a9a868 100755 --- a/templates/emails/owner-list.html.twig +++ b/templates/emails/owner-list.html.twig @@ -1,70 +1,26 @@ {#[Framadate][Réservé à l'auteur] Sondage: TESSSSSSSSSST#} -

+{% extends 'email-base.html.twig' %} +{% block content %} - Voici la liste des {{ polls|length }} sondages - - Framadate - - que vous avez créé. -

-
- Si vous n'avez pas demandé à recevoir cet email, veuillez en informer les administrateurs du site Framadate. -
-
- - -{% include 'emails/footer.html.twig' %} +{% endblock %} diff --git a/templates/emails/partial/admin_link.html.twig b/templates/emails/partial/admin_link.html.twig new file mode 100644 index 0000000..9743509 --- /dev/null +++ b/templates/emails/partial/admin_link.html.twig @@ -0,0 +1,2 @@ +{{ BASE_URL }} + /admin/{{ poll.adminKey }} diff --git a/templates/emails/partial/poll.html.twig b/templates/emails/partial/poll.html.twig new file mode 100644 index 0000000..764aa70 --- /dev/null +++ b/templates/emails/partial/poll.html.twig @@ -0,0 +1,39 @@ +
+

+ Sondage {{ poll.title }} +

+ + +
+
+ créé le {{ poll.creationDate| date('Y m d ') }} +
+
+ expirera le {{ poll.expiracyDate| date('Y m d ') }} +
+ + {{ poll.stacksOfVotes |length }} votes + + + {{ poll.comments |length }} commentaires + + {% if poll.password |length %} + (accès avec mot de passe) + {% else %} + {% endif %} + +
+ +
+ + lien à donner aux votants: + + {% include 'emails/partial/public_link.html.twig' %} +
+
+ + administration: + + {% include 'emails/partial/admin_link.html.twig' %} +
+
diff --git a/templates/emails/partial/public_link.html.twig b/templates/emails/partial/public_link.html.twig new file mode 100644 index 0000000..41114ce --- /dev/null +++ b/templates/emails/partial/public_link.html.twig @@ -0,0 +1,11 @@ + + {% if poll.customUrl |length %} + + {{ BASE_URL }}/#/vote/poll/key/{{ poll.customUrl }} + + {% else %} + + {{ BASE_URL }}/#/vote/poll/id/{{ poll.id }} + + {% endif %} + diff --git a/templates/emails/vote-notification.html.twig b/templates/emails/vote-notification.html.twig new file mode 100644 index 0000000..b1b174d --- /dev/null +++ b/templates/emails/vote-notification.html.twig @@ -0,0 +1,13 @@ +{#[Framadate] Notification d'un sondage : TESSSSSSSSSST#} +{% extends 'email-base.html.twig' %} +{% block content %} + + {{ owner.pseudo }} + + vient de voter au sondage. +
+ Vous pouvez retrouver votre sondage avec le lien suivant : + {% include 'emails/partial/admin_link.html.twig' %} + {% include 'emails/partial/public_link.html.twig' %} + +{% endblock %}