Commit c210e423 by Julien Jorry

Fix redirection after changing role

parent 4792371e
......@@ -33,6 +33,7 @@ use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Routing\RouterInterface;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\Security\Core\Security as Secur;
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
......@@ -49,8 +50,9 @@ class IndexController extends AbstractController
private $authenticator;
private $session;
private $tokenStorage;
private $router;
public function __construct(EventDispatcherInterface $eventDispatcher, EntityManagerInterface $em, UserManagerInterface $userManager, CsrfTokenManagerInterface $tokenManager = null, GuardAuthenticatorHandler $guard, SessionInterface $session, LoginAuthenticator $authenticator, TokenStorageInterface $tokenStorage)
public function __construct(EventDispatcherInterface $eventDispatcher, EntityManagerInterface $em, UserManagerInterface $userManager, CsrfTokenManagerInterface $tokenManager = null, GuardAuthenticatorHandler $guard, SessionInterface $session, LoginAuthenticator $authenticator, TokenStorageInterface $tokenStorage, RouterInterface $router)
{
$this->eventDispatcher = $eventDispatcher;
$this->em = $em;
......@@ -60,6 +62,7 @@ class IndexController extends AbstractController
$this->authenticator = $authenticator;
$this->session = $session;
$this->tokenStorage = $tokenStorage;
$this->router = $router;
}
/**
......@@ -434,13 +437,12 @@ class IndexController extends AbstractController
$this->removeOldSessionParams();
$this->reloadUserTokenFromGroup($group, $request);
// @TODO : On redirige sur l'index (ou en fonction du rôle?)
$referer = $request->headers->get('referer');
if ($referer && !$request->isXmlHttpRequest()) {
return $this->redirect($referer);
} elseif (!$request->isXmlHttpRequest()) {
return $this->redirectToRoute('index');
if (in_array('ROLE_SUPER_ADMIN', $this->getUser()->getRoles(), true)) {
// c'est un administrateur
return new RedirectResponse($this->router->generate('sonata_admin_dashboard'));
}
return new RedirectResponse($this->router->generate('index'));
}
private function removeOldSessionParams()
......
......@@ -60,6 +60,7 @@ class MLCEventListener implements EventSubscriberInterface
MLCEvents::REGISTRATION_PRESTATAIRE => 'onRegistrationPrestataire',
MLCEvents::REGISTRATION_CAISSIER => 'onRegistrationCaissier',
MLCEvents::FLUX => 'onFlux',
// @TODO : checker si VALIDATE_DEMANDE_ACHAT_EMLC c'est toujours d'actualité et utile ?
MLCEvents::VALIDATE_DEMANDE_ACHAT_EMLC => 'onValidateDemandeAchatEmlc',
MLCEvents::CHANGE_PRESTATAIRE_COMPTOIR => 'onChange',
MLCEvents::CHANGE_ADHERENT_COMPTOIR => 'onChange',
......@@ -257,6 +258,7 @@ class MLCEventListener implements EventSubscriberInterface
$template = '@kohinos/email/flux/' . $type . '_' . $flux->getParentType() . '-' . $flux->getType() . '.html.twig';
}
}
return $template;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment