<?php
namespace App\Controller;
use App\Entity\AppUser;
use App\Entity\ResDocument;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
class HomeController extends AbstractController
{
// /**
// * @Route("/home", name="home")
// */
// public function index(EntityManagerInterface $entityManager): Response
// {
//
//
// $currentUser = $this->getUser();
//
//
// return $this->render('home/tdb_utilisateur.html.twig', [
//
//
// ]);
// }
//
/**
* @Route("/home", name="home")
* @Route("/dashboard", name="dashboard")
*/
public function index(EntityManagerInterface $entityManager): Response
{
$currentUser = $this->getUser();
// ( new DateTime())->getOffset(( new DateTime())->getTimezone())
// dump(new DateTime());
return $this->render('dashboard/dashboard.html.twig', [
]);
}
/**
* @Route("/docs/{id}", name="document_show", methods={"GET"})
*/
public function documentShow(ResDocument $resDocument): Response
{
// load the file from the filesystem
$file = new File($this->getParameter('brochures_directory') . '/' . $resDocument->getCheminDuFichier());
// dump($this->getParameter('brochures_directory') . '/' . $resDocument->getCheminDuFichier());
// display the file contents in the browser instead of downloading it
return $this->file($file, 'preview.pdf', ResponseHeaderBag::DISPOSITION_INLINE);
}
/**
* @Route("/pwdgenaration", name="pwd_genaration", methods={"GET"})
*/
public function pwdGenaration(EntityManagerInterface $entityManager, UserPasswordHasherInterface $passwordHasher): Response
{
set_time_limit(0);
$appUserRepository = $entityManager->getRepository(AppUser::class);
$users = $appUserRepository->findAll();
$cpt = 0;
foreach ($users as $user) {
$hashedPassword = $passwordHasher->hashPassword(
$user, 'rootroot');
$user->setPassword($hashedPassword);
$entityManager->flush();
}
$entityManager->flush();
return new Response('OK');
}
}