src/Controller/SecurityController.php line 67

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.      * Portal principal con los 3 accesos (ManteVenues, ManteCatering, ManteAV)
  25.      *
  26.      * @Route("/login", name="login")
  27.      */
  28.     public function loginAction(AuthenticationUtils $authenticationUtilsRequest $request)
  29.     {
  30.         $em $this->getDoctrine()->getManager();
  31.         // Recupera la configuración general (solo debe haber 1)
  32.         $configuration $em->getRepository(Configuration::class)->findOneBy([]);
  33.         return $this->render('inicio/inicio.html.twig', [
  34.             'last_username' => $authenticationUtils->getLastUsername(),
  35.             'error'         => $authenticationUtils->getLastAuthenticationError(),
  36.             'configuration' => $configuration,
  37.         ]);
  38.     }
  39.     /**
  40.      * @Route("/login/{type}", name="app_login_branded")
  41.      */
  42.     public function loginBranded(string $typeRequest $requestAuthenticationUtils $authenticationUtils)
  43.     {
  44.         $em $this->getDoctrine()->getManager();
  45.         // 1. Buscamos la configuración de marca para este tipo (venues, catering o av)
  46.         $branding $em->getRepository(SettingsBranding::class)->findOneBy([
  47.             'accessType' => $type,
  48.             'isActive'   => true
  49.         ]);
  50.         // Si no existe esa configuración, volvemos al portal
  51.         if (!$branding) {
  52.             return $this->redirectToRoute('ruta_inicio');
  53.         }
  54.         // 2. Guardamos en sesión para que el Authenticator sepa a dónde volver si falla
  55.         $request->getSession()->set('current_access_type'$type);
  56.         return $this->render('login/login_unified.html.twig', [
  57.             'last_username' => $authenticationUtils->getLastUsername(),
  58.             'error'         => $authenticationUtils->getLastAuthenticationError(),
  59.             'branding'      => $branding,
  60.             'type'          => $type
  61.         ]);
  62.     }
  63.     /**
  64.      * Cambiar el tipo de acceso (venues / av / catering) y volver al dashboard
  65.      *
  66.      * @Route("/switch-access/{type}", name="switch_access")
  67.      */
  68.     public function switchAccess(string $typeRequest $request)
  69.     {
  70.         // Solo aceptamos estos tipos. Ajusta si quieres añadir más.
  71.         $allowed = ['venues''av''catering'];
  72.         if (!in_array($type$allowedtrue)) {
  73.             throw $this->createNotFoundException();
  74.         }
  75.         // Guardar el nuevo tipo en sesión
  76.         $request->getSession()->set('current_access_type'$type);
  77.         // Redirigir al dashboard principal (pon aquí tu ruta real)
  78.         return $this->redirectToRoute('homepage');
  79.         // ^^^ cambia 'home' por la ruta que uses para tu panel principal
  80.     }
  81.     /**
  82.      * @Route("/kickout", name="kickout")
  83.      */
  84.     public function KickoutAction(Request $request)
  85.     {
  86.         $this->get('security.token_storage')->setToken(null);
  87.         $session $request->getSession();
  88.         $session->invalidate();
  89.         return $this->render('kickout/kickout.html.twig');
  90.     }
  91.     /**
  92.      * @Route("/login_check", name="login_check")
  93.      */
  94.     public function loginCheckAction()
  95.     {
  96.         // lo gestiona el LoginAuthenticator (Guard)
  97.     }
  98.     /**
  99.      * @Route("/logout", name="logout")
  100.      */
  101.     public function logoutAction()
  102.     {
  103.         // gestionado por el firewall
  104.     }
  105.     public function getLicencias()
  106.     {
  107.         $repository    $this->em->getRepository(Configuration::class);
  108.         $configuration $repository->findOneById(1);
  109.         return $configuration->getLicenses();
  110.     }
  111. }