Files
Virtnet.bond/extensions/Others/ContactPage/Livewire/Abuse/AbuseForm.php
2025-11-30 11:57:22 +01:00

90 lines
2.8 KiB
PHP

<?php
namespace Paymenter\Extensions\Others\ContactPage\Livewire\Abuse;
use Livewire\Component;
use App\Traits\Captchable;
use Illuminate\Support\Facades\RateLimiter;
use Livewire\Attributes\Validate;
use Paymenter\Extensions\Others\ContactPage\Models\AbuseReport;
class AbuseForm extends Component
{
use Captchable;
#[Validate('required|string|max:255')]
public string $reporter_name = '';
#[Validate('required|email|max:255')]
public string $reporter_email = '';
#[Validate('required|string|in:spam,harassment,copyright,illegal_content,phishing,malware,other')]
public string $abuse_type = '';
#[Validate('nullable|url|max:500')]
public string $reported_url = '';
#[Validate('nullable|string|max:255')]
public string $reported_user = '';
#[Validate('required|string|min:20|max:2000')]
public string $description = '';
#[Validate('nullable|string|max:1000')]
public string $evidence = '';
public bool $submitted = false;
public function submit()
{
$this->validate();
$key = 'abuse-form:' . request()->ip();
if (RateLimiter::tooManyAttempts($key, 2)) {
$this->addError('description', 'Too many abuse reports. Please try again in 5 minutes.');
return;
}
RateLimiter::increment($key, 300);
try {
$abuseReport = AbuseReport::create([
'reporter_name' => $this->reporter_name,
'reporter_email' => $this->reporter_email,
'abuse_type' => $this->abuse_type,
'reported_url' => $this->reported_url,
'reported_user' => $this->reported_user,
'description' => $this->description,
'evidence' => $this->evidence,
'ip_address' => request()->ip(),
'user_agent' => request()->userAgent(),
]);
RateLimiter::clear($key);
$this->reset([
'reporter_name', 'reporter_email', 'abuse_type',
'reported_url', 'reported_user', 'description', 'evidence'
]);
$this->submitted = true;
session()->flash('success', 'Thank you for your report. We will investigate this matter promptly.');
} catch (\Exception $e) {
$this->addError('description', 'There was an error submitting your report. Please try again later.');
\Log::error('Abuse form error: ' . $e->getMessage());
}
}
public function getAbuseTypes()
{
return AbuseReport::getAbuseTypes();
}
public function render()
{
return view('contactpage::abuse-form', [
'abuseTypes' => $this->getAbuseTypes()
]);
}
}