src/Controller/WelcomeController.php line 16

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Component\Routing\Annotation\Route;
  4. use Symfony\Component\HttpFoundation\BinaryFileResponse;
  5. use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
  6. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  7. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  8. class WelcomeController extends AbstractController
  9. {
  10.     /**
  11.      * @Route("/",name="app_welcome", methods={"GET"})
  12.      */
  13.     public function welcome(AuthenticationUtils $authenticationUtils)
  14.     {
  15.         $securityContext $this->container->get('security.authorization_checker');
  16.         if ($securityContext->isGranted('IS_AUTHENTICATED_REMEMBERED')) {
  17.             if($securityContext->isGranted('ROLE_CLIENT')){
  18.                 return $this->redirectToRoute('client_user_hub');
  19.             }else {
  20.                 return $this->redirectToRoute('app_admin_index');
  21.             }
  22.         }
  23.         return $this->redirect('/it/admin/login');
  24.     }
  25.     /**
  26.      * @Route("/documents/{filename}", methods={"GET"})
  27.      */
  28.     public function documents($filename,$documentsPath) {
  29.         $pathToFile  $documentsPath."/".$filename;
  30.         if(strpos($pathToFile,"..")!==false){
  31.             throw $this->createNotFoundException();
  32.         }
  33.         if(file_exists($pathToFile)){
  34.             return new BinaryFileResponse($pathToFile);
  35.         }
  36.         throw $this->createNotFoundException();
  37.     }
  38. }