<?php
namespace Noahtech\Sistemas\InterjamaBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
use Symfony\Component\HttpFoundation\Session;
use Noahtech\Sistemas\InterjamaBundle\Handler\McPersonaJuridicaHandler;
class SecurityController extends BaseController {
public function loginAction(AuthenticationUtils $authenticationUtils) {
// get the login error if there is one
$error = $authenticationUtils->getLastAuthenticationError();
// last username entered by the user
$lastUsername = $authenticationUtils->getLastUsername();
$user = $this->getUser();
if (isset($user)) {
if ($user->getRoles()[0] == 'ROLE_ADMIN') {
return $this->redirectToRoute("admin_home");
}
if ($user->getRoles()[0] == 'ROLE_CLIENTE') {
return $this->redirectToRoute("cliente_home");
}
if ($user->getRoles()[0] == 'ROLE_OPERADOR') {
return $this->redirectToRoute("operador_home");
}
if ($user->getRoles()[0] == 'ROLE_OPERADOR_ADUANA') {
return $this->redirectToRoute("operador_aduana_home");
}
if ($user->getRoles()[0] == 'ROLE_FUMIGACION') {
return $this->redirectToRoute("fumigacion_home");
}
}
return $this->render('@NoahtechSistemasInterjama/auth/login.html.twig', [
'last_username' => $lastUsername,
'error' => $error,
]);
}
public function logoutAction() {
$this->container->get('security.token_storage')->setToken(null);
return $this->redirect($this->generateUrl('login'));
}
public function loginSuccessAction() {
$session = $this->get("session");
$user = $this->getUser();
$isAdmin = $this->isRolAdmin($user->getRoles());
if ($isAdmin) {
return $this->redirectToRoute("admin_home");
}
$isCliente = $this->isRolCliente($user->getRoles());
if ($isCliente) {
return $this->redirectToRoute("cliente_home");
}
$isOperador = $this->isRolOperador($user->getRoles());
if ($isOperador) {
return $this->redirectToRoute("operador_home");
}
$isOperadorAduana = $this->isRolOperadorAduana($user->getRoles());
if ($isOperadorAduana) {
return $this->redirectToRoute("operador_aduana_home");
}
$isFumigacion = $this->isRolFumigacion($user->getRoles());
if ($isFumigacion) {
return $this->redirectToRoute("fumigacion_home");
}
}
}