dealhub/app/Actions/PasswordReset/VerifyOTPAction.php

31 lines
713 B
PHP

<?php
namespace App\Actions\PasswordReset;
use App\Exceptions\UserNotFoundException;
use App\Models\User;
use App\Services\OTPService;
final readonly class VerifyOTPAction
{
public function __construct(
private OTPService $otpService,
) {}
/**
* @throws \Throwable
*/
public function execute(array $data): bool
{
$user = \Session::get('otp_user_id') ? User::find(\Session::get('otp_user_id')) : null;
throw_if(! $user, new UserNotFoundException('User not found'));
$isVerified = $this->otpService->verify($user, $data['otp']);
if ($isVerified) {
\Session::forget('otp_user_id');
}
return $isVerified;
}
}