<?php
namespace App\Controller;
use App\Entity\Date;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
use Symfony\Component\Security\Http\LoginLink\LoginLinkHandlerInterface;
class SecurityController extends AbstractController
{
private $entityManager;
public function __construct(EntityManagerInterface $entityManager)
{
$this->entityManager = $entityManager;
}
/**
* @Route("/attente/hgdfsgui4568fdg84f8gdfd98g", name="app_attente")
*/
public function attente(AuthenticationUtils $authenticationUtils): Response
{
return $this->render('first/index.html.twig', [
'last_username' => "",
'error' => "",
'demande_confirmation' => "",
'confirmation_compte' => "",
'listeDate' => ""
]);
}
/**
* @Route("/", name="app_login")
*/
public function login(AuthenticationUtils $authenticationUtils): Response
{
if ($this->getUser()) {
if ($this->getUser()->getRoles()[0] == "ROLE_ADMIN"){
return $this->redirectToRoute('app_admin_accueil');
}elseif($this->getUser()->getRoles()[0] == "ROLE_BENEFICIAIRE"){
return $this->redirectToRoute('app_beneficiaire_accueil');
}elseif($this->getUser()->getRoles()[0] == "ROLE_CINEMA"){
return $this->redirectToRoute('app_cinema_accueil');
}else{
return $this->redirectToRoute('app_logout');
}
}
// 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.html.twig', [
'last_username' => $lastUsername,
'error' => $error,
'demande_confirmation' => "",
'confirmation_compte' => "",
]);
}
/**
* @Route("/deconnexion", name="app_logout")
*/
public function logout(Request $request)
{
throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
}
}