From 63bc5bbb4c4604c45836d32e58e54f4012d18ca5 Mon Sep 17 00:00:00 2001 From: Chrysanthos Date: Mon, 22 Apr 2024 10:07:26 +0300 Subject: [PATCH] Dispatch event when OTP is resent --- src/Events/OtpVerificationCodeResentEvent.php | 28 +++++++++++++++++++ .../Controllers/OtpVerificationController.php | 13 +++++---- 2 files changed, 36 insertions(+), 5 deletions(-) create mode 100644 src/Events/OtpVerificationCodeResentEvent.php diff --git a/src/Events/OtpVerificationCodeResentEvent.php b/src/Events/OtpVerificationCodeResentEvent.php new file mode 100644 index 0000000..ef595c1 --- /dev/null +++ b/src/Events/OtpVerificationCodeResentEvent.php @@ -0,0 +1,28 @@ +user = $user; + } +} diff --git a/src/Http/Controllers/OtpVerificationController.php b/src/Http/Controllers/OtpVerificationController.php index 2f93be1..3f1698e 100644 --- a/src/Http/Controllers/OtpVerificationController.php +++ b/src/Http/Controllers/OtpVerificationController.php @@ -2,6 +2,7 @@ namespace Chrysanthos\LaravelOtp\Http\Controllers; +use Chrysanthos\LaravelOtp\Events\OtpVerificationCodeResentEvent; use Chrysanthos\LaravelOtp\Events\OtpVerificationFailedEvent; use Chrysanthos\LaravelOtp\Support\OtpService; use Illuminate\Foundation\Auth\User; @@ -28,11 +29,11 @@ public function send(Request $request) ]); $otp = $request->get('otp-code-1') - .$request->get('otp-code-2') - .$request->get('otp-code-3') - .$request->get('otp-code-4') - .$request->get('otp-code-5') - .$request->get('otp-code-6'); + . $request->get('otp-code-2') + . $request->get('otp-code-3') + . $request->get('otp-code-4') + . $request->get('otp-code-5') + . $request->get('otp-code-6'); /** @var User $user */ $user = auth()->user(); @@ -62,6 +63,8 @@ public function resend() $service->generateOtpAndSend($user); + event(new OtpVerificationCodeResentEvent($user)); + return back()->with('status', 'The OTP has been resent.'); } }