feat(artemis): Ajoute une réponse basique à la route du dashboard Artemis

Ce commit ajoute une réponse simple "a" à la route `/artemis` du DashboardController. Cela permet de s'assurer que la route fonctionne correctement et renvoie une réponse.
This commit is contained in:
Serreau Jovann
2025-07-17 13:41:24 +02:00
parent ba0978d492
commit 5ff0562b15
8 changed files with 133 additions and 3 deletions

1
.env
View File

@@ -49,3 +49,4 @@ SENTRY_DSN=
###< sentry/sentry-symfony ###
VITE_LOAD=0
REDIS_DSN="redis://redis:6379"
REAL_MAIL=1

View File

@@ -70,6 +70,7 @@
REDIS_URL="redis://{{ redis_password }}@127.0.0.1:{{ redis_port }}"
MESSENGER_TRANSPORT_DSN="redis://{{ redis_password }}@127.0.0.1:{{ redis_port }}/messages"
APP_SECRET=939bbc67038c2e2d1232d86fc605bf2f
REAL_MAIL=1
dest: "{{ path }}/.env.local"
when: ansible_os_family == "Debian"

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

View File

@@ -12,6 +12,7 @@ class DashboardController extends AbstractController
#[Route(path: '/artemis',name: 'artemis_dashboard',methods: ['GET', 'POST'])]
public function artemis(AuthenticationUtils $authenticationUtils): Response
{
return new Response("a");
}
}

View File

@@ -3,6 +3,7 @@
namespace App\Controller;
use App\Attribute\Mainframe;
use App\Service\Mailer\Mailer;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
@@ -13,8 +14,9 @@ class HomeController extends AbstractController
{
#[Route(path: '/',name: 'app_login',methods: ['GET', 'POST'])]
public function index(AuthenticationUtils $authenticationUtils): Response
public function index(Mailer $mailer,AuthenticationUtils $authenticationUtils): Response
{
$mailer->sendTest();
if ($this->getUser()) {
return $this->redirectToRoute('artemis_dashboard');
}

View File

@@ -2,9 +2,12 @@
namespace App\Service\Mailer;
use Exception;
use Symfony\Component\Mailer\Transport\Smtp\EsmtpTransport;
use Symfony\Component\Mime\Address;
use Symfony\Component\Mime\Email;
use Symfony\Component\Process\Exception\ProcessFailedException;
use Symfony\Component\Process\Process;
use Twig\Environment;
class Mailer
@@ -14,7 +17,7 @@ class Mailer
public function __construct(private readonly Environment $environment)
{
if ($_ENV['APP_ENV'] =="dev") {
if ($_ENV['REAL_MAIL'] =="0") {
$transport = new EsmtpTransport("mailhog", "1025", false);
} else {
$transport = new EsmtpTransport("mail.esy-web.dev", "465", true);
@@ -24,6 +27,49 @@ class Mailer
$this->mailer = new \Symfony\Component\Mailer\Mailer($transport);
}
private function convertMjmlToHtml(string $mjmlContent): string
{
$command = ['mjml', '--stdin'];
$process = new Process($command);
try {
$process->setInput($mjmlContent);
$process->run();
// Exécute la commande et vérifie la réussite
if (!$process->isSuccessful()) {
throw new ProcessFailedException($process);
}
return $process->getOutput();
} catch (ProcessFailedException $exception) {
return ''; // Retourne une chaîne vide en cas d'échec
} catch (Exception $e) {
return '';
}
}
public function sendTest()
{
$mjmlGenerator = $this->environment->render('mails/test.twig',[
'system' => [
'subject' => 'Test de configuration',
]
]);
$htmlContent = $this->convertMjmlToHtml($mjmlGenerator);
$dest = new Address("jovann@siteonseil.fr", "Serreau Jovann");
$src = new Address("mainframe@esy-web.dev", "Mainframe EsyWeb");
$mail = new Email();
$mail->subject("Test de configuration");
$mail->to($dest);
$mail->from($src);
$mail->generateMessageId();
$mail->html($htmlContent);
$this->mailer->send($mail);
}
public function send(string $address, string $addressName, string $subject, string $template, array $data)
{
$dest = new Address($address, $addressName);
@@ -35,7 +81,7 @@ class Mailer
$mail->generateMessageId();
$mail->html($this->environment->render($template, array_merge([
'system' => [
'subject' => $subject,
]
], $data)));
$this->mailer->send($mail);

67
templates/mails/base.twig Normal file
View File

@@ -0,0 +1,67 @@
{# base.twig - Modèle d'e-mail MJML #}
<mjml>
<mj-head>
<mj-title>{{ system.subject }}</mj-title>
<mj-attributes>
<mj-all font-family="Inter, Helvetica, Arial, sans-serif"></mj-all>
<mj-text font-size="16px" line-height="24px" color="#333333"></mj-text>
<mj-button background-color="#4A90E2" color="#ffffff" border-radius="4px" font-size="16px" padding="10px 25px"></mj-button>
</mj-attributes>
<mj-style inline="inline">
.link-style {
color: #4A90E2;
text-decoration: none;
}
.footer-text {
font-size: 12px;
color: #888888;
}
</mj-style>
</mj-head>
<mj-body background-color="#F2F2F2">
{# Section d'en-tête #}
<mj-section background-color="#ffffff" padding-bottom="0px">
<mj-column>
{# Logo mis à jour pour SARL SITECONSEIL #}
<mj-image src="{{ absolute_url('assets/logo_siteconseil.png') }}" alt="Logo SARL SITECONSEIL" align="center" width="150px" padding-bottom="20px"></mj-image>
</mj-column>
</mj-section>
{# Section de contenu #}
<mj-section background-color="#ffffff" padding-top="0px" padding-bottom="0px">
{# Titre dynamique ajouté avant le bloc de contenu, directement dans la section #}
<mj-text font-size="20px" font-weight="bold" align="center" padding-bottom="20px">{{ system.subject }}</mj-text>
<mj-column width="100%">
{% block content %}
{% endblock %}
</mj-column>
</mj-section>
{# Section d'espacement #}
<mj-section background-color="#ffffff" padding-top="0px" padding-bottom="20px">
<mj-column>
<mj-spacer height="20px"></mj-spacer>
</mj-column>
</mj-section>
{# Section de pied de page #}
<mj-section background-color="#F2F2F2" padding-top="20px" padding-bottom="20px">
<mj-column>
<mj-text align="center" css-class="footer-text">
&copy; {{ "now"|date("Y") }} SARL SITECONSEIL. Tous droits réservés.
</mj-text>
{# Adresse et contact de l'entreprise mis à jour pour SARL SITECONSEIL #}
<mj-text align="center" css-class="footer-text" padding-top="10px">
SARL SITECONSEIL, 27 Rue Le Serurier, 02100 Saint-Quentin, France
<br/>
Téléphone : 03 23 62 73 60
</mj-text>
<mj-social font-size="15px" icon-size="24px" mode="horizontal" padding-top="10px">
<mj-social-element name="facebook" href="#" background-color="#3B5998"></mj-social-element>
<mj-social-element name="linkedin" href="#" background-color="#0077B5"></mj-social-element>
</mj-social>
</mj-column>
</mj-section>
</mj-body>
</mjml>

12
templates/mails/test.twig Normal file
View File

@@ -0,0 +1,12 @@
{% extends 'mails/base.twig' %}
{% block content %}
<mj-text font-size="16px" line-height="24px">
Bonjour,
<br/><br/>
Ceci est un e-mail de test de configuration de la part de SARL SITECONSEIL.
<br/><br/>
Si vous recevez cet e-mail, cela signifie que votre configuration d'envoi d'e-mails fonctionne correctement.
<br/><br/>
N'hésitez pas à nous contacter si vous avez des questions.
</mj-text>
{% endblock %}