File tree Expand file tree Collapse file tree 2 files changed +18
-14
lines changed Expand file tree Collapse file tree 2 files changed +18
-14
lines changed Original file line number Diff line number Diff line change 77use Illuminate \Auth \Events \Logout ;
88use Illuminate \Foundation \Auth \User ;
99use Illuminate \Support \Facades \Cache ;
10- use Illuminate \Support \Facades \Session ;
1110
1211class 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 )
Original file line number Diff line number Diff line change 33namespace Chrysanthos \LaravelOtp \Support ;
44
55use Illuminate \Contracts \Auth \Authenticatable ;
6+ use Illuminate \Foundation \Auth \User ;
67use Illuminate \Support \Facades \Session ;
78
89class 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 );
You can’t perform that action at this time.
0 commit comments