<?php
namespace App\Controller;
use App\Entity\ParametreGlobal;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
class SecurityController extends AbstractController
{
private $entityManager;
public function __construct(EntityManagerInterface $entityManager)
{
$this->entityManager = $entityManager;
}
/**
* @Route("/adminsecurity", name="security")
*/
public function index(): Response
{
return $this->json([
'message' => 'Welcome to your new controller!',
'path' => 'src/Controller/SecurityController.php',
]);
}
/**
* @Route("/", name="racine")
*/
public function racine(): Response
{
return $this->redirectToRoute('app_login');
}
public function getUrlFromGlobalParameter(string $parameterName):string
{
try {
$url = $this->entityManager->getRepository(ParametreGlobal::class)->findOneBy(array('parameterName'=>$parameterName))->getParameterValue();
}catch (\Throwable $t){
$url = "/#";
}
return $url;
}
/**
* @Route("/login", name="app_login")
*/
public function login(AuthenticationUtils $authenticationUtils): Response
{
if ($this->getUser()) {
return $this->redirectToRoute('alfred_front');
}
// get the login error if there is one
$error = $authenticationUtils->getLastAuthenticationError();
// last username entered by the user
$lastUsername = $authenticationUtils->getLastUsername();
$url_devis = $this->getUrlFromGlobalParameter('url_devis');
$url_video = $this->getUrlFromGlobalParameter('url_video');
return $this->render('security/login_front.html.twig', ['last_username' => $lastUsername, 'error' => $error,'url_devis'=>$url_devis,'url_video'=>$url_video]);
}
/**
* @Route("/logout", name="app_logout")
*/
public function logout(): RedirectResponse
{
throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
}
}