- Event-Medien tragen Typ (image/video/audio), Dauer und Notiz; Videos bekommen ein Poster, Audio wird per ffmpeg nach AAC (audio/mp4) gewandelt, Originale werden mit Range-Unterstützung gestreamt. - Upload nimmt eine Notiz (caption) direkt mit, PATCH ändert sie später. - Neue Event-Felder: Zeitraum (end_date), Kategorie, Personen, Meilenstein. Regeln zentral in EventFields, damit CRUD und Sync gleich prüfen. - Titel darf leer sein: ein Event entsteht mit dem ersten Eintrag. - Artisan-Befehl media:transcode-voice-notes wandelt alte WebM/Ogg-Notizen, die Safari nicht abspielen kann. - Login-Throttling, Settings-Validierung, Sync-Fehlercodes ohne Rohtext. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
88 lines
2.3 KiB
PHP
88 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests;
|
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Support\Facades\RateLimiter;
|
|
use Illuminate\Support\Str;
|
|
use Illuminate\Validation\ValidationException;
|
|
|
|
class LoginRequest extends FormRequest
|
|
{
|
|
/**
|
|
* Failed login attempts allowed per throttle key before locking out.
|
|
*/
|
|
private const MAX_ATTEMPTS = 5;
|
|
|
|
/**
|
|
* Lockout duration in seconds once the attempt limit is exceeded.
|
|
*/
|
|
private const DECAY_SECONDS = 60;
|
|
|
|
public function authorize(): bool
|
|
{
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Get the validation rules that apply to the request.
|
|
*
|
|
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
|
|
*/
|
|
public function rules(): array
|
|
{
|
|
return [
|
|
'email' => ['required', 'email'],
|
|
'password' => ['required', 'string'],
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Reject the request once too many failed attempts came from this
|
|
* identity/IP pair, before any password hash is ever computed.
|
|
*
|
|
* @throws ValidationException
|
|
*/
|
|
public function ensureIsNotRateLimited(): void
|
|
{
|
|
if (! RateLimiter::tooManyAttempts($this->throttleKey(), self::MAX_ATTEMPTS)) {
|
|
return;
|
|
}
|
|
|
|
$seconds = RateLimiter::availableIn($this->throttleKey());
|
|
|
|
throw ValidationException::withMessages([
|
|
'email' => __('auth.throttle', [
|
|
'seconds' => $seconds,
|
|
'minutes' => ceil($seconds / 60),
|
|
]),
|
|
])->status(429);
|
|
}
|
|
|
|
/**
|
|
* Record a failed attempt against this identity/IP pair.
|
|
*/
|
|
public function hitRateLimiter(): void
|
|
{
|
|
RateLimiter::hit($this->throttleKey(), self::DECAY_SECONDS);
|
|
}
|
|
|
|
/**
|
|
* Clear the counter after a successful login.
|
|
*/
|
|
public function clearRateLimiter(): void
|
|
{
|
|
RateLimiter::clear($this->throttleKey());
|
|
}
|
|
|
|
/**
|
|
* Throttle per normalised e-mail *and* IP, so one attacker cannot lock
|
|
* out an unrelated account and one IP cannot cycle through accounts.
|
|
*/
|
|
public function throttleKey(): string
|
|
{
|
|
return Str::transliterate(
|
|
'api-login|'.Str::lower((string) $this->input('email')).'|'.$this->ip()
|
|
);
|
|
}
|
|
}
|