Skip to content

Commit

Permalink
removed unnecesary exception form repository
Browse files Browse the repository at this point in the history
removed `UsernameNotFoundException` form repository as this logic does not belong to repository and also it is duplicated. exception is already thrown on proper place if no user is found:
https://github.com/symfony/symfony/blob/master/src/Symfony/Bridge/Doctrine/Security/User/EntityUserProvider.php#L60
  • Loading branch information
gondo authored and xabbuh committed Feb 6, 2016
1 parent ab57eed commit 0e288a2
Showing 1 changed file with 1 addition and 12 deletions.
13 changes: 1 addition & 12 deletions cookbook/security/entity_provider.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down

0 comments on commit 0e288a2

Please sign in to comment.