<?php
namespace App\Controller;
use App\Entity\Society;
use App\Service\ExportAndImportTable;
use App\Form\RegistrationFormType;
use App\Security\SocietyAuthenticator;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Http\Authentication\UserAuthenticatorInterface;
class RegistrationController extends AbstractController
{
/**
* @Route("/register", name="register")
*/
public function register(Request $request, UserPasswordHasherInterface $userPasswordHasher, UserAuthenticatorInterface $authenticator, EntityManagerInterface $entityManager, SocietyAuthenticator $formAuthenticator): Response
{
$society = new Society();
$form = $this->createForm(RegistrationFormType::class, $society);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
// encode the plain password
$society->setPassword(
$userPasswordHasher->hashPassword(
$society,
$form->get('plainPassword')->getData()
)
);
$entityManager->persist($society);
$entityManager->flush();
// do anything else you need here, like send an email
// substitute the previous line (redirect response) with this one.
return $authenticator->authenticateUser(
$society,
$formAuthenticator,
$request
);
return $this->redirectToRoute('home');
}
return $this->render('registration/register.html.twig', [
'registrationForm' => $form->createView()
]);
}
/**
* @Route("/home/portail-administration/Gestion-des-Bases-de-donnees/table/export/{table_name}", name="app_portail_administration-bdd_table-export")
*/
public function tableExportFile($table_name,Request $request, ExportAndImportTable $ExportAndImportTable): Response
{
return $ExportAndImportTable->ExportTable($table_name);
}
}