46 lines
1.3 KiB
PHP
46 lines
1.3 KiB
PHP
<?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 || $user->isActif()) {
|
|
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;
|
|
}
|
|
}
|