343 lines
13 KiB
PHP
343 lines
13 KiB
PHP
<?php
|
|
|
|
namespace App\Controller;
|
|
|
|
use App\Entity\Account;
|
|
use App\Entity\AccountResetPasswordRequest;
|
|
use App\Entity\Customer;
|
|
use App\Entity\Product;
|
|
use App\Form\RequestPasswordConfirmType;
|
|
use App\Form\RequestPasswordRequestType;
|
|
use App\Logger\AppLogger;
|
|
use App\Repository\CustomerRepository;
|
|
use App\Repository\ProductRepository;
|
|
use App\Service\Mailer\Mailer;
|
|
use App\Service\ResetPassword\Event\ResetPasswordConfirmEvent;
|
|
use App\Service\ResetPassword\Event\ResetPasswordEvent;
|
|
use App\Service\Search\Client;
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
use Fkrzski\RobotsTxt\RobotsTxt;
|
|
use KnpU\OAuth2ClientBundle\Client\ClientRegistry;
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
|
use Symfony\Component\Form\Extension\Core\Type\EmailType;
|
|
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
|
|
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
use Symfony\Component\Mailer\MailerInterface;
|
|
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
|
|
use Symfony\Component\Routing\Attribute\Route;
|
|
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
|
|
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
|
use Vich\UploaderBundle\Templating\Helper\UploaderHelper;
|
|
use Vich\UploaderBundle\Templating\Helper\UploaderHelperInterface;
|
|
|
|
|
|
class ReserverController extends AbstractController
|
|
{
|
|
|
|
#[Route('/robots.txt', name: 'robots_txt', defaults: ['_format' => 'txt'])]
|
|
public function index(Request $request): Response
|
|
{
|
|
$robots = new RobotsTxt();
|
|
$robots->disallow('/signature');
|
|
$robots->disallow('/payment');
|
|
$robots->crawlDelay(60);
|
|
$robots->allow('/reservation');
|
|
$robots->sitemap($request->getSchemeAndHttpHost().'/seo/sitemap.xml');
|
|
|
|
return new Response($robots->toString(),Response::HTTP_OK,[
|
|
'Content-Type' => 'text/plain'
|
|
]);
|
|
}
|
|
#[Route('/reservation', name: 'reservation')]
|
|
public function revervation(ProductRepository $productRepository): Response
|
|
{
|
|
$products =$productRepository->findBy([], ['updatedAt' => 'DESC'],3);
|
|
return $this->render('revervation/home.twig',[
|
|
'products' => $products
|
|
]);
|
|
}
|
|
#[Route('/reservation/catalogue', name: 'reservation_catalogue')]
|
|
public function revervationCatalogue(ProductRepository $productRepository): Response
|
|
{
|
|
|
|
return $this->render('revervation/catalogue.twig',[
|
|
'products' => $productRepository->findAll(),
|
|
]);
|
|
}
|
|
#[Route('/reservation/comment-reserver', name: 'reservation_workflow')]
|
|
public function revervationWorkfkow(): Response
|
|
{
|
|
|
|
return $this->render('revervation/workflow.twig',[
|
|
|
|
]);
|
|
}
|
|
|
|
#[Route('/reservation/options/{id}', name: 'reservation_options_show')]
|
|
public function revervationShowOpitons(string $id, ProductRepository $productRepository): Response
|
|
{
|
|
|
|
}
|
|
|
|
#[Route('/reservation/produit/{id}', name: 'reservation_product_show')]
|
|
public function revervationShowProduct(string $id, ProductRepository $productRepository): Response
|
|
{
|
|
// 1. Extraction de l'ID (ex: "15-chateau-fort" -> 15)
|
|
$parts = explode('-', $id);
|
|
$realId = $parts[0]; // Récupère le tout premier élément (l'index 0)
|
|
|
|
// 2. Récupération du produit par son ID numérique
|
|
$product = $productRepository->find($realId);
|
|
|
|
if (!$product) {
|
|
throw $this->createNotFoundException('Produit introuvable');
|
|
}
|
|
|
|
// 3. Logique des suggestions (inchangée)
|
|
$allInCat = $productRepository->findBy(['category' => $product->getCategory()], [], 5);
|
|
|
|
$otherProducts = array_filter($allInCat, function($p) use ($product) {
|
|
return $p->getId() !== $product->getId();
|
|
});
|
|
|
|
return $this->render('revervation/produit.twig', [
|
|
'product' => $product,
|
|
'otherProducts' => array_slice($otherProducts, 0, 4)
|
|
]);
|
|
}
|
|
#[Route('/reservation/connexion', name: 'reservation_login')]
|
|
public function revervationLogin(AuthenticationUtils $authenticationUtils): Response
|
|
{
|
|
return $this->render('revervation/login.twig',[
|
|
'last_username' => $authenticationUtils->getLastUsername(),
|
|
'error' => $authenticationUtils->getLastAuthenticationError()
|
|
|
|
]);
|
|
}
|
|
#[Route('/reservation/logout', name: 'reservation_logout')]
|
|
public function revervationLogout(): Response
|
|
{
|
|
return $this->redirectToRoute('reservation');
|
|
}
|
|
#[Route('/reservation/creation-compte', name: 'reservation_register')]
|
|
public function revervationRegister(
|
|
Request $request,
|
|
Mailer $mailer,
|
|
EntityManagerInterface $em,
|
|
UserPasswordHasherInterface $hasher
|
|
): Response {
|
|
if ($request->isMethod('POST')) {
|
|
$payload = $request->getPayload();
|
|
|
|
$customer = new Customer();
|
|
$customer->setEmail($payload->getString('email'));
|
|
$customer->setName($payload->getString('name'));
|
|
$customer->setSurname($payload->getString('surname'));
|
|
$customer->setPhone($payload->getString('phone'));
|
|
$customer->setCiv($payload->getString('civ'));
|
|
$customer->setType($payload->getString('type')); // 'particular' ou 'buisness'
|
|
|
|
if ($customer->getType() === 'buisness') {
|
|
$customer->setSiret($payload->getString('siret'));
|
|
}
|
|
|
|
// Hachage du mot de passe
|
|
$hashedPassword = $hasher->hashPassword($customer, $payload->getString('password'));
|
|
$customer->setPassword($hashedPassword);
|
|
$customer->setRoles(['ROLE_USER']);
|
|
$mailer->send($customer->getEmail(),
|
|
$customer->getName()." ".$customer->getSurname(),
|
|
"[Ludikevent] - Code de récupération",
|
|
"mails/welcome.twig",[
|
|
'account' => $customer,
|
|
]);
|
|
$em->persist($customer);
|
|
$em->flush();
|
|
|
|
$this->addFlash('success', 'Votre compte a été créé avec succès ! Connectez-vous.');
|
|
return $this->redirectToRoute('reservation_login');
|
|
}
|
|
|
|
return $this->render('revervation/register.twig');
|
|
}
|
|
#[Route('/reservation/mot-de-passe', name: 'reservation_password')]
|
|
public function forgotPassword(
|
|
Request $request,
|
|
CustomerRepository $repository,
|
|
EntityManagerInterface $em,
|
|
Mailer $mailer,
|
|
UserPasswordHasherInterface $hasher
|
|
): Response {
|
|
$session = $request->getSession();
|
|
$step = $request->query->get('step', 'request');
|
|
|
|
if ($request->isMethod('POST')) {
|
|
$payload = $request->getPayload();
|
|
|
|
// ÉTAPE 1 : Générer le code et l'envoyer
|
|
if ($payload->has('email_request')) {
|
|
$email = $payload->getString('email_request');
|
|
$customer = $repository->findOneBy(['email' => $email]);
|
|
|
|
if ($customer) {
|
|
$code = str_pad((string)random_int(0, 999999), 6, '0', STR_PAD_LEFT);
|
|
|
|
// On stocke en session : email + code
|
|
$session->set('reset_password', [
|
|
'email' => $email,
|
|
'code' => $code,
|
|
'expires' => time() + 900 // Valable 15 minutes
|
|
]);
|
|
|
|
$mailer->send($customer->getEmail(),
|
|
$customer->getName()." ".$customer->getSurname(),
|
|
"[Ludikevent] - Code de récupération",
|
|
"mails/code_password.twig",[
|
|
'code' => $code
|
|
]);
|
|
|
|
return $this->redirectToRoute('reservation_password', ['step' => 'verify']);
|
|
}
|
|
$this->addFlash('danger', 'Email inconnu.');
|
|
}
|
|
|
|
// ÉTAPE 2 : Vérifier le code en session
|
|
if ($payload->has('code_verify')) {
|
|
$data = $session->get('reset_password');
|
|
$inputCode = $payload->getString('code_verify');
|
|
|
|
if ($data && $data['code'] === $inputCode && time() < $data['expires']) {
|
|
return $this->redirectToRoute('reservation_password', ['step' => 'reset']);
|
|
}
|
|
$this->addFlash('danger', 'Code invalide ou expiré.');
|
|
}
|
|
|
|
// ÉTAPE 3 : Changer le mot de passe
|
|
if ($payload->has('new_password')) {
|
|
$data = $session->get('reset_password');
|
|
|
|
if ($data) {
|
|
$customer = $repository->findOneBy(['email' => $data['email']]);
|
|
if ($customer) {
|
|
$newEncoded = $hasher->hashPassword($customer, $payload->getString('new_password'));
|
|
$customer->setPassword($newEncoded);
|
|
$em->flush();
|
|
|
|
$session->remove('reset_password'); // On nettoie la session
|
|
$this->addFlash('success', 'Mot de passe mis à jour !');
|
|
return $this->redirectToRoute('reservation_login');
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return $this->render('reservation/password.twig', [
|
|
'step' => $step,
|
|
'email' => $session->get('reset_password')['email'] ?? null
|
|
]);
|
|
}
|
|
#[Route('/reservation/contact', name: 'reservation_contact')]
|
|
public function revervationContact(Request $request, Mailer $mailer): Response
|
|
{
|
|
$form = $this->createFormBuilder()
|
|
->add('name', TextType::class, [
|
|
'label' => 'Nom',
|
|
'required' => true,
|
|
])
|
|
->add('surname', TextType::class, [
|
|
'label' => 'Prenom',
|
|
'required' => true,
|
|
])
|
|
->add('email', EmailType::class, [
|
|
'label' => 'Email',
|
|
'required' => true,
|
|
])
|
|
->add('phone', TextType::class, [
|
|
'label' => 'Telephone',
|
|
'required' => true,
|
|
])
|
|
->add('message', TextareaType::class, [
|
|
'label' => 'Message',
|
|
'required' => true,
|
|
]);
|
|
|
|
$formObject = $form->getForm();
|
|
$formObject->handleRequest($request);
|
|
|
|
if ($formObject->isSubmitted() && $formObject->isValid()) {
|
|
$data = $formObject->getData();
|
|
|
|
$mailer->send(
|
|
'lilian@ludikevent.fr',
|
|
"Ludikevent",
|
|
"[Ludikevent] - Demande de contact via la plateforme de reservation",
|
|
"mails/reserve/contact.twig",
|
|
$data
|
|
);
|
|
|
|
// Ajout du message flash de succès
|
|
$this->addFlash('success', 'Votre message a bien été envoyé ! Notre équipe vous répondra dans les plus brefs délais.');
|
|
|
|
return $this->redirectToRoute('reservation_contact');
|
|
}
|
|
|
|
return $this->render('revervation/contact.twig', [
|
|
'form' => $formObject->createView()
|
|
]);
|
|
}
|
|
#[Route('/reservation/recherche', name: 'reservation_search')]
|
|
public function recherche(UploaderHelper $uploaderHelper,Client $client,Request $request,ProductRepository $productRepository): Response
|
|
{
|
|
$results = $client->search('product',$request->query->get('q',''));
|
|
$items = [];
|
|
foreach ($results['hits'] as $result) {
|
|
$p = $productRepository->find($result['id']);
|
|
if($p instanceof Product) {
|
|
$items[] = [
|
|
'image' => $uploaderHelper->asset($p, 'imageFile') ?: "/provider/images/favicon.png",
|
|
"name" => $p->getName(),
|
|
"price" => $p->getPriceDay(),
|
|
"price1day" => $p->getPriceDay(),
|
|
"caution" => $p->getCaution(),
|
|
"priceSup" => $p->getPriceSup(),
|
|
'link' => $this->generateUrl('reservation_product_show',['id'=>$p->slug()]),
|
|
];
|
|
|
|
}
|
|
}
|
|
return $this->render('revervation/search.twig',[
|
|
'products' => $items
|
|
]);
|
|
}
|
|
|
|
#[Route('/reservation/mentions-legales', name: 'reservation_mentions-legal')]
|
|
public function revervationLegal()
|
|
{
|
|
return $this->render('revervation/legal.twig');
|
|
}
|
|
#[Route('/reservation/rgpd', name: 'reservation_rgpd')]
|
|
public function revervationRgpd()
|
|
{
|
|
return $this->render('revervation/rgpd.twig');
|
|
}
|
|
#[Route('/reservation/cookies', name: 'reservation_cookies')]
|
|
public function revervationCookies()
|
|
{
|
|
return $this->render('revervation/cookies.twig');
|
|
}
|
|
#[Route('/reservation/cgv', name: 'reservation_cgv')]
|
|
public function revervationCgv()
|
|
{
|
|
return $this->render('revervation/cgv.twig');
|
|
}
|
|
#[Route('/reservation/hosting', name: 'reservation_hosting')]
|
|
public function revervationHosting()
|
|
{
|
|
return $this->render('revervation/hosting.twig');
|
|
}
|
|
}
|