diff --git a/src/EventListener/UserResolveListener.php b/src/EventListener/UserResolveListener.php index 8e597bc..fa01a7d 100644 --- a/src/EventListener/UserResolveListener.php +++ b/src/EventListener/UserResolveListener.php @@ -19,10 +19,10 @@ public function __construct(UserRepository $userRepository, PasswordValidatorSer public function onUserResolve(UserResolveEvent $event): void { - $user = $this->userRepository->findOneBy(['email' => $event->getUsername()]); + $user = $this->userRepository->findOneByIdentifier($event->getUsername()); if ($user && $this->passwordValidator->isPasswordValid($user->getPassword(), $event->getPassword())) { $event->setUser($user); } } -} \ No newline at end of file +} diff --git a/src/Repository/UserRepository.php b/src/Repository/UserRepository.php index 3ecc7fb..506d128 100644 --- a/src/Repository/UserRepository.php +++ b/src/Repository/UserRepository.php @@ -48,4 +48,18 @@ public function findById(string $userId): ?User { return $this->findOneBy(["id" => $userId]); } + + /** + * Find an User by any of it's unique properties + * @param string $identifier A user id or email + */ + public function findOneByIdentifier(string $identifier): ?User + { + return $this->createQueryBuilder('u') + ->andWhere('u.id = :val') + ->orWhere('u.email = :val') + ->setParameter('val', $identifier) + ->getQuery() + ->getOneOrNullResult(); + } }