Réparation du DashboardController et AuthenticationController

This commit is contained in:
sermandm 2025-05-08 13:58:02 +02:00
parent 8580911c1a
commit a992c2ea6a
2 changed files with 16 additions and 9 deletions

View File

@ -3,27 +3,31 @@
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
class AuthenticationController extends AbstractController
{
#[Route(path: '/login', name: 'app_login')]
#[Route(path: '/', name: 'app_login')]
public function login(AuthenticationUtils $authenticationUtils): Response
{
// get the login error if there is one
if ($this->getUser()) {
return $this->redirectToRoute('dashboard');
}
$error = $authenticationUtils->getLastAuthenticationError();
// last username entered by the user
$lastUsername = $authenticationUtils->getLastUsername();
return $this->render('authentication/login.html.twig', ['last_username' => $lastUsername, 'error' => $error]);
return $this->render('login/index.html.twig', [
'last_username' => $lastUsername,
'error' => $error,
]);
}
#[Route(path: '/logout', name: 'app_logout')]
public function logout(): void
{
throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
throw new \LogicException('Cette méthode est interceptée par Symfony pour déconnecter.');
}
}

View File

@ -10,18 +10,21 @@ use Symfony\Component\Routing\Annotation\Route;
class DashboardController extends AbstractController
{
#[Route('/', name: 'dashboard')]
#[Route('/admin', name: 'admin_dashboard')]
#[Route('/secretaire', name: 'secretaire_dashboard')]
#[Route('/chauffagiste', name: 'chauffagiste_dashboard')]
public function index(): Response
{
if ($this->isGranted('ROLE_ADMIN')) {
return $this->render('admin.html.twig');
return $this->render('dashboard/admin.html.twig');
}
if ($this->isGranted('ROLE_SECRETAIRE')) {
return $this->render('secretaire.html.twig');
return $this->render('dashboard/secretaire.html.twig');
}
if ($this->isGranted('ROLE_CHAUFFAGISTE')) {
return $this->render('chauffagiste.html.twig');
return $this->render('dashboard/chauffagiste.html.twig');
}
throw $this->createAccessDeniedException('Vous ne pouvez pas accéder à ce tableau de bord.');