<?php
namespace App\Controller;
use App\Form\ContactType;
use App\Services\MailerService;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
class PageController extends AbstractController
{
/**
* @Route("/", name="home")
*/
public function index(MailerService $mailer, Request $request): Response
{
//return $this->redirectToRoute('app_login');
if($this->getUser()){
$userRole = ($this->getUser()->getRoles()[0]);
$role = strtolower(str_replace("ROLE_", "", $userRole));
return $this->redirectToRoute("dashboard");
}
else {
$form = $this->createForm(ContactType::class);
$form->handleRequest($request);
/* Envoi d'un message de contact */
if ($form->isSubmitted() && $form->isValid()) {
$to = ['contact@lotica.fr'];
$data = $form->getData();
$params = [
'data' => $data,
];
$mailer->send("Nouveau message", $to, "contactform_email", $params);
$this->addFlash( 'success', 'Message envoyé. Nous vous répondrons le plus vite possible');
return $this->redirectToRoute('home',['_fragment' => 'contact']);
}
return $this->render('page/index.html.twig', [
'current' => 'home',
'form' => $form->createView(),
]);
}
}
/**
* @Route("/a-propos", name="about")
*/
public function about(): Response
{
$user = $this->getUser() ? $this->getUser() : null;
return $this->render('page/about.html.twig', [
'current' => 'about',
]);
}
/**
* @Route("/services", name="services")
*/
public function services(): Response
{
$user = $this->getUser() ? $this->getUser() : null;
return $this->render('page/services.html.twig', [
'current' => 'services',
]);
}
/**
* @Route("/avantages", name="avantages")
*/
public function avantages(): Response
{
$user = $this->getUser() ? $this->getUser() : null;
return $this->render('page/avantages.html.twig', [
'current' => 'avantages',
]);
}
/**
* @Route("/temoignages", name="testimonials")
*/
public function testimonials(): Response
{
$user = $this->getUser() ? $this->getUser() : null;
return $this->render('page/testimonials.html.twig', [
'current' => 'testimonials',
]);
}
/**
* @Route("/contact", name="contact")
*/
public function contact(): Response
{
$user = $this->getUser() ? $this->getUser() : null;
return $this->render('page/contact.html.twig', [
'current' => 'contact',
]);
}
/**
* @Route("/cgv", name="cgv")
*/
public function cgv(): Response
{
$user = $this->getUser() ? $this->getUser() : null;
return $this->render('page/cgv.html.twig', [
'current' => 'cgv',
]);
}
/**
* @Route("/cgu", name="cgu")
*/
public function cgu(): Response
{
$user = $this->getUser() ? $this->getUser() : null;
return $this->render('page/cgu.html.twig', [
'current' => 'cgu',
]);
}
}