Compare commits

...

5 Commits

Author SHA1 Message Date
Tykayn 8c03b1c521 remove content in header, upgrade deps 2021-05-21 10:52:34 +02:00
Tykayn 7f01e2de60 var env for mailer 2021-05-21 10:15:48 +02:00
Tykayn a034f59a90 add symfony profiling, and spool for emails 2021-05-21 10:09:51 +02:00
Tykayn 64fd83caa2 send mail with owner polls 2021-05-21 09:34:01 +02:00
Tykayn f8554d5f7a global site name in templates 2021-05-21 09:33:31 +02:00
23 changed files with 737 additions and 440 deletions

3
.env
View File

@ -38,7 +38,8 @@ DATABASE_URL=mysql://framadate-admin:framadate-admin-password@127.0.0.1:3306/fra
# Delivery is disabled by default via "null://localhost" # Delivery is disabled by default via "null://localhost"
MAILER_URL=sendmail://YOUR_WEBSITE MAILER_URL=sendmail://YOUR_WEBSITE
# set the support email who will answer users in case of emergency # set the support email who will answer users in case of emergency
SUPPORT_EMAIL=YOUR_EMAIL SUPPORT_EMAIL=support-framadate@YOUR_WEBSITE
SPOOL_PATH=/var/www/html/date-poll-api/var/email/spool
###< symfony/swiftmailer-bundle ### ###< symfony/swiftmailer-bundle ###
###> nelmio/cors-bundle ### ###> nelmio/cors-bundle ###

View File

@ -64,7 +64,9 @@
"require-dev": { "require-dev": {
"doctrine/doctrine-fixtures-bundle": "^3.4", "doctrine/doctrine-fixtures-bundle": "^3.4",
"symfony/debug-bundle": "5.2.*", "symfony/debug-bundle": "5.2.*",
"symfony/maker-bundle": "^1.30" "symfony/maker-bundle": "^1.30",
"symfony/stopwatch": "^5.2",
"symfony/web-profiler-bundle": "^5.2"
}, },
"scripts": { "scripts": {
"auto-scripts": { "auto-scripts": {

888
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -13,4 +13,5 @@ return [
Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle::class => ['dev' => true, 'test' => true], Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle::class => ['dev' => true, 'test' => true],
Nelmio\CorsBundle\NelmioCorsBundle::class => ['all' => true], Nelmio\CorsBundle\NelmioCorsBundle::class => ['all' => true],
Symfony\Bundle\DebugBundle\DebugBundle::class => ['dev' => true, 'test' => true], Symfony\Bundle\DebugBundle\DebugBundle::class => ['dev' => true, 'test' => true],
Symfony\Bundle\WebProfilerBundle\WebProfilerBundle::class => ['dev' => true, 'test' => true],
]; ];

View File

@ -0,0 +1,6 @@
web_profiler:
toolbar: true
intercept_redirects: false
framework:
profiler: { only_exceptions: false }

View File

@ -0,0 +1,11 @@
#SUPPORT_EMAIL: '%env(SUPPORT_EMAIL)%'
# config/packages/dev/mailer.yaml
framework:
mailer:
envelope:
sender: 'fabien@example.com'
recipients: ['foo@example.com', 'bar@example.com']
headers:
from: '%env(SUPPORT_EMAIL)%'
bcc: 'baz@example.com'
X-Custom-Header: 'foobar'

View File

@ -1,3 +1,5 @@
swiftmailer: swiftmailer:
url: '%env(MAILER_URL)%' url: '%env(MAILER_URL)%'
spool: { type: 'memory' } spool:
type: 'file'
path: '%env(SPOOL_PATH)%'

View File

@ -0,0 +1,6 @@
web_profiler:
toolbar: false
intercept_redirects: false
framework:
profiler: { collect: false }

View File

@ -0,0 +1,7 @@
web_profiler_wdt:
resource: '@WebProfilerBundle/Resources/config/routing/wdt.xml'
prefix: /_wdt
web_profiler_profiler:
resource: '@WebProfilerBundle/Resources/config/routing/profiler.xml'
prefix: /_profiler

View File

@ -5,10 +5,13 @@ namespace App\Controller;
use App\Entity\Owner; use App\Entity\Owner;
use App\Entity\Poll; use App\Entity\Poll;
use JMS\Serializer\Type\Exception\Exception; use JMS\Serializer\Type\Exception\Exception;
use Psr\Log\LoggerInterface;
use Swift_Mailer; use Swift_Mailer;
use Swift_Message; use Swift_Message;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Mailer\Exception\HttpTransportException;
use Symfony\Component\Mailer\Exception\TransportExceptionInterface; use Symfony\Component\Mailer\Exception\TransportExceptionInterface;
/** /**
* sending emails controller * sending emails controller
* *
@ -51,7 +54,7 @@ class EmailsController extends AbstractController {
* *
* @throws TransportExceptionInterface * @throws TransportExceptionInterface
*/ */
public function sendMailWithVars( $config ) { public function sendMailWithVars( $config) {
if ( ! isset( $config[ 'poll' ] ) ) { if ( ! isset( $config[ 'poll' ] ) ) {
$config[ 'poll' ] = new Poll(); $config[ 'poll' ] = new Poll();
@ -82,14 +85,22 @@ class EmailsController extends AbstractController {
$message = ( new Swift_Message( $config[ 'title' ] ) ) $message = ( new Swift_Message( $config[ 'title' ] ) )
->setContentType( "text/html" ) ->setContentType( "text/html" )
->setCharset( 'UTF-8' ) ->setCharset( 'UTF-8' )
->setFrom( [ 'ne-pas-repondre@framadate-api.cipherbliss.com'] ) ->setFrom( [ 'ne-pas-repondre@framadate-api.cipherbliss.com' ] )
->setTo( [ $config[ 'owner' ]->getEmail() ] ) ->setTo( [ $config[ 'owner' ]->getEmail() ] )
->setBody( $htmlbody, 'text/html' ); ->setBody( $htmlbody, 'text/html' );
// Send the message // Send the message
$numSent = $this->mail_service->send( $message ); try {
$this->numSent = $numSent; $numSent = $this->mail_service->send( $message );
$this->numSent = $numSent;
} catch ( TransportExceptionInterface $err ) {
// some error prevented the email sending; display an
// error message or try to resend the message
throw $err;
}
} }

View File

@ -14,6 +14,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\SerializerInterface; use JMS\Serializer\SerializerInterface;
use Psr\Log\LoggerInterface;
use Swift_Mailer; use Swift_Mailer;
use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
@ -121,6 +122,36 @@ class PollController extends EmailsController {
404 ); 404 );
} }
/**
* get a poll config by its custom URL, we do not want polls to be reachable by their numeric id
* @Get(
* path = "/owner/{owner_email}/",
* name = "get_owner_poll",
* )
*
* @return JsonResponse|Response
*/
function getOwnerPolls( $owner_email , LoggerInterface $logger ) {
$repository = $this->getDoctrine()->getRepository( Owner::class );
$owner = $repository->findOneByEmail( $owner_email );
if ( ! $owner ) {
return $this->json( [ 'message' => "Owner $owner_email non trouvé" ], 404 );
} else {
$polls = $owner->getPolls();
$pollsDisplay = [];
foreach ( $polls as $p ) {
$pollsDisplay[] = $p->displayForAdmin();
}
$mail_sent = $this->sendOwnerPollsAction( $owner );
$logger->info('getOwnerPolls : Email sent : '.$mail_sent);
return $this->json( [ 'mail_sent' => $mail_sent ], $mail_sent ? 200 : 404 );
// return $this->json(['owner' => $owner->displayForAdmin(), 'polls' => $pollsDisplay], 200);
}
}
/** /**
* get a poll config by its custom URL, we do not want polls to be reachable by their numeric id * get a poll config by its custom URL, we do not want polls to be reachable by their numeric id
* @Get( * @Get(
@ -412,27 +443,6 @@ class PollController extends EmailsController {
return $this->render( 'emails/creation-mail.html.twig', return $this->render( 'emails/creation-mail.html.twig',
[ 'poll' => $foundPoll, 'owner' => $foundPoll->getOwner() ] ); [ 'poll' => $foundPoll, 'owner' => $foundPoll->getOwner() ] );
// if ( $foundOwner ) {
// $sent = $this->sendOwnerPollsAction( $foundOwner );
// if ( $sent ) {
// $config = [
// 'owner' => $foundOwner,
// 'title' => $this->getParameter( 'WEBSITE_NAME' ) . ' | Mes sondages',
// 'email_template' => 'emails/owner-list.html.twig',
// ];
// return $this->render( 'emails/owner-list.html.twig', $config );
// }
// }
// return $this->json( [ "message" => "test email sent to " . $foundOwner->getEmail() . "!" ], 200 );
// $this->sendMailWithVars( $config );
// return $this->json( [ "message" => "user with this email was not found" ], 400 );
} }

View File

@ -35,15 +35,15 @@ class PollRepository extends ServiceEntityRepository {
return $this->findExpirationPollOfDay( - 30 ); return $this->findExpirationPollOfDay( - 30 );
} }
public function findExpirationPollOfDay( $count_of_days){ public function findExpirationPollOfDay( $count_of_days ) {
$today = new \DateTime(); $today = new \DateTime();
if($count_of_days > -1){ if ( $count_of_days > - 1 ) {
$date_soon = $today->add( new \DateInterval( 'P' . $count_of_days . 'D' ) ); $date_soon = $today->add( new \DateInterval( 'P' . $count_of_days . 'D' ) );
}else{ } else {
$date_soon = $today->sub( new \DateInterval( 'P' . abs($count_of_days) . 'D' ) ); $date_soon = $today->sub( new \DateInterval( 'P' . abs( $count_of_days ) . 'D' ) );
} }
@ -55,4 +55,21 @@ class PollRepository extends ServiceEntityRepository {
->getResult(); ->getResult();
} }
/**
* find all the polls of an owner
*
* @param $email
*
* @return int|mixed|string
*/
public function findAllByOwnerEmail( $email ) {
return $this->createQueryBuilder( 'p' )
->andWhere( 'p.owner.email = :email' )
->setParameter( 'email', $email )
->orderBy( 'p.id', 'DESC' )
->getQuery()
->getResult();
}
} }

View File

@ -350,6 +350,9 @@
"symfony/polyfill-php80": { "symfony/polyfill-php80": {
"version": "v1.22.1" "version": "v1.22.1"
}, },
"symfony/profiler-pack": {
"version": "v1.0.5"
},
"symfony/property-access": { "symfony/property-access": {
"version": "v5.2.4" "version": "v5.2.4"
}, },
@ -425,6 +428,20 @@
"symfony/var-exporter": { "symfony/var-exporter": {
"version": "v5.2.4" "version": "v5.2.4"
}, },
"symfony/web-profiler-bundle": {
"version": "3.3",
"recipe": {
"repo": "github.com/symfony/recipes",
"branch": "master",
"version": "3.3",
"ref": "6bdfa1a95f6b2e677ab985cd1af2eae35d62e0f6"
},
"files": [
"config/packages/dev/web_profiler.yaml",
"config/packages/test/web_profiler.yaml",
"config/routes/dev/web_profiler.yaml"
]
},
"symfony/yaml": { "symfony/yaml": {
"version": "v5.2.5" "version": "v5.2.5"
}, },

View File

@ -4,16 +4,16 @@
<meta charset="UTF-8"> <meta charset="UTF-8">
<base href="/"> <base href="/">
<meta content="width=device-width, initial-scale=1" name="viewport"/> <meta content="width=device-width, initial-scale=1" name="viewport"/>
<link href="favicon.ico" rel="icon" type="image/x-icon"/> <link href="img/logo.png" rel="icon" type="image/png"/>
<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500&display=swap" rel="stylesheet"/> {# <link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500&display=swap" rel="stylesheet"/>#}
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet"/> {# <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet"/>#}
<link rel="stylesheet" href="styles.css" crossorigin="anonymous"> <link rel="stylesheet" href="styles.css" crossorigin="anonymous">
<title>{% block title %}Framdate{% endblock %}</title> <title>{% block title %}{{ WEBSITE_NAME }}{% endblock %}</title>
{# {% block stylesheets %}#} {# {% block stylesheets %} #}
{# <link rel="stylesheet" href="{{ asset('build/vendors~app.css') }}">#} {# <link rel="stylesheet" href="{{ asset('build/vendors~app.css') }}"> #}
{# <link rel="stylesheet" href="{{ asset('build/app.css') }}">#} {# <link rel="stylesheet" href="{{ asset('build/app.css') }}"> #}
{# {% endblock %}#} {# {% endblock %} #}
</head> </head>
<body> <body>
{% include 'split/header.html.twig' %} {% include 'split/header.html.twig' %}
@ -22,7 +22,7 @@
<div class="container"> <div class="container">
{% block body %} {% block body %}
coucou!
{% endblock %} {% endblock %}
</div> </div>
{% endblock %} {% endblock %}

View File

@ -2,7 +2,7 @@
{% if title is defined %} {% if title is defined %}
<h1>{{ title }}</h1> <h1>{{ title }}</h1>
{% else %} {% else %}
<h1>Framadate - email</h1> <h1>{{ WEBSITE_NAME }} - email</h1>
{% endif %} {% endif %}
<hr> <hr>
{% endblock %} {% endblock %}

View File

@ -9,9 +9,9 @@
<header> <header>
{% block title %} {% block title %}
{% if title is defined %} {% if title is defined %}
<h1 class="text-center">{{ title }}</h1> <h1 class="text-center">{{ title }} - {{ WEBSITE_NAME }}</h1>
{% else %} {% else %}
<h1 class="text-center">Framadate</h1> <h1 class="text-center">{{ WEBSITE_NAME }}</h1>
{% endif %} {% endif %}
<hr> <hr>
{% endblock %} {% endblock %}

View File

@ -1,5 +1,5 @@
<div class="footer-content" style="text-align:center; padding: 1em;"> <div class="footer-content" style="text-align:center; padding: 1em;">
Framadate est un logiciel libre, tout le monde peut {{ WEBSITE_NAME }} est un logiciel libre, tout le monde peut
<a href="https://framateam.org/ux-framatrucs/channels/framadate"> <a href="https://framateam.org/ux-framatrucs/channels/framadate">
l'améliorer. l'améliorer.
</a> </a>
@ -7,7 +7,7 @@
Merci de votre confiance. Merci de votre confiance.
<br> <br>
<a href="{{ BASE_URL }}"> <a href="{{ BASE_URL }}">
Framadate {{ BASE_URL }} {{ WEBSITE_NAME }} {{ BASE_URL }}
</a> </a>
<br> <br>
<a href="https://framagit.org/framasoft/framadate/funky-framadate-front"> <a href="https://framagit.org/framasoft/framadate/funky-framadate-front">

View File

@ -6,7 +6,7 @@
Voici la liste des {{ owner.polls|length }} sondages Voici la liste des {{ owner.polls|length }} sondages
<a href="{{ BASE_URL }}"> <a href="{{ BASE_URL }}">
Framadate {{ WEBSITE_NAME }}
</a> </a>
que vous avez créé. que vous avez créé.
</h2> </h2>

View File

@ -2,7 +2,7 @@
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<title>Framadate</title> <title>{{ WEBSITE_NAME }}</title>
<base href="/"> <base href="/">
<meta <meta
content="width=device-width, initial-scale=1" content="width=device-width, initial-scale=1"
@ -12,56 +12,58 @@
rel="icon" rel="icon"
type="image/x-icon"> type="image/x-icon">
<link {# <link#}
rel="stylesheet" {# rel="stylesheet"#}
href="assets/css/bootstrap-reboot-4.3.1.css"> {# href="/assets/css/bootstrap-reboot-4.3.1.css">#}
<link <link
rel="stylesheet" rel="stylesheet"
href="styles.css" href="styles.css"
crossorigin="anonymous"> crossorigin="anonymous">
</head> </head>
<body> <body>
<app-root></app-root> <app-root>
Chargement de l'app, hopla!
</app-root>
<footer id="main-footer" class="text-center"> <footer id="main-footer" class="text-center">
<a href="https://framagit.org/tykayn/date-poll-api"> <a href="https://framagit.org/tykayn/date-poll-api">
Sources Sources
<i class="fa fa-gitlab"></i> <i class="fa fa-gitlab"></i>
</a> </a>
<a href="mailto:contact@cipherbliss.com"> <a href="mailto:contact+framadate@cipherbliss.com">
Contact Contact
<i class="fa fa-envelope"></i> <i class="fa fa-envelope"></i>
</a> </a>
</footer> </footer>
<script {#<script#}
src="runtime-es2018.js" {# src="/runtime-es2018.js"#}
crossorigin="anonymous" {# crossorigin="anonymous"#}
type="module"></script> {# type="module"></script>#}
<script {#<script#}
src="runtime-es5.js" {# src="runtime-es5.js"#}
crossorigin="anonymous" {# crossorigin="anonymous"#}
nomodule {# nomodule#}
defer></script> {# defer></script>#}
<script {#<script#}
src="polyfills-es5.js" {# src="polyfills-es5.js"#}
crossorigin="anonymous" {# crossorigin="anonymous"#}
nomodule {# nomodule#}
defer></script> {# defer></script>#}
<script {#<script#}
src="polyfills-es2018.js" {# src="polyfills-es2018.js"#}
crossorigin="anonymous" {# crossorigin="anonymous"#}
type="module"></script> {# type="module"></script>#}
<script {#<script#}
src="scripts.js" {# src="scripts.js"#}
crossorigin="anonymous" {# crossorigin="anonymous"#}
defer></script> {# defer></script>#}
<script {#<script#}
src="main-es2018.js" {# src="main-es2018.js"#}
crossorigin="anonymous" {# crossorigin="anonymous"#}
type="module"></script> {# type="module"></script>#}
<script {#<script#}
src="main-es5.js" {# src="main-es5.js"#}
crossorigin="anonymous" {# crossorigin="anonymous"#}
nomodule {# nomodule#}
defer></script> {# defer></script>#}
</body> </body>
</html> </html>

View File

@ -1,5 +1,5 @@
{% extends 'base.html.twig' %} {% extends 'base.html.twig' %}
{% block title %}migration depuis un Framadate version 1{% endblock %} {% block title %}migration depuis un Framadate version 1 vers {{ WEBSITE_NAME }} version funky{% endblock %}
{% block body %} {% block body %}
<main> <main>

View File

@ -33,7 +33,7 @@
<td>{{ poll.title }}</td> <td>{{ poll.title }}</td>
<td>{{ poll.customUrl }}</td> <td>{{ poll.customUrl }}</td>
<td>{{ poll.description }}</td> <td>{{ poll.description }}</td>
<td>{{ poll.creationDate ? poll.creationDate|date('Y-m-d H:i:s') : '' }}</td> <td>{{ poll.createdAt ? poll.createdAt|date('Y-m-d H:i:s') : '' }}</td>
<td>{{ poll.expiracyDate ? poll.expiracyDate|date('Y-m-d H:i:s') : '' }}</td> <td>{{ poll.expiracyDate ? poll.expiracyDate|date('Y-m-d H:i:s') : '' }}</td>
<td>{{ poll.kind }}</td> <td>{{ poll.kind }}</td>
<td>{{ poll.allowedAnswers ? poll.allowedAnswers|join(', ') : '' }}</td> <td>{{ poll.allowedAnswers ? poll.allowedAnswers|join(', ') : '' }}</td>

View File

@ -25,7 +25,7 @@
</tr> </tr>
<tr> <tr>
<th>CreationDate</th> <th>CreationDate</th>
<td>{{ poll.creationDate ? poll.creationDate|date('Y-m-d H:i:s') : '' }}</td> <td>{{ poll.createdAt ? poll.createdAt|date('Y-m-d H:i:s') : '' }}</td>
</tr> </tr>
<tr> <tr>
<th>ExpiracyDate</th> <th>ExpiracyDate</th>

View File

@ -1,20 +1,6 @@
{% block header %} {% block header %}
<header class="bg-purple-300 p-4 block"> {# <img src="{{ WEBSITE_LOGO }}" alt="logo">#}
<div class="container"> {# {{ WEBSITE_NAME }}#}
<nav>
<ul>
<li>
<a class="btn button rounded bg-purple-200 p-2" href="/">
<i class="fa fa-home"></i>
<img src="{{ WEBSITE_LOGO }}" alt="logo">
{{ WEBSITE_NAME }}
</a>
</li>
</ul>
</nav>
</div>
</header>
{% endblock %} {% endblock %}