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.         }       
  31.         return $this->render('@NoahtechSistemasInterjama/auth/login.html.twig', [
  32.             'last_username' => $lastUsername,
  33.             'error' => $error,
  34.         ]);
  35.     }
  36.     public function logoutAction() {
  37.         $this->container->get('security.token_storage')->setToken(null);
  38.         return $this->redirect($this->generateUrl('login'));
  39.     }
  40.     public function loginSuccessAction() {
  41.         $session $this->get("session");
  42.         $user $this->getUser();
  43.         $isAdmin $this->isRolAdmin($user->getRoles());
  44.         if ($isAdmin) {
  45.             return $this->redirectToRoute("admin_home");
  46.         } 
  47.         $isCliente $this->isRolCliente($user->getRoles());
  48.         if ($isCliente) {
  49.             return $this->redirectToRoute("cliente_home");
  50.         }
  51.         $isOperador $this->isRolOperador($user->getRoles());
  52.         if ($isOperador) {
  53.             return $this->redirectToRoute("operador_home");
  54.         }
  55.         $isOperadorAduana $this->isRolOperadorAduana($user->getRoles());
  56.         if ($isOperadorAduana) {
  57.             return $this->redirectToRoute("operador_aduana_home");
  58.         }
  59.         $isFumigacion $this->isRolFumigacion($user->getRoles());
  60.         if ($isFumigacion) {
  61.             return $this->redirectToRoute("fumigacion_home");
  62.         }           
  63.     }   
  64. }