Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR attempts to address the issue described in #145
That issue states the
Failed
event is not being dispatched when a user provides faulty credentials. From my assessment this happens when 2-Factor Auth is enabled, or when the developer uses theFortify::$authenticateUsingCallback
feature.Reason I found is the
Failed
event is only dispatched inside the\Illuminate\Auth\SessionGuard@attempt
method after a failed login attempt.As the
RedirectIfTwoFactorAuthenticatable
action is executed before theAttemptToAuthenticate
in the default Fortify's login pipeline, when a user provides faulty credentials the\Illuminate\Auth\SessionGuard@attempt
is not executed, and thus theFailed
event never gets dispatched.I added the code to dispatch the
Failed
event in 3 spots:AttemptToAuthenticate@handleUsingCustomCallback
method, as it skips using the\Illuminate\Auth\SessionGuard@attempt
, but later uses the guard's login method, so I thought in increased consistency.RedirectIfTwoFactorAuthenticatable@validateCredentials
inside the firstif
clause, when the developer configured aFortify::$authenticateUsingCallback
.RedirectIfTwoFactorAuthenticatable@validateCredentials
inside thereturn
callback, executed when the developer did NOT configured aFortify::$authenticateUsingCallback
.In the
RedirectIfTwoFactorAuthenticatable
action I considered dispatching theFailed
event from within thethrowFailedAuthenticationException
method. But I decided to keep it separated to increase consistency between theRedirectIfTwoFactorAuthenticatable
andAttemptToAuthenticate
actions code.Let me know if you prefer to have it consolidated inside that method.
As there no tests to assess the other events dispatched by Fortify (
Registered
,PasswordReset
,Lockout
, andVerified
events), I did not add tests for checking if theFailed
event gets dispatched.