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
0accceeafa
commit
4ea3baeb27
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();
|
||||
}
|
||||
}
|
||||
35
app/Mail/WithdrawalRequestReceived.php
Normal file
35
app/Mail/WithdrawalRequestReceived.php
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
namespace App\Mail;
|
||||
|
||||
use App\Models\WithdrawalRequest;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Mail\Mailable;
|
||||
use Illuminate\Mail\Mailables\Content;
|
||||
use Illuminate\Mail\Mailables\Envelope;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
/**
|
||||
* Sofortige automatische Eingangsbestätigung an den Verbraucher — gesetzlich
|
||||
* vorgeschrieben beim Online-Widerruf (Widerrufsbutton).
|
||||
*/
|
||||
class WithdrawalRequestReceived extends Mailable
|
||||
{
|
||||
use Queueable, SerializesModels;
|
||||
|
||||
public function __construct(
|
||||
public readonly WithdrawalRequest $withdrawalRequest,
|
||||
) {}
|
||||
|
||||
public function envelope(): Envelope
|
||||
{
|
||||
return new Envelope(
|
||||
subject: 'Eingangsbestätigung: Ihr Widerruf vom '.$this->withdrawalRequest->created_at->format('d.m.Y'),
|
||||
);
|
||||
}
|
||||
|
||||
public function content(): Content
|
||||
{
|
||||
return new Content(view: 'emails.withdrawal.received');
|
||||
}
|
||||
}
|
||||
34
app/Mail/WithdrawalRequestSubmitted.php
Normal file
34
app/Mail/WithdrawalRequestSubmitted.php
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
namespace App\Mail;
|
||||
|
||||
use App\Models\WithdrawalRequest;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Mail\Mailable;
|
||||
use Illuminate\Mail\Mailables\Content;
|
||||
use Illuminate\Mail\Mailables\Envelope;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
/**
|
||||
* Interne Benachrichtigung an den Betreiber über einen neuen Online-Widerruf.
|
||||
*/
|
||||
class WithdrawalRequestSubmitted extends Mailable
|
||||
{
|
||||
use Queueable, SerializesModels;
|
||||
|
||||
public function __construct(
|
||||
public readonly WithdrawalRequest $withdrawalRequest,
|
||||
) {}
|
||||
|
||||
public function envelope(): Envelope
|
||||
{
|
||||
return new Envelope(
|
||||
subject: 'Neuer Online-Widerruf #'.$this->withdrawalRequest->id.' über '.$this->withdrawalRequest->host,
|
||||
);
|
||||
}
|
||||
|
||||
public function content(): Content
|
||||
{
|
||||
return new Content(view: 'emails.withdrawal.submitted');
|
||||
}
|
||||
}
|
||||
35
app/Models/WithdrawalRequest.php
Normal file
35
app/Models/WithdrawalRequest.php
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* Online-Widerruf über den gesetzlichen Widerrufsbutton (ohne Login).
|
||||
* Enthält nur Zuordnungsdaten — ein Widerrufsgrund darf nicht erhoben werden.
|
||||
*/
|
||||
class WithdrawalRequest extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'email',
|
||||
'order_reference',
|
||||
'host',
|
||||
'requester_ip',
|
||||
'status',
|
||||
'resolved_at',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'resolved_at' => 'datetime',
|
||||
];
|
||||
}
|
||||
|
||||
public function scopeOpen(Builder $query): Builder
|
||||
{
|
||||
return $query->where('status', 'open');
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue