add pseudo
This commit is contained in:
@@ -4,11 +4,8 @@ security:
|
||||
Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface: 'auto'
|
||||
# https://symfony.com/doc/current/security.html#loading-the-user-the-user-provider
|
||||
providers:
|
||||
# used to reload user from session & other features (e.g. switch_user)
|
||||
app_user_provider:
|
||||
entity:
|
||||
class: App\Entity\Participant
|
||||
property: email
|
||||
id: App\Security\UserProvider
|
||||
# used to reload user from session & other features (e.g. switch_user)
|
||||
# used to reload user from session & other features (e.g. switch_user)
|
||||
firewalls:
|
||||
@@ -26,6 +23,10 @@ security:
|
||||
path: app_logout
|
||||
target: app_login
|
||||
# where to redirect after logout
|
||||
remember_me:
|
||||
secret: '%kernel.secret%'
|
||||
lifetime: 604800 # 1 week in seconds
|
||||
#always_remember_me: true
|
||||
|
||||
# activate different ways to authenticate
|
||||
# https://symfony.com/doc/current/security.html#the-firewall
|
||||
|
||||
@@ -7,6 +7,9 @@ parameters:
|
||||
|
||||
services:
|
||||
# default configuration for services in *this* file
|
||||
App\Security\UserProvider:
|
||||
arguments:
|
||||
$entityManager: '@doctrine.orm.entity_manager'
|
||||
_defaults:
|
||||
autowire: true # Automatically injects dependencies in your services.
|
||||
autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.
|
||||
|
||||
@@ -12,6 +12,7 @@ use Symfony\Component\Uid\Uuid;
|
||||
|
||||
#[ORM\Entity(repositoryClass: ParticipantRepository::class)]
|
||||
#[ORM\UniqueConstraint(name: 'UNIQ_IDENTIFIER_EMAIL', fields: ['email'])]
|
||||
#[ORM\UniqueConstraint(name: 'UNIQ_IDENTIFIER_PSEUDO', fields: ['pseudo'])]
|
||||
class Participant implements UserInterface, PasswordAuthenticatedUserInterface
|
||||
{
|
||||
#[ORM\Id]
|
||||
@@ -26,6 +27,9 @@ class Participant implements UserInterface, PasswordAuthenticatedUserInterface
|
||||
#[ORM\Column(length: 255)]
|
||||
private ?string $prenom = null;
|
||||
|
||||
#[ORM\Column(length: 255, nullable: false)]
|
||||
private ?string $pseudo = null;
|
||||
|
||||
#[ORM\Column(length: 255, nullable: true)]
|
||||
private ?string $telephone = null;
|
||||
|
||||
@@ -76,6 +80,17 @@ class Participant implements UserInterface, PasswordAuthenticatedUserInterface
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getPseudo(): ?string
|
||||
{
|
||||
return $this->pseudo;
|
||||
}
|
||||
|
||||
public function setPseudo(string $pseudo): self
|
||||
{
|
||||
$this->pseudo = $pseudo;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getPrenom(): ?string
|
||||
{
|
||||
return $this->prenom;
|
||||
|
||||
@@ -39,6 +39,14 @@ class RegistrationFormType extends AbstractType
|
||||
'placeholder' => 'Prénom',
|
||||
],
|
||||
])
|
||||
->add('pseudo', TextType::class, [
|
||||
'label' => 'Pseudo',
|
||||
'label_attr' => ['class' => 'text-gray-700 font-bold'],
|
||||
'attr' => [
|
||||
'class' => 'w-full mb-4 px-4 py-2 border-2 border-gray-300 rounded-lg focus:outline-none focus:border-blue-500',
|
||||
'placeholder' => 'Pseudo',
|
||||
],
|
||||
])
|
||||
->add('nom', TextType::class, [
|
||||
'label' => 'Nom',
|
||||
'label_attr' => ['class' => 'text-gray-700 font-bold'],
|
||||
|
||||
45
src/Security/UserProvider.php
Normal file
45
src/Security/UserProvider.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace App\Security;
|
||||
|
||||
use App\Entity\Participant;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Component\Security\Core\User\UserInterface;
|
||||
use Symfony\Component\Security\Core\User\UserProviderInterface;
|
||||
//use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
|
||||
|
||||
class UserProvider implements UserProviderInterface
|
||||
{
|
||||
private $entityManager;
|
||||
|
||||
public function __construct(EntityManagerInterface $entityManager)
|
||||
{
|
||||
$this->entityManager = $entityManager;
|
||||
}
|
||||
|
||||
public function loadUserByIdentifier(string $username): UserInterface
|
||||
{
|
||||
// Cherche par email ou pseudo
|
||||
$user = $this->entityManager->getRepository(Participant::class)
|
||||
->findOneBy(['email' => $username]) // Cherche par email
|
||||
?? $this->entityManager->getRepository(Participant::class)
|
||||
->findOneBy(['pseudo' => $username]); // Ou par pseudo
|
||||
|
||||
if (!$user) {
|
||||
throw new UsernameNotFoundException('Utilisateur non trouvé');
|
||||
}
|
||||
|
||||
return $user;
|
||||
}
|
||||
|
||||
public function refreshUser(UserInterface $user): UserInterface
|
||||
{
|
||||
// Permet de rafraîchir les données d'un utilisateur (pas toujours nécessaire)
|
||||
return $user;
|
||||
}
|
||||
|
||||
public function supportsClass(string $class): bool
|
||||
{
|
||||
return Participant::class === $class;
|
||||
}
|
||||
}
|
||||
@@ -13,11 +13,14 @@
|
||||
<div class="bg-white shadow-lg rounded-lg p-8 max-w-sm text-center">
|
||||
<h2 class="text-2xl font-bold text-center pb-6">Connectez-vous !</h2>
|
||||
<form action="{{ path('app_login') }}" method="post">
|
||||
<label class="text-gray-700 font-bold" for="username">Email</label>
|
||||
<input class="w-full mb-4 px-4 py-2 border-2 border-gray-300 rounded-lg focus:outline-none focus:border-blue-500" placeholder="Adresse e-mail" type="email" value="{{ last_username }}" name="_username" id="username" autocomplete="email" required autofocus>
|
||||
<label class="text-gray-700 font-bold" for="username">Email ou pseudo</label>
|
||||
<input class="w-full mb-4 px-4 py-2 border-2 border-gray-300 rounded-lg focus:outline-none focus:border-blue-500" placeholder="Adresse e-mail ou pseudo" type="email" value="{{ last_username }}" name="_username" id="username" autocomplete="email" required autofocus>
|
||||
<label class="text-gray-700 font-bold" for="password">Mot de passe</label>
|
||||
<input class="w-full mb-4 px-4 py-2 border-2 border-gray-300 rounded-lg focus:outline-none focus:border-blue-500" placeholder="Mot de passe" type="password" name="_password" id="password" autocomplete="current-password" required>
|
||||
|
||||
<label>
|
||||
<input type="checkbox" name="_remember_me" checked>
|
||||
Se souvenir de moi
|
||||
</label>
|
||||
<input type="hidden" name="_csrf_token"
|
||||
value="{{ csrf_token('authenticate') }}"
|
||||
>
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
{{ form_row(registrationForm.nom) }}
|
||||
{{ form_row(registrationForm.telephone) }}
|
||||
{{ form_row(registrationForm.email) }}
|
||||
{{ form_row(registrationForm.pseudo) }}
|
||||
{{ form_row(registrationForm.plainPassword) }}
|
||||
<button class="btnRegister text-white font-bold py-2 px-4 border-b-4 rounded mx-auto" type="submit">S'inscrire</button>
|
||||
{{ form_end(registrationForm) }}
|
||||
|
||||
Reference in New Issue
Block a user