src/Controller/SecurityController.php line 24

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Services\SessionService;
  4. use Exception;
  5. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  6. use Symfony\Component\HttpFoundation\Request;
  7. use Symfony\Component\HttpFoundation\Response;
  8. use Symfony\Component\Routing\Annotation\Route;
  9. use Symfony\Contracts\Translation\TranslatorInterface;
  10. use Twig\Environment;
  11. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  12. class SecurityController extends AbstractController
  13. {
  14.     private SessionService $sessionService;
  15.     public function __construct(SessionService $sessionService)
  16.     {
  17.         $this->sessionService $sessionService;
  18.     }
  19.     #[Route('/login'name'app_login'methods: ["GET""POST"])]
  20.     public function index(AuthenticationUtils $authenticationUtils,TranslatorInterface $translator): Response
  21.     {
  22.         $data $this->sessionService->_getBaseParameters();
  23.         if ($data["elligible"]) {
  24.             return $this->redirectToRoute('home');
  25.         }
  26.         if ($data["code"]) {
  27.             return $this->redirectToRoute('verify');
  28.         }
  29.         $data["error"] = $authenticationUtils->getLastAuthenticationError();
  30.         $data["last_username"] = $authenticationUtils->getLastUsername();
  31.         $data['title'] = $translator->trans('pages.login.title');
  32.         return $this->render('Security/login.twig'$data);
  33.     }
  34.     /**
  35.      * @Route("/logout", name="app_logout", methods={"GET"})
  36.      */
  37.     public function logout(): void
  38.     {
  39.         // controller can be blank: it will never be called!
  40.         throw new Exception('Don\'t forget to activate logout in security.yaml');
  41.     }
  42. }