- Magic-Link-Login übergibt bei aktiviertem 2FA an die 2FA-Challenge, statt sie zu umgehen (M1). - Bestätigungs-/Benachrichtigungs-Mails (Kontakt, Recht, Kündigung, Widerruf, Magic-Link) laufen als ShouldQueue+afterCommit über die Queue, damit die Response nicht am SMTP-Roundtrip hängt. Hinweis: Der Queue-Worker muss im Betrieb laufen und überwacht werden, da fristrelevante Bestätigungen darüber zugestellt werden (siehe Betriebsüberwachung). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
97 lines
3.6 KiB
PHP
97 lines
3.6 KiB
PHP
<?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)->queue(
|
|
(new WithdrawalRequestReceived($withdrawalRequest))->afterCommit()
|
|
);
|
|
Mail::to($this->operatorRecipient())->queue(
|
|
(new WithdrawalRequestSubmitted($withdrawalRequest))->afterCommit()
|
|
);
|
|
|
|
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();
|
|
}
|
|
}
|