authentication done

This commit is contained in:
Olivier PARPAILLON
2024-11-19 13:07:07 +01:00
parent 51fcbba8b2
commit 8ddbf9c5d6
7 changed files with 134 additions and 34 deletions

View File

@@ -6,6 +6,7 @@ use App\Entity\Participant;
use App\Form\RegistrationFormType;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Bundle\SecurityBundle\Security;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
@@ -14,7 +15,7 @@ use Symfony\Component\Routing\Attribute\Route;
class RegistrationController extends AbstractController
{
#[Route('/register', name: 'app_register')]
public function register(Request $request, UserPasswordHasherInterface $userPasswordHasher, EntityManagerInterface $entityManager): Response
public function register(Request $request, UserPasswordHasherInterface $userPasswordHasher, EntityManagerInterface $entityManager, Security $security,): Response
{
$user = new Participant();
$form = $this->createForm(RegistrationFormType::class, $user);
@@ -26,16 +27,24 @@ class RegistrationController extends AbstractController
// encode the plain password
$user->setPassword($userPasswordHasher->hashPassword($user, $plainPassword));
$user->setRoles(['ROLE_USER']);
$user->setActif(false);
if ($user->getRoles() == 'ROLE_ADMIN') {
$user->setAdministrateur(true);
} else {
$user->setAdministrateur(false);
}
$entityManager->persist($user);
$entityManager->flush();
// do anything else you need here, like send an email
return $this->redirectToRoute('home');
// return $this->redirectToRoute('home');
return $security->login($user, 'form_login', 'main');
}
return $this->render('registration/register.html.twig', [
return $this->render('auth/register.html.twig', [
'registrationForm' => $form,
]);
}