3
3
namespace App \Http \Requests \Auth ;
4
4
5
5
use Illuminate \Foundation \Http \FormRequest ;
6
- use Illuminate \Support \Facades \Auth ;
7
- use Laravel \Fortify \Actions \DisableTwoFactorAuthentication ;
8
6
use Laravel \Fortify \Features ;
7
+ use Laravel \Fortify \InteractsWithTwoFactorState ;
9
8
10
9
class TwoFactorAuthenticationRequest extends FormRequest
11
10
{
11
+ use InteractsWithTwoFactorState;
12
+
12
13
/**
13
14
* Determine if the user is authorized to make this request.
14
15
*/
@@ -26,61 +27,4 @@ public function rules(): array
26
27
{
27
28
return [];
28
29
}
29
-
30
- /**
31
- * Validate the two-factor authentication state for the request.
32
- */
33
- public function validateState (): void
34
- {
35
- if (! Features::optionEnabled (Features::twoFactorAuthentication (), 'confirm ' )) {
36
- return ;
37
- }
38
-
39
- $ currentTime = time ();
40
-
41
- if ($ this ->twoFactorAuthenticationDisabled ()) {
42
- $ this ->session ()->put ('two_factor_empty_at ' , $ currentTime );
43
- }
44
-
45
- if ($ this ->hasJustBegunConfirmingTwoFactorAuthentication ()) {
46
- $ this ->session ()->put ('two_factor_confirming_at ' , $ currentTime );
47
- }
48
-
49
- if ($ this ->neverFinishedConfirmingTwoFactorAuthentication ($ currentTime )) {
50
- app (DisableTwoFactorAuthentication::class)(Auth::user ());
51
-
52
- $ this ->session ()->put ('two_factor_empty_at ' , $ currentTime );
53
- $ this ->session ()->remove ('two_factor_confirming_at ' );
54
- }
55
- }
56
-
57
- /**
58
- * Determine if two-factor authentication is totally disabled.
59
- */
60
- protected function twoFactorAuthenticationDisabled (): bool
61
- {
62
- return is_null ($ this ->user ()->two_factor_secret ) &&
63
- is_null ($ this ->user ()->two_factor_confirmed_at );
64
- }
65
-
66
- /**
67
- * Determine if two-factor authentication is being confirmed within the last request cycle.
68
- */
69
- protected function hasJustBegunConfirmingTwoFactorAuthentication (): bool
70
- {
71
- return ! is_null ($ this ->user ()->two_factor_secret ) &&
72
- is_null ($ this ->user ()->two_factor_confirmed_at ) &&
73
- $ this ->session ()->has ('two_factor_empty_at ' ) &&
74
- is_null ($ this ->session ()->get ('two_factor_confirming_at ' ));
75
- }
76
-
77
- /**
78
- * Determine if two-factor authentication was never totally confirmed once confirmation started.
79
- */
80
- protected function neverFinishedConfirmingTwoFactorAuthentication (int $ currentTime ): bool
81
- {
82
- return ! array_key_exists ('code ' , $ this ->session ()->getOldInput ()) &&
83
- is_null ($ this ->user ()->two_factor_confirmed_at ) &&
84
- $ this ->session ()->get ('two_factor_confirming_at ' , 0 ) != $ currentTime ;
85
- }
86
30
}
0 commit comments