Merge branch '302-consent' into 'develop'
feat: ✨ add consent page
See merge request ldc-web/projets/le-gaulois!270
This commit is contained in:
commit
c389013a64
6 changed files with 153 additions and 0 deletions
44
app/Http/Controllers/Fo/ConsentController.php
Normal file
44
app/Http/Controllers/Fo/ConsentController.php
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Fo;
|
||||
|
||||
use App\Models\StaticPage;
|
||||
use App\Models\OptinConsent;
|
||||
use Illuminate\Http\Request;
|
||||
use LDC\LDCCRM\Models\SingleOptin;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Fo\ConsentRequest;
|
||||
use LDC\LDCCRM\Exceptions\CrmException;
|
||||
use LDC\LDCCRM\Exceptions\ApiErrorException;
|
||||
use LDC\LDCCRM\Exceptions\ValidationException;
|
||||
|
||||
class ConsentController extends Controller
|
||||
{
|
||||
/**
|
||||
* Check if a customer consent to receive newsletters.
|
||||
*
|
||||
* @param \App\Http\Requests\Fo\ConsentRequest $request
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
||||
* @throws \LDC\LDCCRM\Exceptions\ValidationException ValidationException.
|
||||
* @throws \LDC\LDCCRM\Exceptions\CrmException CrmException
|
||||
* @throws \LDC\LDCCRM\Exceptions\ApiErrorException ApiErrorException
|
||||
*/
|
||||
|
||||
public function consent(ConsentRequest $request): \Illuminate\Contracts\View\View
|
||||
{
|
||||
$isSubscribed = false;
|
||||
|
||||
if ($request->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'));
|
||||
}
|
||||
}
|
||||
21
app/Http/Requests/Fo/ConsentRequest.php
Normal file
21
app/Http/Requests/Fo/ConsentRequest.php
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests\Fo;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class ConsentRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'hashcode' => 'required|string|exists:optin_consents,hashcode',
|
||||
'action' => 'required|string|in:optin,noptin'
|
||||
];
|
||||
}
|
||||
}
|
||||
18
app/Models/OptinConsent.php
Normal file
18
app/Models/OptinConsent.php
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
|
||||
/**
|
||||
* @property string $email Email of the customer.
|
||||
* @property string $hashcode Hashcode of the customer.
|
||||
*/
|
||||
class OptinConsent extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'email',
|
||||
'hashcode',
|
||||
];
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('optin_consents', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('email')->unique();
|
||||
$table->string('hashcode')->unique();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('optin_consents');
|
||||
}
|
||||
};
|
||||
39
resources/views/fo/pages/newsletter-consent.blade.php
Normal file
39
resources/views/fo/pages/newsletter-consent.blade.php
Normal file
|
|
@ -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')
|
||||
<div class="container mt-5 pt-5 mb-3">
|
||||
<div class="row mb-5">
|
||||
<div @class([
|
||||
'col-6 mx-auto alert fw-medium text-center',
|
||||
'alert-danger' => !$isSubscribed,
|
||||
'alert-success' => $isSubscribed
|
||||
])>
|
||||
<p>
|
||||
@if($isSubscribed)
|
||||
{{ __('Vous êtes désormais inscrit à la newsletter Le Gaulois.') }}<br>
|
||||
{{ __('A bientôt !')}}
|
||||
@else
|
||||
{{ __('Vous n\'êtes pas inscrits à la newsletter Le Gaulois.') }}<br>
|
||||
{{ __('En espérant vous revoir bientôt !') }}
|
||||
@endif
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
use App\Http\Controllers\Fo\BreedingController;
|
||||
use App\Http\Controllers\Fo\BreederController;
|
||||
use App\Http\Controllers\Fo\ConsentController;
|
||||
use App\Http\Controllers\Fo\ContactController;
|
||||
use App\Http\Controllers\Fo\ExportController;
|
||||
use App\Http\Controllers\Fo\HomeController;
|
||||
|
|
@ -11,6 +12,7 @@ use App\Http\Controllers\Fo\RatingController;
|
|||
use App\Http\Controllers\Fo\RecipeController;
|
||||
use App\Http\Controllers\Fo\SearchController;
|
||||
use App\Http\Controllers\Fo\StaticPageController;
|
||||
use App\Models\StaticPage;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
Route::middleware(['throttle:web'])->name('fo.')->group(function () {
|
||||
|
|
@ -156,6 +158,7 @@ Route::middleware(['throttle:web'])->name('fo.')->group(function () {
|
|||
Route::get('/{unsubscribe}', [HomeController::class, 'unsubscribeNewsletter'])
|
||||
->where('unsubscribe', 'unsubscribe|unsubscribe.php|unsubscribe.html|newsletter')
|
||||
->name('unsubscribeNewsletter');
|
||||
Route::get('/newsletter/consent', [ConsentController::class, 'consent'])->name('newsletter.consent');
|
||||
|
||||
// * BREEDERS
|
||||
Route::prefix('breeders')
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue