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,17 +45,17 @@ class UserProvider implements UserProviderInterface
public function loadUserByUsername($username): UserInterface
{
$user = $this->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();
if (NULL === $user) {
throw new UsernameNotFoundException(sprintf('Username "%s" does not exist.', $username));
try {
$user = $this->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 (\Doctrine\ORM\NoResultException $e) {
throw new UsernameNotFoundException(sprintf('Bad credentials.', $username));
}
return $user;