resolveType($type); if (! $request->hasValidSignature()) { return view('web.email-unsubscribe', [ 'state' => 'invalid', 'notificationType' => $notificationType, ]); } $user->optOutOfEmailNotification($notificationType); return view('web.email-unsubscribe', [ 'state' => 'unsubscribed', 'notificationType' => $notificationType, 'resubscribeUrl' => URL::signedRoute('email-preferences.resubscribe', [ 'user' => $user->id, 'type' => $notificationType->value, ]), ]); } /** * RFC-8058-Endpunkt: Mail-Clients senden `List-Unsubscribe=One-Click` * per POST, ohne die Seite zu öffnen. Antwort bewusst schlicht (2xx). */ public function oneClickUnsubscribe(Request $request, User $user, string $type): Response { abort_unless($request->hasValidSignature(), 403); $user->optOutOfEmailNotification($this->resolveType($type)); return response('Sie wurden erfolgreich abgemeldet.'); } public function resubscribe(Request $request, User $user, string $type): View|RedirectResponse { abort_unless($request->hasValidSignature(), 403); $notificationType = $this->resolveType($type); $user->optIntoEmailNotification($notificationType); return view('web.email-unsubscribe', [ 'state' => 'resubscribed', 'notificationType' => $notificationType, ]); } private function resolveType(string $type): EmailNotificationType { $notificationType = EmailNotificationType::tryFrom($type); abort_if($notificationType === null, 404); return $notificationType; } }