cloud: marketing emails

This commit is contained in:
Andras Bacsai
2023-09-25 20:57:52 +02:00
parent cbf9bc99ea
commit a4320b7cee
8 changed files with 118 additions and 23 deletions

View File

@@ -1,5 +1,6 @@
<?php
use App\Models\User;
use Illuminate\Support\Facades\Route;
/*
@@ -16,3 +17,23 @@ use Illuminate\Support\Facades\Route;
Route::get('/health', function () {
return 'OK';
});
Route::middleware(['throttle:5'])->group(function () {
Route::get('/unsubscribe/{token}', function() {
try {
$token = request()->token;
$email = decrypt($token);
if (!User::whereEmail($email)->exists()) {
return redirect('/');
}
if (User::whereEmail($email)->first()->marketing_emails === false) {
return 'You have already unsubscribed from marketing emails.';
}
User::whereEmail($email)->update(['marketing_emails' => false]);
return 'You have been unsubscribed from marketing emails.';
} catch (\Throwable $e) {
return 'Something went wrong. Please try again or contact support.';
}
})->name('unsubscribe.marketing.emails');
});