src/Controller/IndexController.php line 30

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\User;
  4. use Doctrine\ORM\EntityManagerInterface;
  5. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  6. use Symfony\Component\HttpFoundation\RedirectResponse;
  7. use Symfony\Component\HttpFoundation\Request;
  8. use Symfony\Component\HttpFoundation\Response;
  9. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  10. use Symfony\Component\Routing\Annotation\Route;
  11. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  12. use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
  13. use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
  14. use Symfony\Component\Security\Csrf\TokenGenerator\TokenGeneratorInterface;
  15. use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
  16. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  17. use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
  18. class IndexController extends AbstractController
  19. {
  20.     public function __construct(
  21.         EntityManagerInterface $em,
  22.         TokenStorageInterface $tokenStorage,
  23.         SessionInterface $session
  24.     ) {
  25.         $this->em = $em;
  26.         $this->tokenStorage = $tokenStorage;
  27.         $this->session = $session;
  28.     }
  29.     /**
  30.      * @Route("/", name="aaa")
  31.      */
  32.     public function index(): Response
  33.     {
  34.         $user = $this->getUser();
  35.         if($user){
  36.             $roles = $user->getRoles();
  37.             if (in_array("ROLE_SUPER_ADMINISTRATOR", $roles) or in_array("ROLE_ADMIN", $roles)){
  38.                 return $this->redirectToRoute('admin_project_list_home');
  39.             }else if (in_array("ROLE_DEV", $roles) or in_array("ROLE_EPC", $roles)){
  40.                 return $this->redirectToRoute('user_project_list_home');
  41.             }
  42.         }else{
  43.             return $this->redirectToRoute('app_login');
  44.         }
  45.         return $this->render('admin/index.html.twig');
  46.     }
  47.     /**
  48.      * @Route("/integration/{page}", name="app_integration")
  49.      */
  50.     public function integration($page): Response
  51.     {
  52.         return $this->render("intergration/$page.html.twig");
  53.     }
  54.     /**
  55.      * @Route("/integration/equipement/{page}", name="app_equipement_integration")
  56.      */
  57.     public function integrationEquipement($page): Response
  58.     {
  59.         return $this->render("intergration/equipement/$page.html.twig");
  60.     }
  61.     /**
  62.      * @Route("/switch-user/{id}", name="switch_user_admin")
  63.      * @IsGranted("ROLE_SUPER_ADMINISTRATOR")
  64.      */
  65.     public function switchUser(Request $request,$id) : Response
  66.     {
  67.         $user = $this->em->getRepository(User::class)->find($id);
  68.         $token = new UsernamePasswordToken($user, null, 'main', $user->getRoles());
  69.         $this->tokenStorage->setToken($token);
  70.         $this->session->set('_security_main', serialize($token));
  71.         return $this->redirectToRoute('intervenant_project_view');
  72.     }
  73.     /**
  74.      * @Route("/altarea", name="app_altarea_login_redirection")
  75.      */
  76.     public function redirectAltarea(): Response
  77.     {
  78.         return $this->redirect('https://launcher.myapps.microsoft.com/api/signin/e458aa6e-633e-4c9a-a6eb-e60e14212070?tenantId=a3fa8e74-b14d-4758-a49c-931f83606b14');
  79.     }
  80. }