src/Controller/SecurityController.php line 16

  1. <?php
  2. namespace App\Controller;
  3. use App\Service\HostResolver;
  4. use GroupIN\ConfigBundle\Service\Config;
  5. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  6. use Symfony\Component\HttpFoundation\Response;
  7. use Symfony\Component\HttpKernel\KernelInterface;
  8. use Symfony\Component\Routing\Annotation\Route;
  9. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  10. class SecurityController extends AbstractController
  11. {
  12.     #[Route(path'/login'name'app_login')]
  13.     public function login(
  14.         HostResolver $hostResolver,
  15.         AuthenticationUtils $authenticationUtils,
  16.     ): Response
  17.     {
  18.         $establishmentManager $hostResolver->getEstablishmentManager();
  19.         /*if ($establishmentManager->getConnected() === null || $hostResolver->siteActif()) {
  20.             return  $this->redirect($kernel->getEnvironment() == 'prod' ? "{$config->getUrlSite()}/login"  : 'https://127.0.0.1:8000/login');
  21.         }*/
  22.         if ($this->getUser()) {
  23.             return $this->redirectToRoute('app');
  24.         }
  25.         // get the login error if there is one
  26.         $error $authenticationUtils->getLastAuthenticationError();
  27.         // last username entered by the user
  28.         $lastUsername $authenticationUtils->getLastUsername();
  29.         return $this->render('security/login.html.twig', [
  30.             'last_username' => $lastUsername,
  31.             'error' => $error,
  32.             'establishment' => $hostResolver->getEstablishmentManager()->getConnected()
  33.         ]);
  34.     }
  35.     #[Route(path'/logout'name'app_logout')]
  36.     public function logout(): void
  37.     {
  38.         throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
  39.     }
  40. }