apertoAlle = now()->timestamp; } public function invia(RichiesteServizio $richieste): void { if ($this->sito !== '' || now()->timestamp - $this->apertoAlle < self::SECONDI_MINIMI) { $this->inviata = true; return; } $chiave = 'richiesta-pubblica:' . sha1((string) request()->ip()); if (RateLimiter::tooManyAttempts($chiave, self::MASSIMO_ORA)) { $this->addError('nome', "Hai già mandato diverse richieste: riprova fra un po'."); return; } $this->validate([ 'tipo' => 'required|in:' . Richiesta::NUOVO . ',' . Richiesta::RICONSEGNA, 'nome' => 'required|string|min:3|max:100', 'numero' => 'nullable|required_if:tipo,' . Richiesta::RICONSEGNA . '|string|max:20', 'note' => 'nullable|string|max:1000', ], [ 'nome.required' => 'Scrivi nome e cognome.', 'nome.min' => 'Scrivi nome e cognome.', 'numero.required_if' => 'Scrivi il numero del territorio che riconsegni.', ]); RateLimiter::hit($chiave, 3600); $richieste->registra($this->tipo, $this->nome, $this->numero, $this->note); $this->reset(['nome', 'numero', 'note']); $this->inviata = true; } public function nuova(): void { $this->reset(['tipo', 'nome', 'numero', 'note', 'inviata']); $this->apertoAlle = now()->timestamp; } public function render() { return view('livewire.richieste.modulo-richiesta', [ 'congregazione' => Setting::instance()->congregazione_nome ?: 'TerManager2', ])->layout('components.layouts.guest', ['title' => 'Richiesta territorio']); } }