Skip to content

Conversation

@weaverryan
Copy link
Member

The idea is that this is easier and more self-documenting than teaching the user to translate the "Username could not be found." message.

// src/Security/LoginFormAuthenticator.php
// ...

public function getUser($credentials, UserProviderInterface $userProvider)
{
// ...

-   return $this->entityManager->getRepository(User::class)->findOneBy([
+   $user = $this->entityManager->getRepository(User::class)->findOneBy([
        'email' => $credentials['email'],
    ]);

+   if (!$user) {
+       // fail authentication with a custom error
+       throw new CustomUserMessageAuthenticationException('Email could not be found.');
+   }

+   return $user;
}

Cheers!

form

The idea is that this is easier and more self-documenting than teaching
the user to translate the "Username could not be found." message.
@weaverryan weaverryan merged commit 5f9fead into symfony:master Oct 4, 2018
weaverryan added a commit that referenced this pull request Oct 4, 2018
…e:auth login (weaverryan)

This PR was merged into the 1.0-dev branch.

Discussion
----------

Throwing CustomUserMessageAuthenticationException in make:auth login

The idea is that this is easier and more self-documenting than teaching the user to translate the "Username could not be found." message.

```diff
// src/Security/LoginFormAuthenticator.php
// ...

public function getUser($credentials, UserProviderInterface $userProvider)
{
// ...

-   return $this->entityManager->getRepository(User::class)->findOneBy([
+   $user = $this->entityManager->getRepository(User::class)->findOneBy([
        'email' => $credentials['email'],
    ]);

+   if (!$user) {
+       // fail authentication with a custom error
+       throw new CustomUserMessageAuthenticationException('Email could not be found.');
+   }

+   return $user;
}
```

Cheers!

Commits
-------

5f9fead Throwing CustomUserMessageAuthenticationException in make:auth login form
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant