<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
/**
* classe qui gere la vue sur l'autenthication des utilisateurs.
*/
class SecurityController extends AbstractController
{
/**
* @param AuthenticationUtils $authenticationUtils l'utilitaire d'authentification
* @return Response Soit une redirection si l'utilisateur est deja loggé, soit la page de login
*/
#[Route(path: '/login', name: 'app_login')]
public function login(AuthenticationUtils $authenticationUtils): Response
{
if ($this->getUser() !== null) {
switch($this->getUser()->getRoles()[0]){
case 'ROLE_ADMIN':
return $this->redirectToRoute('admin');
case 'ROLE_CUSTOMER':
return $this->redirectToRoute('customer');
case 'ROLE_PROVIDER':
return $this->redirectToRoute('provider');
case 'ROLE_GESTIONNAIRE':
return $this->redirectToRoute('admin_exporter_home');
}
}
// get the login error if there is one
$error = $authenticationUtils->getLastAuthenticationError();
// last username entered by the user
$lastUsername = $authenticationUtils->getLastUsername();
return $this->render('security/login.html.twig', ['last_username' => $lastUsername, 'error' => $error]);
}
#[Route(path: '/logout', name: 'app_logout')]
public function logout()
{
throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
}
}