src/Controller/Utilisateurs/InscriptionController.php line 23
<?php
namespace App\Controller\Utilisateurs;
use App\Form\InscriptionForm;
use App\Service\Utilisateurs;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Http\Attribute\IsGranted;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
/**
* Class for inscription
* Class InscriptionController
*/
class InscriptionController extends AbstractController
{
/**
* @Route("/inscription", name="inscription", methods={"GET","POST"})
*/
public function inscription(
Request $request,
Utilisateurs $utilisateurService
): Response {
$form = $this->createForm(InscriptionForm::class);
$done = false;
$errors = [];
if ($request->isMethod("POST")) {
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$result = $utilisateurService->register($form->getData());
if($result === "done"){
$done = true;
}else if ($result === "email_already_used"){
$errors[] = array(
"message" => 'Cette adresse mail est déjà utilisé, veuillez choisir une autre adresse mail'
);
}
} else {
$errors = $form->getErrors(true);
}
}
return $this->render('users/inscription-form.html.twig', [
'form' => $form,
'errors' => $errors,
'done' => $done
]);
}
}