<?php
namespace App\Controller\Security;
use App\Form\SubscribeFormType;
use App\Service\Generale;
use App\Service\WSCMS;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
class LoginController extends AbstractController
{
public function __construct(Generale $service)
{
$this->service = $service;
}
/**
* @Route("/login", name="app_login")
*/
public function index(AuthenticationUtils $authenticationUtils, EntityManagerInterface $em, WSCMS $WSCMS): Response
{
$error = $authenticationUtils->getLastAuthenticationError();
$lastUsername = $authenticationUtils->getLastUsername();
if ($error) {
$stmt = $em->getConnection()->prepare("delete from user where username='$lastUsername'");
$stmt->execute();
$this->addFlash('danger', $error->getMessage());
}
if (isset($_GET['http_referer']))
return $this->redirect($_GET['http_referer']);
if (isset($_SERVER['APP_MODAL_LOGIN_REGISTER']))
return $this->redirectToRoute('accueil', ['mdl' => 'login']);
$pays = array_column($WSCMS->Pays()['Pays'], 'id', 'name');
$_pays = array_column($WSCMS->Pays()['Pays'], 'id', 'code');
$agence = $WSCMS->Agence()['Agence'];
$form = $this->get('form.factory')->createNamed('', SubscribeFormType::class, null, [
'pays' => $pays,
'nationalite' => $_pays[$agence['nationalite']],
'csrf_protection' => true
]);
$b2b = '';
if (in_array($_SERVER['APP_ACCESS_CONTROL'],['ROLE_CLIENT_B2B','ROLE_CLIENT_B2B_OR_AMICALE']) or
in_array($_SERVER['APP_SECOND_ACCESS_CONTROL'],['ROLE_CLIENT_B2B','ROLE_CLIENT_B2B_OR_AMICALE']))
$b2b = '-b2b';
return $this->render(
$this->service->checkCustomTemplate(
"login/index$b2b.html.twig",
"login/index$b2b.html.twig"),
[
'last_username' => $lastUsername,
'form' => $form->createView()
]
);
}
}