src/Noahtech/Sistemas/InterjamaBundle/Controller/SecurityController.php line 12

Open in your IDE?
  1. <?php
  2. namespace Noahtech\Sistemas\InterjamaBundle\Controller;
  3. use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  4. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  5. use Symfony\Component\HttpFoundation\Session;
  6. use Noahtech\Sistemas\InterjamaBundle\Handler\McPersonaJuridicaHandler;
  7. class SecurityController extends BaseController {
  8.     public function loginAction(AuthenticationUtils $authenticationUtils) {
  9.         // get the login error if there is one
  10.         $error $authenticationUtils->getLastAuthenticationError();
  11.         // last username entered by the user
  12.         $lastUsername $authenticationUtils->getLastUsername();
  13.         $user $this->getUser();
  14.         if (isset($user)) {            
  15.             if ($user->getRoles()[0] == 'ROLE_ADMIN') {
  16.                 return $this->redirectToRoute("admin_home");
  17.             }
  18.             if ($user->getRoles()[0] == 'ROLE_CLIENTE') {
  19.                 return $this->redirectToRoute("cliente_home");
  20.             }
  21.             if ($user->getRoles()[0] == 'ROLE_OPERADOR') {
  22.                 return $this->redirectToRoute("operador_home");
  23.             }
  24.             if ($user->getRoles()[0] == 'ROLE_OPERADOR_ADUANA') {
  25.                 return $this->redirectToRoute("operador_aduana_home");
  26.             }
  27.             if ($user->getRoles()[0] == 'ROLE_FUMIGACION') {
  28.                 return $this->redirectToRoute("fumigacion_home");
  29.             }
  30.             if ($user->getRoles()[0] == 'ROLE_ATENCION') {
  31.                 return $this->redirectToRoute("atencion_home");
  32.             }
  33.         }       
  34.         return $this->render('@NoahtechSistemasInterjama/auth/login.html.twig', [
  35.             'last_username' => $lastUsername,
  36.             'error' => $error,
  37.         ]);
  38.     }
  39.     public function logoutAction() {
  40.         $this->container->get('security.token_storage')->setToken(null);
  41.         return $this->redirect($this->generateUrl('login'));
  42.     }
  43.     public function loginSuccessAction() {
  44.         $session $this->get("session");
  45.         $user $this->getUser();
  46.         $isAdmin $this->isRolAdmin($user->getRoles());
  47.         if ($isAdmin) {
  48.             return $this->redirectToRoute("admin_home");
  49.         } 
  50.         $isCliente $this->isRolCliente($user->getRoles());
  51.         if ($isCliente) {
  52.             return $this->redirectToRoute("cliente_home");
  53.         }
  54.         $isOperador $this->isRolOperador($user->getRoles());
  55.         if ($isOperador) {
  56.             return $this->redirectToRoute("operador_home");
  57.         }
  58.         $isOperadorAduana $this->isRolOperadorAduana($user->getRoles());
  59.         if ($isOperadorAduana) {
  60.             return $this->redirectToRoute("operador_aduana_home");
  61.         }
  62.         $isFumigacion $this->isRolFumigacion($user->getRoles());
  63.         if ($isFumigacion) {
  64.             return $this->redirectToRoute("fumigacion_home");
  65.         }
  66.         $isAtencion $this->isRolAtencion($user->getRoles());
  67.         if ($isAtencion) {
  68.             return $this->redirectToRoute("atencion_home");
  69.         }     
  70.     }   
  71. }