@@ -58,13 +58,7 @@ public function verifyToken(VerifySMSToken $request)
58
58
return $ this ->sendTwoFactorAuthResponse ($ request );
59
59
}
60
60
61
- // If the two-factor authentication attempt was unsuccessful we will increment
62
- // the number of attempts to two-factor authenticate and redirect the user
63
- // back to the two-factor authentication form. Of course, when this user
64
- // surpasses their maximum number of attempts they will get locked out.
65
- $ this ->incrementTwoFactorAuthAttempts ($ request );
66
-
67
- return $ this ->sendFailedTwoFactorAuthResponse ($ request );
61
+ return $ this ->handleFailedAttempt ($ request );
68
62
}
69
63
70
64
/**
@@ -122,6 +116,49 @@ protected function authenticated(Request $request, $user)
122
116
//
123
117
}
124
118
119
+ /**
120
+ * Handle the case where a user has submitted an invalid token.
121
+ *
122
+ * Default: If the two-factor authentication attempt was unsuccessful we
123
+ * will increment the number of attempts to two-factor authenticate and
124
+ * redirect the user back to the two-factor authentication form. Of course,
125
+ * when this user surpasses their maximum number of attempts they will get
126
+ * locked out.
127
+ *
128
+ * @param \Illuminate\Http\Request $request
129
+ * @return \Illuminate\Http\Response
130
+ */
131
+ protected function handleFailedAttempt (Request $ request )
132
+ {
133
+ $ this ->incrementTwoFactorAuthAttempts ($ request );
134
+
135
+ if ($ path = $ this ->redirectAfterFailurePath ()) {
136
+ return redirect ()->to ($ path )->withErrors ([
137
+ 'token ' => __ ('twofactor-auth::twofactor-auth.failed ' )
138
+ ]);
139
+ }
140
+
141
+ return $ this ->sendFailedTwoFactorAuthResponse ($ request );
142
+ }
143
+
144
+ /**
145
+ * Get the post two-factor authentication failure redirect path.
146
+ *
147
+ * @return null|string
148
+ */
149
+ protected function redirectAfterFailurePath (): ?string
150
+ {
151
+ if (method_exists ($ this , 'redirectToAfterFailure ' )) {
152
+ return $ this ->redirectToAfterFailure ();
153
+ }
154
+
155
+ if (property_exists ($ this , 'redirectToAfterFailure ' )) {
156
+ return $ this ->redirectToAfterFailure ;
157
+ }
158
+
159
+ return null ;
160
+ }
161
+
125
162
/**
126
163
* Throw a validation exception when two-factor authentication attempt fails.
127
164
* NOTE: Throwing a validation exception is cleaner than redirecting, but
0 commit comments