diff --git a/app/Livewire/EmailSubscribe.php b/app/Livewire/EmailSubscribe.php new file mode 100644 index 0000000..36bc8b6 --- /dev/null +++ b/app/Livewire/EmailSubscribe.php @@ -0,0 +1,76 @@ + 'required|email|max:255', + ]; + + public function subscribe(): void + { + // Honeypot - if this hidden field is filled, treat as success but do nothing + if (! empty($this->trap)) { + $this->reset(['email', 'trap']); + $this->success = true; + $this->message = 'Thanks, you have been subscribed to our newsletter.'; + return; + } + + // Simple rate limiting per session + $attempts = session('subscribe_attempts', 0); + if ($attempts >= 5) { + $this->success = false; + $this->message = 'Too many attempts. Please try again in a little while.'; + return; + } + session(['subscribe_attempts' => $attempts + 1]); + + + $this->validate(); + + // Look up existing subscription by email + $subscription = EmailSubscriptions::where('email', $this->email)->first(); + + // If already confirmed, do not create a new record or resend confirmation + if ($subscription && $subscription->confirmed) { + // Optionally you could set a different flag or message here + $this->success = false; + $this->message = 'That email is already subscribed to our newsletter.'; + } else { + // If no subscription exists, create a new unconfirmed one + if (!$subscription) { + $subscription = EmailSubscriptions::create([ + 'email' => $this->email, + 'confirmed' => Carbon::now() + ]); + + $subscription->save(); + } + + dispatch(new SendEmail($subscription->email, new UserWelcome($subscription->email)))->onQueue('mail'); + + $this->success = true; + $this->message = 'Thanks, you have been subscribed to our newsletter.'; + } + + $this->reset(['email', 'trap']); + } + + public function render() + { + return view('livewire.email-subscribe'); + } +} diff --git a/public/about.webp b/public/about.webp new file mode 100644 index 0000000..ff7bf86 Binary files /dev/null and b/public/about.webp differ diff --git a/resources/views/livewire/email-subscribe.blade.php b/resources/views/livewire/email-subscribe.blade.php new file mode 100644 index 0000000..07f338f --- /dev/null +++ b/resources/views/livewire/email-subscribe.blade.php @@ -0,0 +1,39 @@ +
+
+ + + + + {{-- Submit button --}} + + Subscribe + + + + @if($message) + @if($success) +

+ {{ $message }} +

+ @else +

+ {{ $message }} +

+ @endif + @endif +
\ No newline at end of file