src/Controller/SecurityController.php line 31

  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Utilisateur;
  4. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  5. use Symfony\Component\HttpFoundation\Response;
  6. use Symfony\Component\Routing\Annotation\Route;
  7. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  8. class SecurityController extends AbstractController
  9. {
  10.     #[Route(path'/'name'app_home')]
  11.     public function home(): Response
  12.     {
  13.         if ($this->getUser()) {
  14.             if (Utilisateur::ROLE_SUPERADMIN == $this->getUser()->getRole()) {
  15.                 return $this->redirectToRoute('structure_index');
  16.             } else {
  17.                 // else ADMIN LOCAL
  18.                 // every ADMIN LOCAL have structure by obligation
  19.                 $structureID $this->getUser()->getStructure()->getId();
  20.                 return $this->redirectToRoute('structure_edit', ['id' => $structureID ]);
  21.             }
  22.         } else {
  23.             return $this->redirectToRoute('app_login');
  24.         }
  25.     }
  26.     #[Route(path'/login'name'app_login')]
  27.     public function login(AuthenticationUtils $authenticationUtils): Response
  28.     {
  29.         if ($this->getUser()) {
  30.             return $this->redirectToRoute('app_home');
  31.         }
  32.         // get the login error if there is one
  33.         $error $authenticationUtils->getLastAuthenticationError();
  34.         // last username entered by the user
  35.         $lastUsername $authenticationUtils->getLastUsername();
  36.         return $this->render('security/login.html.twig', ['last_username' => $lastUsername'error' => $error]);
  37.     }
  38.     #[Route(path'/logout'name'app_logout')]
  39.     public function logout(): void
  40.     {
  41.         throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
  42.     }
  43. }