src/Controller/Security/LoginController.php line 24

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Security;
  3. use App\Form\SubscribeFormType;
  4. use App\Service\Generale;
  5. use App\Service\WSCMS;
  6. use Doctrine\ORM\EntityManagerInterface;
  7. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  8. use Symfony\Component\HttpFoundation\Response;
  9. use Symfony\Component\Routing\Annotation\Route;
  10. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  11. class LoginController extends AbstractController
  12. {
  13.     public function __construct(Generale $service)
  14.     {
  15.         $this->service = $service;
  16.     }
  17.     /**
  18.      * @Route("/login", name="app_login")
  19.      */
  20.     public function index(AuthenticationUtils $authenticationUtils, EntityManagerInterface $em, WSCMS $WSCMS): Response
  21.     {
  22.         $error = $authenticationUtils->getLastAuthenticationError();
  23.         $lastUsername = $authenticationUtils->getLastUsername();
  24.         if ($error) {
  25.             $stmt = $em->getConnection()->prepare("delete from user where username='$lastUsername'");
  26.             $stmt->execute();
  27.             $this->addFlash('danger', $error->getMessage());
  28.         }
  29.         if (isset($_GET['http_referer']))
  30.             return $this->redirect($_GET['http_referer']);
  31.         if (isset($_SERVER['APP_MODAL_LOGIN_REGISTER']))
  32.             return $this->redirectToRoute('accueil', ['mdl' => 'login']);
  33.         $pays = array_column($WSCMS->Pays()['Pays'], 'id', 'name');
  34.         $_pays = array_column($WSCMS->Pays()['Pays'], 'id', 'code');
  35.         $agence = $WSCMS->Agence()['Agence'];
  36.         $form = $this->get('form.factory')->createNamed('', SubscribeFormType::class, null, [
  37.             'pays' => $pays,
  38.             'nationalite' => $_pays[$agence['nationalite']],
  39.             'csrf_protection' => true
  40.         ]);
  41.         $b2b = '';
  42.         if (in_array($_SERVER['APP_ACCESS_CONTROL'],['ROLE_CLIENT_B2B','ROLE_CLIENT_B2B_OR_AMICALE']) or
  43.             in_array($_SERVER['APP_SECOND_ACCESS_CONTROL'],['ROLE_CLIENT_B2B','ROLE_CLIENT_B2B_OR_AMICALE']))
  44.             $b2b = '-b2b';
  45.         return $this->render(
  46.             $this->service->checkCustomTemplate(
  47.                 "login/index$b2b.html.twig",
  48.                 "login/index$b2b.html.twig"),
  49.             [
  50.                 'last_username' => $lastUsername,
  51.                 'form' => $form->createView()
  52.             ]
  53.         );
  54.     }
  55. }