You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've written a UserChecker to check for active user, and deleted account. If any of these issues happen, a CustomUserMessageAuthenticationException is thrown. With that there is specific message related to the issue. But extension always give a message of "Bad Credentials" when these exceptions are thrown. I need these detail messages to be in response. Please help.
/** * Class UserChecker * @package App\Security * * Validate username/email before authentication * Also make sure that the user is not deleted or inactive */class UserChecker implements UserCheckerInterface
{
/** * @var ValidatorInterface */private$validator;
/** * UserChecker constructor. * @param ValidatorInterface $validator */publicfunction__construct(ValidatorInterface$validator)
{
$this->validator = $validator;
}
/** * @param UserInterface $user */publicfunctioncheckPreAuth(UserInterface$user) : void
{
if (!$userinstanceof User) {
return;
}
$errors = $this->validator->validate($user);
if ($errors->count()) {
/* * Uses a __toString method on the $errors variable which is a * ConstraintViolationList object. This gives us a nice string * for debugging. *///$errorsString = (string) $errors;thrownewCustomUserMessageAuthenticationException(
$errors, [], 1
);
}
// user is deleted, show a generic Account Not Found message.if ($user->isDeleted()) {
//throw new AccountDeletedException('Account Deleted');// or to customize the message shownthrownewCustomUserMessageAuthenticationException(
'Your account was deleted. Sorry about that!', [],2
);
}
thrownewCustomUserMessageAuthenticationException(
'Your account is not active. Sorry about that!'
);
if (!$user->isActive()) {
//throw new AccountDeletedException('Account Not Active');// or to customize the message shownthrownewCustomUserMessageAuthenticationException(
'Your account is not active. Sorry about that!'
);
}
}
/** * @param UserInterface $user */publicfunctioncheckPostAuth(UserInterface$user) : void
{
if (!$userinstanceof User) {
return;
}
}
}
The text was updated successfully, but these errors were encountered:
…ustom exceptions (EresDev)
This PR was squashed before being merged into the 2.x-dev branch (closes#650).
Discussion
----------
Fixed AuthenticaionFailureHandler to utilize messages from custom exceptions
Fixed#588
Commits
-------
9414427 Fixed AuthenticaionFailureHandler to utilize messages from custom exceptions
I've written a UserChecker to check for active user, and deleted account. If any of these issues happen, a CustomUserMessageAuthenticationException is thrown. With that there is specific message related to the issue. But extension always give a message of "Bad Credentials" when these exceptions are thrown. I need these detail messages to be in response. Please help.
The text was updated successfully, but these errors were encountered: