From b882d92328faceb3bb6be90fad840495d52b752f Mon Sep 17 00:00:00 2001 From: James Collins Date: Sun, 16 Nov 2025 23:08:34 +1000 Subject: [PATCH] fix timings --- app/Livewire/EmailSubscribe.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/app/Livewire/EmailSubscribe.php b/app/Livewire/EmailSubscribe.php index b4255f1..53858c3 100644 --- a/app/Livewire/EmailSubscribe.php +++ b/app/Livewire/EmailSubscribe.php @@ -36,20 +36,24 @@ class EmailSubscribe extends Component } // 2. Block submits in first 10 seconds after render - if (now()->timestamp - $this->renderedAt < 10) { + if (now()->timestamp - $this->renderedAt < 7) { $this->success = false; $this->message = 'That was a bit quick. Please wait a few seconds and try again.'; return; } // 3. Enforce 30 seconds between attempts per session - $lastAttempt = session('subscribe_last_attempt'); - if ($lastAttempt && now()->diffInSeconds($lastAttempt) < 30) { + $lastAttempt = session('subscribe_last_attempt'); // int timestamp or null + $now = time(); + + if ($lastAttempt && ($now - $lastAttempt) < 30) { + $remaining = 30 - ($now - $lastAttempt); $this->success = false; - $this->message = 'Please wait a little before trying again (' . now()->diffInSeconds($lastAttempt) . ')'; + $this->message = 'Please wait a little before trying again.'; return; } - session(['subscribe_last_attempt' => now()]); + + session(['subscribe_last_attempt' => $now]); // 4. Limit to 5 attempts per session (your existing logic) $attempts = session('subscribe_attempts', 0);