-
Notifications
You must be signed in to change notification settings - Fork 310
/
Copy pathConfirmTwoFactorAuthentication.php
52 lines (45 loc) · 1.44 KB
/
ConfirmTwoFactorAuthentication.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
namespace Laravel\Fortify\Actions;
use Illuminate\Validation\ValidationException;
use Laravel\Fortify\Contracts\TwoFactorAuthenticationProvider;
use Laravel\Fortify\Events\TwoFactorAuthenticationConfirmed;
class ConfirmTwoFactorAuthentication
{
/**
* The two factor authentication provider.
*
* @var \Laravel\Fortify\Contracts\TwoFactorAuthenticationProvider
*/
protected $provider;
/**
* Create a new action instance.
*
* @param \Laravel\Fortify\Contracts\TwoFactorAuthenticationProvider $provider
* @return void
*/
public function __construct(TwoFactorAuthenticationProvider $provider)
{
$this->provider = $provider;
}
/**
* Confirm the two factor authentication configuration for the user.
*
* @param mixed $user
* @param string $code
* @return void
*/
public function __invoke($user, $code)
{
if (empty($user->two_factor_secret) ||
empty($code) ||
! $this->provider->verify(decrypt($user->two_factor_secret), $code)) {
throw ValidationException::withMessages([
'code' => [__('The provided two factor authentication code was invalid.')],
])->errorBag('confirmTwoFactorAuthentication');
}
$user->forceFill([
'two_factor_confirmed_at' => now(),
])->save();
TwoFactorAuthenticationConfirmed::dispatch($user);
}
}