em->createQuery(sprintf( 'SELECT u FROM %s u ' .'WHERE u.usernameCanonical = UNACCENT(LOWER(:pattern)) ' .'OR ' .'u.emailCanonical = UNACCENT(LOWER(:pattern))', User::class )) ->setParameter('pattern', $username) ->getSingleResult(); } catch (NoResultException $e) { throw new \Symfony\Component\Security\Core\Exception\UserNotFoundException('Bad credentials.', 0, $e); } return $user; } public function refreshUser(UserInterface $user): UserInterface { if (!$user instanceof User) { throw new UnsupportedUserException('Unsupported user class: cannot reload this user'); } $reloadedUser = $this->em->getRepository(User::class)->find($user->getId()); if (null === $reloadedUser) { throw new \Symfony\Component\Security\Core\Exception\UserNotFoundException(sprintf('User with ID "%s" could not be reloaded.', $user->getId())); } return $reloadedUser; } public function supportsClass($class): bool { return User::class === $class; } }