Skip to content

Commit 541c2a4

Browse files
committed
wip
1 parent 7fc97b7 commit 541c2a4

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

src/Listeners/OtpListener.php

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use Illuminate\Auth\Events\Logout;
88
use Illuminate\Foundation\Auth\User;
99
use Illuminate\Support\Facades\Cache;
10-
use Illuminate\Support\Facades\Session;
1110

1211
class OtpListener
1312
{
@@ -20,19 +19,7 @@ public function generate(Login $event)
2019
return;
2120
}
2221

23-
$service = app(OtpService::class);
24-
25-
if (Session::get($key = $service->generateKey($user))) {
26-
return;
27-
}
28-
29-
$otp = $service->generateRandomOtp();
30-
31-
$service->storeOtpCode($key, $otp);
32-
33-
$class = config('otp.notification');
34-
35-
$user->notify(new $class($otp));
22+
app(OtpService::class)->generateOtpAndSend($user);
3623
}
3724

3825
public function clear(Logout $event)

src/Support/OtpService.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,27 @@
33
namespace Chrysanthos\LaravelOtp\Support;
44

55
use Illuminate\Contracts\Auth\Authenticatable;
6+
use Illuminate\Foundation\Auth\User;
67
use Illuminate\Support\Facades\Session;
78

89
class OtpService
910
{
11+
/**
12+
* @param User $user
13+
*
14+
* @return void
15+
*/
16+
public function generateOtpAndSend(User $user)
17+
{
18+
$otp = $this->generateRandomOtp();
19+
20+
$this->storeOtpCode($this->generateKey($user), $otp);
21+
22+
$class = config('otp.notification');
23+
24+
$user->notify(new $class($otp));
25+
}
26+
1027
public function generateRandomOtp(): int
1128
{
1229
return random_int(100001, 999999);

0 commit comments

Comments
 (0)