src/Controller/SecurityController.php line 60

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use FOS\UserBundle\Controller\SecurityController as FOSSecurityController;
  4. use Symfony\Component\HttpFoundation\RequestStack;
  5. use Symfony\Component\HttpFoundation\Response;
  6. use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
  7. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  8. class SecurityController extends FOSSecurityController
  9. {
  10.     public const ADMIN_ROUTE 'admin_security_login';
  11.     public const INVOICE_PROCESSING_PROVIDER_ROUTE 'invoice_processing_provider_security_login';
  12.     protected $requestStack;
  13.     public function __construct(
  14.         RequestStack $requestStack,
  15.         AuthenticationUtils $authenticationUtils,
  16.         ?CsrfTokenManagerInterface $tokenManager null
  17.     ) {
  18.         $this->requestStack $requestStack;
  19.         parent::__construct($authenticationUtils$tokenManager);
  20.     }
  21.     public function login(): Response
  22.     {
  23.         $request $this->requestStack->getCurrentRequest();
  24.         $data json_decode(parent::loginAction()->getContent(), true);
  25.         $data['displayedPanel'] = $request->query->get('display''actionChoice');
  26.         if (!is_null($data['error'])) {
  27.             // this is a hacky way to detect we have to display the login panel
  28.             $data['displayedPanel'] = 'login';
  29.         }
  30.         switch ($request->attributes->get('_route')) {
  31.             case self::ADMIN_ROUTE:
  32.                 $template 'admin/security/login.html.twig';
  33.                 break;
  34.             case self::INVOICE_PROCESSING_PROVIDER_ROUTE:
  35.                 $template 'invoiceProcessingProvider/security/login.html.twig';
  36.                 break;
  37.             default:
  38.                 $template 'front/security/welcome.html.twig';
  39.                 break;
  40.         }
  41.         return $this->render($template$data);
  42.     }
  43.     
  44.     protected function renderLogin(array $data): Response
  45.     {
  46.         return $this->render('front/security/welcome.html.twig'$data);
  47.     }
  48. }