src/Controller/HomeController.php line 39

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\AppUser;
  4. use App\Entity\ResDocument;
  5. use Doctrine\ORM\EntityManagerInterface;
  6. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  7. use Symfony\Component\HttpFoundation\Response;
  8. use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
  9. use Symfony\Component\Routing\Annotation\Route;
  10. use Symfony\Component\HttpFoundation\File\File;
  11. use Symfony\Component\HttpFoundation\ResponseHeaderBag;
  12. class HomeController extends AbstractController
  13. {
  14. //    /**
  15. //     * @Route("/home", name="home")
  16. //     */
  17. //    public function index(EntityManagerInterface $entityManager): Response
  18. //    {
  19. //
  20. //
  21. //        $currentUser = $this->getUser();
  22. //
  23. //
  24. //        return $this->render('home/tdb_utilisateur.html.twig', [
  25. //
  26. //
  27. //        ]);
  28. //    }
  29. //
  30.     /**
  31.      * @Route("/home", name="home")
  32.      * @Route("/dashboard", name="dashboard")
  33.      */
  34.     public function index(EntityManagerInterface $entityManager): Response
  35.     {
  36.         $currentUser $this->getUser();
  37. //       ( new DateTime())->getOffset(( new DateTime())->getTimezone())
  38. //        dump(new DateTime());
  39.         return $this->render('dashboard/dashboard.html.twig', [
  40.         ]);
  41.     }
  42.     /**
  43.      * @Route("/docs/{id}", name="document_show", methods={"GET"})
  44.      */
  45.     public function documentShow(ResDocument $resDocument): Response
  46.     {
  47.         // load the file from the filesystem
  48.         $file = new File($this->getParameter('brochures_directory') . '/' $resDocument->getCheminDuFichier());
  49. //        dump($this->getParameter('brochures_directory') . '/' . $resDocument->getCheminDuFichier());
  50.         // display the file contents in the browser instead of downloading it
  51.         return $this->file($file'preview.pdf'ResponseHeaderBag::DISPOSITION_INLINE);
  52.     }
  53.     /**
  54.      * @Route("/pwdgenaration", name="pwd_genaration", methods={"GET"})
  55.      */
  56.     public function pwdGenaration(EntityManagerInterface $entityManagerUserPasswordHasherInterface $passwordHasher): Response
  57.     {
  58.         set_time_limit(0);
  59.         $appUserRepository $entityManager->getRepository(AppUser::class);
  60.         $users $appUserRepository->findAll();
  61.         $cpt 0;
  62.         foreach ($users as $user) {
  63.             $hashedPassword $passwordHasher->hashPassword(
  64.                 $user'rootroot');
  65.             $user->setPassword($hashedPassword);
  66.             $entityManager->flush();
  67.         }
  68.         $entityManager->flush();
  69.         return new Response('OK');
  70.     }
  71. }