Skip to content

Commit

Permalink
Dispatch event when OTP is resent
Browse files Browse the repository at this point in the history
  • Loading branch information
chrysanthos committed Apr 22, 2024
1 parent e9f4cc8 commit 63bc5bb
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 5 deletions.
28 changes: 28 additions & 0 deletions src/Events/OtpVerificationCodeResentEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace Chrysanthos\LaravelOtp\Events;

use Illuminate\Queue\SerializesModels;

class OtpVerificationCodeResentEvent
{
use SerializesModels;

/**
* The authenticated user.
*
* @var \Illuminate\Contracts\Auth\Authenticatable
*/
public $user;

/**
* Create a new event instance.
*
* @param \Illuminate\Contracts\Auth\Authenticatable $user
* @return void
*/
public function __construct($user)
{
$this->user = $user;
}
}
13 changes: 8 additions & 5 deletions src/Http/Controllers/OtpVerificationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand Down Expand Up @@ -62,6 +63,8 @@ public function resend()

$service->generateOtpAndSend($user);

event(new OtpVerificationCodeResentEvent($user));

return back()->with('status', 'The OTP has been resent.');
}
}

0 comments on commit 63bc5bb

Please sign in to comment.