<?php
/*
* Unauthorized copying of this file, via any medium is strictly prohibited
* Proprietary and confidential.
*
* @author Bilel AZRI <azri.bilel@gmail.com>
* @author Assma BEN SASSI <bensassiasma.bws@gmail.com>
*
* Bicking man (c) 2019-present.
*/
declare(strict_types=1);
namespace App\Controller\Front;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Security\Core\Security;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
use Symfony\Contracts\Translation\TranslatorInterface;
use Twig\Environment;
/**
* @Route("/", name="security.")
*/
final class SecurityController
{
/**
* @var UrlGeneratorInterface
*/
private $urlGenerator;
/**
* @var Security
*/
private $security;
/**
* @var Environment
*/
private $twig;
/**
* @var AuthenticationUtils
*/
private $authenticationUtils;
private TranslatorInterface $translator;
public function __construct(UrlGeneratorInterface $urlGenerator, TranslatorInterface $translator, Security $security, Environment $twig, AuthenticationUtils $authenticationUtils)
{
$this->urlGenerator = $urlGenerator;
$this->security = $security;
$this->twig = $twig;
$this->authenticationUtils = $authenticationUtils;
$this->translator = $translator;
}
/**
* @Route("/",
* name="app_login",
* options={"expose": true}
* )
*/
public function login(): Response
{
if (null !== $this->security->getUser()) {
return new RedirectResponse($this->urlGenerator->generate('front.course.index'));
}
//$this->translator->setLocale('fr');
// get the login error if there is one
$error = $this->authenticationUtils->getLastAuthenticationError();
// last username entered by the user
$lastUsername = $this->authenticationUtils->getLastUsername();
return new Response($this->twig->render('front/security/login.html.twig', ['last_username' => $lastUsername, 'error' => $error]));
}
/**
* @Route("/logout", name="logout")
*/
public function logout(): void
{
// This method can be blank - it will be intercepted by the logout key on your firewall
}
}