src/Controller/Front/SecurityController.php line 81

Open in your IDE?
  1. <?php
  2. /*
  3.  * Unauthorized copying of this file, via any medium is strictly prohibited
  4.  * Proprietary and confidential.
  5.  *
  6.  * @author Bilel AZRI          <azri.bilel@gmail.com>
  7.  * @author Assma BEN SASSI     <bensassiasma.bws@gmail.com>
  8.  *
  9.  * Bicking man (c) 2019-present.
  10.  */
  11. declare(strict_types=1);
  12. namespace App\Controller\Front;
  13. use Symfony\Component\HttpFoundation\RedirectResponse;
  14. use Symfony\Component\HttpFoundation\Response;
  15. use Symfony\Component\Routing\Annotation\Route;
  16. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  17. use Symfony\Component\Security\Core\Security;
  18. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  19. use Symfony\Contracts\Translation\TranslatorInterface;
  20. use Twig\Environment;
  21. /**
  22.  * @Route("/", name="security.")
  23.  */
  24. final class SecurityController
  25. {
  26.     /**
  27.      * @var UrlGeneratorInterface
  28.      */
  29.     private $urlGenerator;
  30.     /**
  31.      * @var Security
  32.      */
  33.     private $security;
  34.     /**
  35.      * @var Environment
  36.      */
  37.     private $twig;
  38.     /**
  39.      * @var AuthenticationUtils
  40.      */
  41.     private $authenticationUtils;
  42.     private TranslatorInterface $translator;
  43.     public function __construct(UrlGeneratorInterface $urlGeneratorTranslatorInterface $translatorSecurity $securityEnvironment $twigAuthenticationUtils $authenticationUtils)
  44.     {
  45.         $this->urlGenerator $urlGenerator;
  46.         $this->security $security;
  47.         $this->twig $twig;
  48.         $this->authenticationUtils $authenticationUtils;
  49.         $this->translator $translator;
  50.     }
  51.     /**
  52.      * @Route("/",
  53.      *     name="app_login",
  54.      *     options={"expose": true}
  55.      * )
  56.      */
  57.     public function login(): Response
  58.     {
  59.         if (null !== $this->security->getUser()) {
  60.             return new RedirectResponse($this->urlGenerator->generate('front.course.index'));
  61.         }
  62.         //$this->translator->setLocale('fr');
  63.         // get the login error if there is one
  64.         $error $this->authenticationUtils->getLastAuthenticationError();
  65.         // last username entered by the user
  66.         $lastUsername $this->authenticationUtils->getLastUsername();
  67.         return new Response($this->twig->render('front/security/login.html.twig', ['last_username' => $lastUsername'error' => $error]));
  68.     }
  69.     /**
  70.      * @Route("/logout", name="logout")
  71.      */
  72.     public function logout(): void
  73.     {
  74.         // This method can be blank - it will be intercepted by the logout key on your firewall
  75.     }
  76. }