31 lines
727 B
PHP
31 lines
727 B
PHP
<?php
|
|
|
|
namespace App\Actions\PasswordReset;
|
|
|
|
use App\Exceptions\UserNotFoundException;
|
|
use App\Models\User;
|
|
use App\Services\OTPService;
|
|
|
|
final readonly class SendOTPAction
|
|
{
|
|
public function __construct(
|
|
private OTPService $otpService,
|
|
private SendOTPToUserAction $otpToUserAction
|
|
) {}
|
|
|
|
/**
|
|
* @throws \Throwable
|
|
*/
|
|
public function execute(array $data): void
|
|
{
|
|
$user = User::where('email', $data['email'])->first();
|
|
throw_if(! $user, new UserNotFoundException('User not found'));
|
|
|
|
\Session::put('otp_user_id', $user->id);
|
|
$otp = $this->otpService->generate($user);
|
|
|
|
$this->otpToUserAction->execute(['user' => $user, 'otp' => $otp]);
|
|
|
|
}
|
|
}
|