Skip to content

Commit b06c25f

Browse files
committed
Add a Listener to login via remember
1 parent e355281 commit b06c25f

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

src/Listeners/LoginViaRemember.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
namespace PragmaRX\Google2FALaravel\Listeners;
4+
5+
use Illuminate\Auth\Events\Login;
6+
use Illuminate\Support\Facades\Auth;
7+
use Illuminate\Contracts\Auth\Authenticatable as User;
8+
use PragmaRX\Google2FALaravel\Facade as Google2FA;
9+
10+
class LoginViaRemember
11+
{
12+
/**
13+
* Handle the event.
14+
*
15+
* @param \Illuminate\Auth\Events\Login $event
16+
* @return void
17+
*/
18+
public function handle(Login $event)
19+
{
20+
if (Auth::viaRemember()) {
21+
$this->registerGoogle2fa($event->user);
22+
}
23+
}
24+
25+
/**
26+
* Force register Google2fa login.
27+
*
28+
* @param User $user
29+
*/
30+
private function registerGoogle2fa(User $user)
31+
{
32+
$secret = $user->{Google2FA::config('otp_secret_column')};
33+
34+
if (!is_null($secret) && !empty($secret)) {
35+
Google2FA::login();
36+
}
37+
}
38+
}

0 commit comments

Comments
 (0)