2026-01-29 17:32:03 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Controller;
|
|
|
|
|
|
|
|
|
|
use App\Entity\Account;
|
2026-02-06 11:43:31 +01:00
|
|
|
use App\Entity\Prestaire;
|
|
|
|
|
use App\Form\PrestairePasswordType;
|
2026-01-29 17:32:03 +01:00
|
|
|
use App\Repository\ContratsRepository;
|
|
|
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
|
|
|
|
use Symfony\Component\HttpFoundation\RedirectResponse;
|
|
|
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
|
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
|
|
|
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
|
|
|
|
|
use Symfony\Component\Routing\Attribute\Route;
|
|
|
|
|
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
|
2026-02-06 11:43:31 +01:00
|
|
|
use KnpU\OAuth2ClientBundle\Client\ClientRegistry;
|
2026-01-29 17:32:03 +01:00
|
|
|
|
|
|
|
|
class EtlController extends AbstractController
|
|
|
|
|
{
|
|
|
|
|
#[Route('/etl', name: 'etl_home')]
|
2026-02-06 11:43:31 +01:00
|
|
|
public function eltHome(ContratsRepository $contratsRepository): Response
|
2026-01-29 17:32:03 +01:00
|
|
|
{
|
2026-02-06 11:43:31 +01:00
|
|
|
$user = $this->getUser();
|
|
|
|
|
if (!$user) {
|
2026-01-29 17:32:03 +01:00
|
|
|
return $this->redirectToRoute('etl_login');
|
2026-02-06 11:43:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$missions = [];
|
|
|
|
|
$states = ['ready', 'progress'];
|
|
|
|
|
|
|
|
|
|
if ($user instanceof Account) {
|
|
|
|
|
// Admins see all active missions
|
|
|
|
|
$missions = $contratsRepository->findBy(['reservationState' => $states], ['dateAt' => 'ASC']);
|
|
|
|
|
} elseif ($user instanceof Prestaire) {
|
|
|
|
|
// Providers see only their missions
|
|
|
|
|
$missions = $contratsRepository->findBy(['reservationState' => $states, 'prestataire' => $user], ['dateAt' => 'ASC']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $this->render('etl/home.twig', [
|
|
|
|
|
'missions' => $missions
|
|
|
|
|
]);
|
2026-01-29 17:32:03 +01:00
|
|
|
}
|
2026-02-06 11:43:31 +01:00
|
|
|
|
|
|
|
|
#[Route('/etl/account', name: 'etl_account', methods: ['GET', 'POST'])]
|
|
|
|
|
public function eltAccount(
|
|
|
|
|
Request $request,
|
|
|
|
|
UserPasswordHasherInterface $passwordHasher,
|
|
|
|
|
EntityManagerInterface $entityManager
|
|
|
|
|
): Response {
|
|
|
|
|
if (!$this->getUser()) {
|
|
|
|
|
return $this->redirectToRoute('etl_login');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$user = $this->getUser();
|
|
|
|
|
$form = $this->createForm(PrestairePasswordType::class, $user);
|
|
|
|
|
$form->handleRequest($request);
|
|
|
|
|
|
|
|
|
|
if ($form->isSubmitted() && $form->isValid()) {
|
|
|
|
|
$hashedPassword = $passwordHasher->hashPassword(
|
|
|
|
|
$user,
|
|
|
|
|
$form->get('password')->getData()
|
|
|
|
|
);
|
|
|
|
|
$user->setPassword($hashedPassword);
|
|
|
|
|
|
|
|
|
|
$entityManager->flush();
|
|
|
|
|
|
|
|
|
|
$this->addFlash('success', 'Votre mot de passe a été modifié avec succès.');
|
|
|
|
|
return $this->redirectToRoute('etl_account');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $this->render('etl/account.twig', [
|
|
|
|
|
'form' => $form->createView(),
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-29 17:32:03 +01:00
|
|
|
#[Route('/etl/connexion', name: 'etl_login')]
|
|
|
|
|
public function eltLogin(AuthenticationUtils $authenticationUtils): Response
|
|
|
|
|
{
|
2026-02-06 11:43:31 +01:00
|
|
|
if ($this->getUser()) {
|
|
|
|
|
return $this->redirectToRoute('etl_home');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $this->render('etl/login.twig', [
|
2026-01-29 17:32:03 +01:00
|
|
|
'last_username' => $authenticationUtils->getLastUsername(),
|
|
|
|
|
'error' => $authenticationUtils->getLastAuthenticationError()
|
|
|
|
|
]);
|
|
|
|
|
}
|
2026-02-06 11:43:31 +01:00
|
|
|
|
|
|
|
|
#[Route('/etl/logout', name: 'elt_logout')]
|
2026-01-29 17:32:03 +01:00
|
|
|
public function eltLogout(): Response
|
|
|
|
|
{
|
2026-02-06 11:43:31 +01:00
|
|
|
// This method can be blank - it will be intercepted by the logout key on your firewall
|
|
|
|
|
return $this->redirectToRoute('etl_login');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[Route('/etl/connect/keycloak', name: 'connect_keycloak_etl_start')]
|
|
|
|
|
public function connectKeycloakEtlStart(ClientRegistry $clientRegistry): RedirectResponse
|
|
|
|
|
{
|
|
|
|
|
return $clientRegistry
|
|
|
|
|
->getClient('keycloak_etl')
|
|
|
|
|
->redirect(['openid', 'profile', 'email']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[Route('/etl/oauth/sso', name: 'connect_keycloak_etl_check')]
|
|
|
|
|
public function connectKeycloakEtlCheck(): Response
|
|
|
|
|
{
|
|
|
|
|
return new Response('Auth check', 200); // Intercepted by authenticator
|
2026-01-29 17:32:03 +01:00
|
|
|
}
|
|
|
|
|
}
|