<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Security\Core\Security;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Contracts\Translation\TranslatorInterface;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
use App\Entity\User;
class SecurityController extends AbstractController
{
private $translator;
public function __construct(TranslatorInterface $translator)
{
$this->translator = $translator;
}
/**
* @Route("/login", name="app_login")
*/
public function login(AuthenticationUtils $authenticationUtils): Response
{
// get the login error if there is one
$error = $authenticationUtils->getLastAuthenticationError();
// last username entered by the user
$lastUsername = $authenticationUtils->getLastUsername();
return $this->render('security/login_front.html.twig', [
'last_username' => $lastUsername,
'error' => $error,
]);
}
/**
* @Route("/login_check", name="login_check")
*/
public function loginCheck(AuthenticationUtils $authenticationUtils): Response
{
// get the login error if there is one
$error = $authenticationUtils->getLastAuthenticationError();
// last username entered by the user
$lastUsername = $authenticationUtils->getLastUsername();
return $this->render('security/login_front.html.twig', [
'last_username' => $lastUsername,
'error' => $error,
]);
}
/**
* @Route("/login_fail", name="login_fail")
*/
public function loginFail(Request $request)
{
$session = $request->getSession();
$title="";
$message = $this->translator->trans('compte.register.inscription.erreur.login_password', array(), 'app');
$session->getFlashBag()->add('danger', ['type' => 'danger', 'title' => $title, 'message' => $message]);
return $this->redirectToRoute('compte');
}
/**
* @Route("/accessDenied", name="login_accessdenied")
*/
public function accessDenied(Request $request)
{
$session = $request->getSession();
$title="";
$message = $this->translator->trans('compte.register.inscription.erreur.acces_refuse', array(), 'app');
$session->getFlashBag()->add('danger', ['type' => 'danger', 'title' => $title, 'message' => $message]);
return $this->redirectToRoute('compte');
}
/**
* @Route("/admin/login", name="login_bo")
*/
public function loginBo(AuthenticationUtils $authenticationUtils)
{
// get the login error if there is one
$error = $authenticationUtils->getLastAuthenticationError();
// last username entered by the user
$lastUsername = $authenticationUtils->getLastUsername();
return $this->render('security/login_back.html.twig', [
'last_username' => $lastUsername,
'error' => $error,
]);
}
}