sending correct error if user does not exists

This commit is contained in:
Julien Fastré 2018-08-31 16:01:15 +02:00
parent 43edcfc416
commit 4be4ab3402

View File

@ -45,6 +45,7 @@ class UserProvider implements UserProviderInterface
public function loadUserByUsername($username): UserInterface public function loadUserByUsername($username): UserInterface
{ {
try {
$user = $this->em->createQuery(sprintf( $user = $this->em->createQuery(sprintf(
"SELECT u FROM %s u " "SELECT u FROM %s u "
. "WHERE u.usernameCanonical = UNACCENT(LOWER(:pattern)) " . "WHERE u.usernameCanonical = UNACCENT(LOWER(:pattern)) "
@ -53,9 +54,8 @@ class UserProvider implements UserProviderInterface
User::class)) User::class))
->setParameter('pattern', $username) ->setParameter('pattern', $username)
->getSingleResult(); ->getSingleResult();
} catch (\Doctrine\ORM\NoResultException $e) {
if (NULL === $user) { throw new UsernameNotFoundException(sprintf('Bad credentials.', $username));
throw new UsernameNotFoundException(sprintf('Username "%s" does not exist.', $username));
} }
return $user; return $user;