Recht: Online-Widerruf ohne Login (gesetzlicher Widerrufsbutton) - Backend
POST /widerruf (host-agnostisch, throttled, Honeypot, eigener withdrawal-Error-Bag): persistiert nur Zuordnungsdaten (Name, E-Mail, optionale Bestellnummer - KEIN Grund, darf nicht verlangt werden) und versendet sofort die gesetzlich vorgeschriebene automatische Eingangsbestaetigung mit Zeitstempel an den Verbraucher plus eine interne Benachrichtigung an die Brand-Kontaktadresse des Hosts. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
parent
47d03ec777
commit
8c0bf00604
9 changed files with 429 additions and 0 deletions
93
app/Http/Controllers/Web/WithdrawalController.php
Normal file
93
app/Http/Controllers/Web/WithdrawalController.php
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Web;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Mail\WithdrawalRequestReceived;
|
||||
use App\Mail\WithdrawalRequestSubmitted;
|
||||
use App\Models\WithdrawalRequest;
|
||||
use App\Support\WebPortalContext;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Illuminate\Support\Facades\RateLimiter;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
|
||||
/**
|
||||
* Online-Widerruf über den gesetzlichen Widerrufsbutton: ohne Login, nur
|
||||
* Zuordnungsdaten (Name, E-Mail, optional Bestellnummer) — ein Widerrufsgrund
|
||||
* darf nicht verlangt werden. Der Eingang wird sofort automatisch per E-Mail
|
||||
* bestätigt (dauerhafter Datenträger inkl. Zeitstempel) und persistiert.
|
||||
*/
|
||||
class WithdrawalController extends Controller
|
||||
{
|
||||
public function __invoke(Request $request): RedirectResponse
|
||||
{
|
||||
// Bot: ein ausgefülltes Honeypot-Feld → still und neutral abnicken,
|
||||
// bewusst VOR der Validierung (sonst verrät die Regel die Falle).
|
||||
if (filled($request->input('website')) || filled($request->input('homepage'))) {
|
||||
return $this->done();
|
||||
}
|
||||
|
||||
// Eigener Error-Bag, damit sich Widerrufs- und Kontakt-Modal auf
|
||||
// derselben Seite nicht gegenseitig öffnen.
|
||||
$validated = $request->validateWithBag('withdrawal', [
|
||||
'name' => ['required', 'string', 'max:255'],
|
||||
'email' => ['required', 'email', 'max:255'],
|
||||
'order_reference' => ['nullable', 'string', 'max:255'],
|
||||
]);
|
||||
|
||||
$this->ensureNotRateLimited($request);
|
||||
RateLimiter::hit($this->throttleKey($request), 3600);
|
||||
|
||||
$withdrawalRequest = WithdrawalRequest::query()->create([
|
||||
'name' => $validated['name'],
|
||||
'email' => $validated['email'],
|
||||
'order_reference' => $validated['order_reference'] ?? null,
|
||||
'host' => $request->getHost(),
|
||||
'requester_ip' => $request->ip(),
|
||||
]);
|
||||
|
||||
// Gesetzlich vorgeschrieben: sofortige automatische Eingangsbestätigung.
|
||||
Mail::to($withdrawalRequest->email)->send(new WithdrawalRequestReceived($withdrawalRequest));
|
||||
Mail::to($this->operatorRecipient())->send(new WithdrawalRequestSubmitted($withdrawalRequest));
|
||||
|
||||
return $this->done();
|
||||
}
|
||||
|
||||
private function done(): RedirectResponse
|
||||
{
|
||||
return back()->with('withdrawal-status', __('Ihr Widerruf ist bei uns eingegangen. Sie erhalten umgehend eine automatische Eingangsbestätigung per E-Mail.'));
|
||||
}
|
||||
|
||||
private function operatorRecipient(): string
|
||||
{
|
||||
if (str_contains(request()->getHost(), 'pressekonto')) {
|
||||
$brand = config('domains.domains.pressekonto.brand', []);
|
||||
} else {
|
||||
$brand = WebPortalContext::fromRequest()->domainConfig['brand'] ?? [];
|
||||
}
|
||||
|
||||
return $brand['contact_email'] ?? config('mail.from.address');
|
||||
}
|
||||
|
||||
private function ensureNotRateLimited(Request $request): void
|
||||
{
|
||||
if (! RateLimiter::tooManyAttempts($this->throttleKey($request), 5)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$seconds = RateLimiter::availableIn($this->throttleKey($request));
|
||||
|
||||
throw ValidationException::withMessages([
|
||||
'email' => __('Zu viele Anfragen. Bitte versuchen Sie es in :minutes Minuten erneut.', [
|
||||
'minutes' => max(1, (int) ceil($seconds / 60)),
|
||||
]),
|
||||
])->errorBag('withdrawal');
|
||||
}
|
||||
|
||||
private function throttleKey(Request $request): string
|
||||
{
|
||||
return 'withdrawal-form|'.$request->ip();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue