src/Controller/SecurityController.php line 38

  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Component\HttpFoundation\Request;
  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'/login'name'app_login')]
  11.     public function login(AuthenticationUtils $authenticationUtilsRequest $request): Response
  12.     {
  13.         if ($this->getUser()) {
  14.             $host $request->getHost();
  15.             if ($host === 'surmurthag.eu') {
  16.                 // Redirection vers la route nommée 'app_store'
  17.                 return $this->redirectToRoute('app_store');
  18.             } elseif ($host === 'surmurthag.com') {
  19.                 // Redirection vers la route nommée 'app_portfolio'
  20.                 return $this->redirectToRoute('app_portfolio');
  21.             }
  22.         }
  23.         // get the login error if there is one
  24.         $error $authenticationUtils->getLastAuthenticationError();
  25.         // last username entered by the user
  26.         $lastUsername $authenticationUtils->getLastUsername();
  27.         return $this->render('security/login.html.twig', ['last_username' => $lastUsername'error' => $error]);
  28.     }
  29.     #[Route(path'/logout'name'app_logout')]
  30.     public function logout(): void
  31.     {
  32.         throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
  33.     }
  34. }