28 lines
718 B
PHP
28 lines
718 B
PHP
<?php
|
|
|
|
namespace App\Services;
|
|
|
|
use App\Models\User;
|
|
use Illuminate\Support\Facades\RateLimiter;
|
|
use Throwable;
|
|
|
|
class AccountEmailService
|
|
{
|
|
public function sendVerification(User $user): void
|
|
{
|
|
if (! $user->needsEmailVerification()) {
|
|
return;
|
|
}
|
|
|
|
$key = 'email-verification:'.hash('sha256', strtolower($user->email));
|
|
RateLimiter::attempt($key, 1, function () use ($user): void {
|
|
try {
|
|
$user->sendEmailVerificationNotification();
|
|
} catch (Throwable $exception) {
|
|
// Registration is already committed; the user can request another email.
|
|
report($exception);
|
|
}
|
|
}, 60);
|
|
}
|
|
}
|