<?php
namespace App\Controller;
use FOS\UserBundle\Controller\SecurityController as FOSSecurityController;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
class SecurityController extends FOSSecurityController
{
public const ADMIN_ROUTE = 'admin_security_login';
public const INVOICE_PROCESSING_PROVIDER_ROUTE = 'invoice_processing_provider_security_login';
protected $requestStack;
public function __construct(
RequestStack $requestStack,
AuthenticationUtils $authenticationUtils,
?CsrfTokenManagerInterface $tokenManager = null
) {
$this->requestStack = $requestStack;
parent::__construct($authenticationUtils, $tokenManager);
}
public function login(): Response
{
$request = $this->requestStack->getCurrentRequest();
$data = json_decode(parent::loginAction()->getContent(), true);
$data['displayedPanel'] = $request->query->get('display', 'actionChoice');
if (!is_null($data['error'])) {
// this is a hacky way to detect we have to display the login panel
$data['displayedPanel'] = 'login';
}
switch ($request->attributes->get('_route')) {
case self::ADMIN_ROUTE:
$template = 'admin/security/login.html.twig';
break;
case self::INVOICE_PROCESSING_PROVIDER_ROUTE:
$template = 'invoiceProcessingProvider/security/login.html.twig';
break;
default:
$template = 'front/security/welcome.html.twig';
break;
}
return $this->render($template, $data);
}
protected function renderLogin(array $data): Response
{
return $this->render('front/security/welcome.html.twig', $data);
}
}