src/Controller/Public/SecurityController.php line 15

  1. <?php
  2. namespace App\Controller\Public;
  3. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  4. use Symfony\Component\HttpFoundation\Request;
  5. use Symfony\Component\HttpFoundation\Response;
  6. use Symfony\Component\Routing\Annotation\Route;
  7. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  8. use Symfony\UX\Turbo\TurboBundle;
  9. class SecurityController extends AbstractController
  10. {
  11.     #[Route('/'name'login')]
  12.     public function index(AuthenticationUtils $authenticationUtilsRequest $request): Response
  13.     {
  14.         if ($this->isGranted('ROLE_ADMIN')) {
  15.             return $this->redirectToRoute('app_admin_dashboard_index');
  16.         } elseif ($this->isGranted('ROLE_CLIENT')) {
  17.             return $this->redirectToRoute('app_client_dashboard');
  18.         } elseif ($this->isGranted('ROLE_USER') && $this->getUser()->isVerified() === false) {
  19.             return $this->redirectToRoute('app_public_unverified_user');
  20.         } elseif ($this->isGranted('ROLE_USER') && $this->getUser()->isVerified() === true) {
  21.             return $this->redirectToRoute('app_public_awaiting_validation_user');
  22.         }
  23.         $error $authenticationUtils->getLastAuthenticationError();
  24.         $lastUsername $authenticationUtils->getLastUsername();
  25.         if (TurboBundle::STREAM_FORMAT === $request->getPreferredFormat() && $request->getRealMethod() === Request::METHOD_POST) {
  26.             $request->setRequestFormat(TurboBundle::STREAM_FORMAT);
  27.             return $this->renderForm('security/login.stream.html.twig', [
  28.                 'last_username' => $lastUsername,
  29.                 'error' => $error,
  30.             ]);
  31.         }
  32.         return $this->renderForm('security/login.html.twig', [
  33.             'last_username' => $lastUsername,
  34.             'error' => $error,
  35.         ]);
  36.     }
  37.     #[Route('/logout'name'logout'methods: ['GET'])]
  38.     public function logout()
  39.     {
  40.         // controller can be blank: it will never be called!
  41.         throw new \Exception('Don\'t forget to activate logout in security.yaml');
  42.     }
  43. }