src/Controller/SecurityController.php line 52

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\ParametreGlobal;
  4. use Doctrine\ORM\EntityManagerInterface;
  5. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  6. use Symfony\Component\HttpFoundation\RedirectResponse;
  7. use Symfony\Component\HttpFoundation\Response;
  8. use Symfony\Component\Routing\Annotation\Route;
  9. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  10. class SecurityController extends AbstractController
  11. {
  12.     private $entityManager;
  13.     public function __construct(EntityManagerInterface $entityManager)
  14.     {
  15.         $this->entityManager $entityManager;
  16.     }
  17.     /**
  18.      * @Route("/adminsecurity", name="security")
  19.      */
  20.     public function index(): Response
  21.     {
  22.         return $this->json([
  23.             'message' => 'Welcome to your new controller!',
  24.             'path' => 'src/Controller/SecurityController.php',
  25.         ]);
  26.     }
  27.     /**
  28.      * @Route("/", name="racine")
  29.      */
  30.     public function racine(): Response
  31.     {
  32.         return $this->redirectToRoute('app_login');
  33.     }
  34.     public function getUrlFromGlobalParameter(string $parameterName):string
  35.     {
  36.         try {
  37.             $url $this->entityManager->getRepository(ParametreGlobal::class)->findOneBy(array('parameterName'=>$parameterName))->getParameterValue();
  38.         }catch (\Throwable $t){
  39.             $url "/#";
  40.         }
  41.         return $url;
  42.     }
  43.     /**
  44.      * @Route("/login", name="app_login")
  45.      */
  46.     public function login(AuthenticationUtils $authenticationUtils): Response
  47.     {
  48.         if ($this->getUser()) {
  49.             return $this->redirectToRoute('alfred_front');
  50.         }
  51.         // get the login error if there is one
  52.         $error $authenticationUtils->getLastAuthenticationError();
  53.         // last username entered by the user
  54.         $lastUsername $authenticationUtils->getLastUsername();
  55.         $url_devis $this->getUrlFromGlobalParameter('url_devis');
  56.         $url_video $this->getUrlFromGlobalParameter('url_video');
  57.         return $this->render('security/login_front.html.twig', ['last_username' => $lastUsername'error' => $error,'url_devis'=>$url_devis,'url_video'=>$url_video]);
  58.     }
  59.     /**
  60.      * @Route("/logout", name="app_logout")
  61.      */
  62.     public function logout(): RedirectResponse
  63.     {
  64.         throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
  65.     }
  66. }