dealhub/app/Actions/PasswordResetAction.php

25 lines
630 B
PHP

<?php
namespace App\Actions;
use App\Exceptions\UserNotFoundException;
use App\Models\User;
use App\Services\OTPService;
final readonly class PasswordResetAction
{
public function __construct(private SendPasswordResetMailAction $mailAction, private OTPService $otpService) {}
/**
* @throws \Throwable
*/
public function execute(array $data): void
{
$user = User::where('email', $data['email'])->first();
throw_if(! $user, new UserNotFoundException('User not found'));
$otp = $this->otpService->generate($user);
$this->mailAction->execute($user->email, $otp);
}
}