This commit is contained in:
Kayn Ty 2020-04-12 16:19:19 +00:00
commit a90fe5dd1a
18 changed files with 400 additions and 96 deletions

2
.env
View File

@ -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 ###

15
.gitignore vendored
View File

@ -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

View File

@ -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
}

View File

@ -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(

View File

@ -0,0 +1,59 @@
<?php
namespace App\Service;
use App\Entity\Owner;
use App\Entity\Poll;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityManagerInterface;
use Swift_Message;
class MailService {
public function __construct(EntityManagerInterface $entityManager) {
$this->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 );
}
}

View File

@ -2,7 +2,7 @@
<html>
<head>
<meta charset="UTF-8">
<title>{% block title %}Welcome!{% endblock %}</title>
<title>{% block title %}Framdate{% endblock %}</title>
{% block stylesheets %}{% endblock %}
</head>
<body>

View File

@ -0,0 +1,50 @@
<div class="email">
<style>
html, body, main, header, footer, div {
font-family: "Open Sans", "Helvetica Neue", sans-serif;
}
.email{
padding: 1em;
}
.footer-content{
margin-top: 1em;
background: #f2dff2;
}
ul {
border-left: 3px solid #f2dff2;
}
a {
padding: 1em; border-radius: 3px;
background: #ceb4f5;
color: #201b27;
margin: 0.5rem 0;
display: inline-block;
}
h1,h2,h3{
color: #3c334a;
}
</style>
<header>
{% block title %}
{% if title is defined %}
<h1>{{ title }}</h1>
{% else %}
<h1>Framadate - email</h1>
{% endif %}
<hr>
{% endblock %}
{% block stylesheets %}{% endblock %}
</header>
<main>
{% block content %}
{% endblock %}
</main>
<footer>
{% block footer %}
{% include 'emails/footer.html.twig' %}
{% endblock %}
</footer>
</div>

View File

@ -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 %}
<h1>
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.
</h1>
<br>
<h2>
Vous pouvez modifier ce sondage à l'adresse suivante :
</h2>
<br>
{% include 'emails/partial/admin_link.html.twig' %}
<br>
Pour partager votre sondage aux participants, utilisez son lien d'accès public que vous avez reçu dans un autre email.
<br>
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 %}

View File

@ -0,0 +1,22 @@
{#[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 :
<br>
{% include 'emails/partial/admin_link.html.twig' %}
<br>
{% include 'emails/partial/public_link.html.twig' %}
{% endblock %}

View File

@ -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.
<br>
Ce mail est le premier, comportant le message qui doit être envoyé aux sondés.<br>
Merci de votre confiance.
Framadate
Vous pouvez maintenant transmettre ce message à toutes les personnes susceptibles de participer au vote.<br>
<br>
<fieldset>
<blockquote>
<i>
{{ owner.pseudo }} ( {{ owner.email }} ) vient de créer un sondage intitulé : " <strong>{{ title }}
"</strong>.
<br>
<br>
Merci de bien vouloir participer au sondage à l'adresse suivante :<br>
</i>
{% include 'emails/partial/public_link.html.twig' %}
</blockquote>
</fieldset>
{% endblock %}

View File

@ -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, <br>
<blockquote>
le {{ poll.expiracyDate | date('D Y-m-d') }}
</blockquote>
il ne sera plus possible d'y voter. <br>
Dans 31 jours il sera supprimé.<br>
Vous pouvez exporter ses données à tout moment en vous rendant à ce lien pour l'administrer:
<br>
{% include 'emails/partial/admin_link.html.twig' %}
{% endblock %}

View File

@ -1,4 +1,24 @@
Merci de votre confiance.
<a href="{{ BASE_URL }}">
Framadate
</a>
<div class="footer-content" style="text-align:center; padding: 1em;">
Framadate est un logiciel libre, tout le monde peut
<a href="https://framateam.org/ux-framatrucs/channels/framadate">
l'améliorer.
</a>
<br>
Merci de votre confiance.
<br>
<a href="{{ BASE_URL }}">
Framadate {{ BASE_URL }}
</a>
<br>
<a href="https://framagit.org/framasoft/framadate/funky-framadate-front">
Sources du client Front end,
</a>
<a href="https://framagit.org/framasoft/framadate/framadate">
API back end.
</a>
<a href="https://framagit.org/framasoft/framadate/funky-framadate-front/-/wikis/home">
Documentation
</a>
</div>

View File

@ -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 %}
<strong>
{{ poll.owner.pseudo }} ,
{{ poll.owner.email }} , </strong>
vient de modifier votre sondage accessible au lien suivant:
<br>
{% include 'emails/partial/admin_link.html.twig' %}
<br>
lien public:
<br>
{% include 'emails/partial/public_link.html.twig' %}
Merci de votre confiance.
Framadate
{% endblock %}

View File

@ -1,70 +1,26 @@
{#[Framadate][Réservé à l'auteur] Sondage: TESSSSSSSSSST#}
<h2>
{% extends 'email-base.html.twig' %}
{% block content %}
Voici la liste des {{ polls|length }} sondages
<a href="{{ BASE_URL }}">
Framadate
</a>
que vous avez créé.
</h2>
<div>
Si vous n'avez pas demandé à recevoir cet email, veuillez en informer les administrateurs du site Framadate.
</div>
<hr>
<ul>
{% for p in polls %}
<li>
<h2>
<strong>
{{ p.title }}
</strong>
Voici la liste des {{ owner.polls|length }} sondages
<a href="{{ BASE_URL }}">
Framadate
</a>
que vous avez créé.
</h2>
<div>
Si vous n'avez pas demandé à recevoir cet email, veuillez en informer les administrateurs du site Framadate.
</div>
<hr>
<ul style="list-style-type: none">
{% for poll in owner.polls %}
<li class="poll-element" style="border: solid 1px #ccc; padding: 1em; margin-top: 1em;">
{% include 'emails/partial/poll.html.twig' %}
</li>
{% endfor %}
</ul>
<br>
<div class="creation">
créé le {{ p.creationDate| date('Y m d ') }}
</div>
<div class="creation">
expirera le {{ p.expiracyDate| date('Y m d ') }}
</div>
<span class="votes-count">
{{ p.stacksOfVotes |length }} votes
</span>
<span class="votes-count">
{{ p.comments |length }} commentaires
</span>
{% if p.password |length %}
(accès avec mot de passe)
{% else %}
{% endif %}
<br>
<div class="public">
<span>
lien à donner aux votants:
</span>
{% if p.customUrl |length %}
<a href="{{ BASE_URL }}/poll/{{ p.customUrl }}">
{{ BASE_URL }}/poll/{{ p.customUrl }}
</a>
{% else %}
<a href="{{ BASE_URL }}/poll/{{ p.customUrl }}">
{{ BASE_URL }}/poll/{{ p.id }}
</a>
{% endif %}
</div>
<div class="admin">
<span>
administration:
</span>
<a href="{{ BASE_URL }}/poll/{{ p.id }}/admin/{{ p.adminKey }}">{{ BASE_URL }}
/admin/{{ p.adminKey }}</a>
</div>
</li>
{% endfor %}
</ul>
{% include 'emails/footer.html.twig' %}
{% endblock %}

View File

@ -0,0 +1,2 @@
<a href="{{ BASE_URL }}/#/poll/{{ poll.id }}/admin/{{ poll.adminKey }}">{{ BASE_URL }}
/admin/{{ poll.adminKey }}</a>

View File

@ -0,0 +1,39 @@
<div class="poll">
<h1>
Sondage {{ poll.title }}
</h1>
<br>
<div class="creation">
créé le {{ poll.creationDate| date('Y m d ') }}
</div>
<div class="creation">
expirera le {{ poll.expiracyDate| date('Y m d ') }}
</div>
<span class="votes-count">
{{ poll.stacksOfVotes |length }} votes
</span>
<span class="votes-count">
{{ poll.comments |length }} commentaires
</span>
{% if poll.password |length %}
(accès avec mot de passe)
{% else %}
{% endif %}
<br>
<div class="public">
<span>
lien à donner aux votants:
</span>
{% include 'emails/partial/public_link.html.twig' %}
</div>
<div class="admin">
<span>
administration:
</span>
{% include 'emails/partial/admin_link.html.twig' %}
</div>
</div>

View File

@ -0,0 +1,11 @@
<span class="public-link">
{% if poll.customUrl |length %}
<a href="{{ BASE_URL }}/#/vote/poll/key/{{ poll.customUrl }}">
{{ BASE_URL }}/#/vote/poll/key/{{ poll.customUrl }}
</a>
{% else %}
<a href="{{ BASE_URL }}/#/vote/poll/id/{{ poll.id }}">
{{ BASE_URL }}/#/vote/poll/id/{{ poll.id }}
</a>
{% endif %}
</span>

View File

@ -0,0 +1,13 @@
{#[Framadate] Notification d'un sondage : TESSSSSSSSSST#}
{% extends 'email-base.html.twig' %}
{% block content %}
<strong>
{{ owner.pseudo }}
</strong>
vient de voter au sondage.
<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 %}