src/Controller/SecurityController.php line 66

Open in your IDE?
  1. <?php
  2. /**
  3.  * Created by Mediterranean Develup Solutions.
  4.  * User: carlos.rojas@develup.solutions
  5.  * Date: 12/06/2017
  6.  * Time: 17:44
  7.  */
  8. namespace App\Controller;
  9. use App\Entity\Configuration;
  10. use App\Entity\SettingsBranding;
  11. use Doctrine\ORM\EntityManagerInterface;
  12. use Symfony\Component\Routing\Annotation\Route;
  13. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  14. use Symfony\Component\HttpFoundation\Request;
  15. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  16. class SecurityController extends AbstractController
  17. {
  18.     protected EntityManagerInterface $em;
  19.     public function __construct(EntityManagerInterface $em)
  20.     {
  21.         $this->em $em;
  22.     }
  23.     /**
  24.      * @Route("/inicio", name="ruta_inicio")
  25.      */
  26.     public function inicioAction(AuthenticationUtils $authenticationUtils)
  27.     {
  28.         $em $this->getDoctrine()->getManager();
  29.         $configuration $em->getRepository(Configuration::class)->findOneBy([]);
  30.         return $this->render('login/login.html.twig', [
  31.             'last_username' => $authenticationUtils->getLastUsername(),
  32.             'error'         => $authenticationUtils->getLastAuthenticationError(),
  33.             'configuration' => $configuration,
  34.         ]);
  35.     }
  36.     
  37.     /**
  38.      * Portal principal con los 3 accesos (ManteVenues, ManteCatering, ManteAV)
  39.      *
  40.      * @Route("/login", name="login")
  41.      */
  42.     public function loginAction(AuthenticationUtils $authenticationUtilsRequest $request)
  43.     {
  44.         $em $this->getDoctrine()->getManager();
  45.         // Recupera la configuración general (solo debe haber 1)
  46.         $configuration $em->getRepository(Configuration::class)->findOneBy([]);
  47.         return $this->render('inicio/inicio.html.twig', [
  48.             'last_username' => $authenticationUtils->getLastUsername(),
  49.             'error'         => $authenticationUtils->getLastAuthenticationError(),
  50.             'configuration' => $configuration,
  51.         ]);
  52.     }
  53.     /**
  54.      * @Route("/login/{type}", name="app_login_branded")
  55.      */
  56.     public function loginBranded(string $typeRequest $requestAuthenticationUtils $authenticationUtils)
  57.     {
  58.         $em $this->getDoctrine()->getManager();
  59.         // 1. Buscamos la configuración de marca para este tipo (venues, catering o av)
  60.         $branding $em->getRepository(SettingsBranding::class)->findOneBy([
  61.             'accessType' => $type,
  62.             'isActive'   => true
  63.         ]);
  64.         // Si no existe esa configuración, volvemos al portal
  65.         if (!$branding) {
  66.             return $this->redirectToRoute('ruta_inicio');
  67.         }
  68.         // 2. Guardamos en sesión para que el Authenticator sepa a dónde volver si falla
  69.         $request->getSession()->set('current_access_type'$type);
  70.         return $this->render('login/login_unified.html.twig', [
  71.             'last_username' => $authenticationUtils->getLastUsername(),
  72.             'error'         => $authenticationUtils->getLastAuthenticationError(),
  73.             'branding'      => $branding,
  74.             'type'          => $type
  75.         ]);
  76.     }
  77.     /**
  78.      * Cambiar el tipo de acceso (venues / av / catering) y volver al dashboard
  79.      *
  80.      * @Route("/switch-access/{type}", name="switch_access")
  81.      */
  82.     public function switchAccess(string $typeRequest $request)
  83.     {
  84.         // Solo aceptamos estos tipos. Ajusta si quieres añadir más.
  85.         $allowed = ['venues''av''catering'];
  86.         if (!in_array($type$allowedtrue)) {
  87.             throw $this->createNotFoundException();
  88.         }
  89.         // Guardar el nuevo tipo en sesión
  90.         $request->getSession()->set('current_access_type'$type);
  91.         // Redirigir al dashboard principal (pon aquí tu ruta real)
  92.         return $this->redirectToRoute('homepage');
  93.         // ^^^ cambia 'home' por la ruta que uses para tu panel principal
  94.     }
  95.     /**
  96.      * @Route("/kickout", name="kickout")
  97.      */
  98.     public function KickoutAction(Request $request)
  99.     {
  100.         $this->get('security.token_storage')->setToken(null);
  101.         $session $request->getSession();
  102.         $session->invalidate();
  103.         return $this->render('kickout/kickout.html.twig');
  104.     }
  105.     /**
  106.      * @Route("/login_check", name="login_check")
  107.      */
  108.     public function loginCheckAction()
  109.     {
  110.         // lo gestiona el LoginAuthenticator (Guard)
  111.     }
  112.     /**
  113.      * @Route("/logout", name="logout")
  114.      */
  115.     public function logoutAction()
  116.     {
  117.         // gestionado por el firewall
  118.     }
  119.     public function getLicencias()
  120.     {
  121.         $repository    $this->em->getRepository(Configuration::class);
  122.         $configuration $repository->findOneById(1);
  123.         return $configuration->getLicenses();
  124.     }
  125. }