Skip to content
This repository was archived by the owner on Apr 19, 2025. It is now read-only.

Commit 8db3779

Browse files
committed
Add an overrideable method to perform an action after completion of 2fa, fire event after completion of 2fa
1 parent acdb198 commit 8db3779

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace MichaelDzjap\TwoFactorAuth\Events;
4+
5+
use App\User;
6+
use Illuminate\Queue\SerializesModels;
7+
8+
class TwoFactorAuthenticated
9+
{
10+
use SerializesModels;
11+
12+
/**
13+
* The user instance.
14+
*
15+
* @var \App\User
16+
*/
17+
public $user;
18+
19+
/**
20+
* Create a new event instance.
21+
*
22+
* @param \App\User $user
23+
* @return void
24+
*/
25+
public function __construct(User $user)
26+
{
27+
$this->user = $user;
28+
}
29+
}

src/Http/Controllers/TwoFactorAuthenticatesUsers.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Illuminate\Http\Request;
88
use Illuminate\Validation\ValidationException;
99
use MichaelDzjap\TwoFactorAuth\Contracts\TwoFactorProvider;
10+
use MichaelDzjap\TwoFactorAuth\Events\TwoFactorAuthenticated;
1011
use MichaelDzjap\TwoFactorAuth\Exceptions\TokenAlreadyProcessedException;
1112
use MichaelDzjap\TwoFactorAuth\Exceptions\TokenExpiredException;
1213
use MichaelDzjap\TwoFactorAuth\Exceptions\TokenInvalidException;
@@ -100,7 +101,24 @@ protected function sendTwoFactorAuthResponse(Request $request)
100101

101102
$request->session()->forget('two-factor:auth');
102103

103-
return redirect()->intended($this->redirectPath());
104+
$user = $request->user();
105+
106+
event(new TwoFactorAuthenticated($user));
107+
108+
return $this->authenticated($request, $user)
109+
?: redirect()->intended($this->redirectPath());
110+
}
111+
112+
/**
113+
* The user has been two-factor authenticated.
114+
*
115+
* @param \Illuminate\Http\Request $request
116+
* @param mixed $user
117+
* @return mixed
118+
*/
119+
protected function authenticated(Request $request, $user)
120+
{
121+
//
104122
}
105123

106124
/**
@@ -109,6 +127,7 @@ protected function sendTwoFactorAuthResponse(Request $request)
109127
* we can only do it here because we don't need to redirect to the login route.
110128
*
111129
* @param \Illuminate\Http\Request $request
130+
*
112131
* @throws \Illuminate\Validation\ValidationException
113132
*/
114133
protected function sendFailedTwoFactorAuthResponse(Request $request)

0 commit comments

Comments
 (0)