diff --git a/cookbook/security/entity_provider.rst b/cookbook/security/entity_provider.rst index 57f5bb8fff1..0f36ceb0622 100644 --- a/cookbook/security/entity_provider.rst +++ b/cookbook/security/entity_provider.rst @@ -432,29 +432,18 @@ interface only requires one method: ``loadUserByUsername($username)``:: use Symfony\Bridge\Doctrine\Security\User\UserLoaderInterface; use Symfony\Component\Security\Core\User\UserInterface; - use Symfony\Component\Security\Core\Exception\UsernameNotFoundException; use Doctrine\ORM\EntityRepository; class UserRepository extends EntityRepository implements UserLoaderInterface { public function loadUserByUsername($username) { - $user = $this->createQueryBuilder('u') + return $this->createQueryBuilder('u') ->where('u.username = :username OR u.email = :email') ->setParameter('username', $username) ->setParameter('email', $username) ->getQuery() ->getOneOrNullResult(); - - if (null === $user) { - $message = sprintf( - 'Unable to find an active admin AppBundle:User object identified by "%s".', - $username - ); - throw new UsernameNotFoundException($message); - } - - return $user; } }