diff --git a/app/Http/Controllers/Fo/ConsentController.php b/app/Http/Controllers/Fo/ConsentController.php new file mode 100644 index 00000000..5ea42837 --- /dev/null +++ b/app/Http/Controllers/Fo/ConsentController.php @@ -0,0 +1,44 @@ +action === 'optin') { + try { + if ($optinToAdd = OptinConsent::query()->where('hashcode', $request->hashcode)->first()) { + SingleOptin::setStatus($optinToAdd->email, true); + $isSubscribed = true; + } + } catch (ValidationException | CrmException | ApiErrorException $e) { + report($e); + } + } + + return view('fo.pages.newsletter-consent', compact('isSubscribed')); + } +} diff --git a/app/Http/Requests/Fo/ConsentRequest.php b/app/Http/Requests/Fo/ConsentRequest.php new file mode 100644 index 00000000..c4c89a99 --- /dev/null +++ b/app/Http/Requests/Fo/ConsentRequest.php @@ -0,0 +1,21 @@ +|string> + */ + public function rules(): array + { + return [ + 'hashcode' => 'required|string|exists:optin_consents,hashcode', + 'action' => 'required|string|in:optin,noptin' + ]; + } +} diff --git a/app/Models/OptinConsent.php b/app/Models/OptinConsent.php new file mode 100644 index 00000000..acf691f1 --- /dev/null +++ b/app/Models/OptinConsent.php @@ -0,0 +1,18 @@ +id(); + $table->string('email')->unique(); + $table->string('hashcode')->unique(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('optin_consents'); + } +}; diff --git a/resources/views/fo/pages/newsletter-consent.blade.php b/resources/views/fo/pages/newsletter-consent.blade.php new file mode 100644 index 00000000..6c125d12 --- /dev/null +++ b/resources/views/fo/pages/newsletter-consent.blade.php @@ -0,0 +1,39 @@ +@php + $staticPageModel = new stdClass(); + $staticPageModel->title = __('Consentir à la newsletter'); + $staticPageModel->subtitle = ''; + $staticPageModel->description = __('Page de consentement à la newsletter du site le Gaulois'); + $staticPageModel->picture = null; + $staticPageModel->picture_title = ''; + $staticPageModel->picture_alt = ''; +@endphp + +@extends('fo.layout', ['brParam' => $staticPageModel]) +@section('title', $staticPageModel->title) +@section('description', $staticPageModel->description) +@section('breadcrumb', request()->route()->getName()) +@section('bg-offset', true) + +@section('content') + {{-- HEADER --}} + @include('fo.layouts.header-banner') +
+ @if($isSubscribed)
+ {{ __('Vous êtes désormais inscrit à la newsletter Le Gaulois.') }}
+ {{ __('A bientôt !')}}
+ @else
+ {{ __('Vous n\'êtes pas inscrits à la newsletter Le Gaulois.') }}
+ {{ __('En espérant vous revoir bientôt !') }}
+ @endif
+