2026-08-31 12:05:37 +02:00
|
|
|
<?php
|
|
|
|
|
|
2026-08-31 12:40:30 +02:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
2026-08-31 12:05:37 +02:00
|
|
|
namespace App\Http\Requests;
|
|
|
|
|
|
2026-09-04 15:14:37 +02:00
|
|
|
use App\Enums\Country;
|
2026-08-31 12:05:37 +02:00
|
|
|
use App\Http\Requests\Concerns\HasEmailRateLimit;
|
2026-09-04 12:15:37 +02:00
|
|
|
use Illuminate\Contracts\Validation\Validator;
|
2026-08-31 12:05:37 +02:00
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
2026-09-04 15:14:37 +02:00
|
|
|
use Illuminate\Validation\Rule;
|
|
|
|
|
use Uwil\LaravelCommon\Helpers\ToolboxHelper;
|
2026-08-31 12:05:37 +02:00
|
|
|
|
|
|
|
|
class JoinGroupRequest extends FormRequest
|
|
|
|
|
{
|
|
|
|
|
use HasEmailRateLimit;
|
|
|
|
|
|
2026-09-04 15:14:37 +02:00
|
|
|
/** @var list<Country> */
|
|
|
|
|
private const ALLOWED_PHONE_COUNTRIES = [
|
|
|
|
|
Country::france,
|
|
|
|
|
Country::belgium,
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
/** @var list<string> */
|
|
|
|
|
private const COMMUNITIES = [
|
|
|
|
|
'amont',
|
|
|
|
|
'aval',
|
|
|
|
|
'transformateurs',
|
|
|
|
|
'scientifique',
|
|
|
|
|
'autres',
|
|
|
|
|
];
|
|
|
|
|
|
2026-08-31 12:05:37 +02:00
|
|
|
public function authorize(): bool
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-04 15:14:37 +02:00
|
|
|
#[\Override]
|
|
|
|
|
public function prepareForValidation(): void
|
|
|
|
|
{
|
|
|
|
|
$this->merge([
|
|
|
|
|
'supportsManifesto' => $this->boolean('supportsManifesto'),
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-31 12:05:37 +02:00
|
|
|
/**
|
|
|
|
|
* @return array<string, mixed>
|
|
|
|
|
*/
|
|
|
|
|
public function rules(): array
|
|
|
|
|
{
|
2026-09-02 17:14:01 +02:00
|
|
|
ToolboxHelper::validateRecaptcha($this);
|
2026-08-31 12:40:30 +02:00
|
|
|
|
2026-09-04 15:14:37 +02:00
|
|
|
$allowedIso2 = array_map(
|
|
|
|
|
static fn(Country $c): string => $c->iso2(),
|
|
|
|
|
self::ALLOWED_PHONE_COUNTRIES
|
|
|
|
|
);
|
|
|
|
|
|
2026-08-31 12:05:37 +02:00
|
|
|
return [
|
2026-09-04 15:14:37 +02:00
|
|
|
'lastName' => ['required', 'string', 'min:3', 'max:50'],
|
|
|
|
|
'firstName' => ['required', 'string', 'min:3', 'max:50'],
|
|
|
|
|
'email' => ['required', 'string', 'email:strict,rfc,spoof', 'max:255'],
|
|
|
|
|
'role' => ['required', 'string', 'min:3', 'max:30'],
|
|
|
|
|
'company' => ['required', 'string', 'min:3', 'max:60'],
|
|
|
|
|
'community' => ['required', 'string', Rule::in(self::COMMUNITIES)],
|
|
|
|
|
'phone' => ['required', 'phone:' . implode(',', $allowedIso2)],
|
|
|
|
|
'message' => ['required', 'string', 'min:30', 'max:255'],
|
|
|
|
|
'supportsManifesto' => ['boolean'],
|
|
|
|
|
'acceptsUsage' => ['required', 'accepted'],
|
2026-08-31 12:05:37 +02:00
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return array<string, string>
|
|
|
|
|
*/
|
2026-09-04 15:14:37 +02:00
|
|
|
#[\Override]
|
2026-08-31 12:05:37 +02:00
|
|
|
public function messages(): array
|
|
|
|
|
{
|
2026-09-04 15:14:37 +02:00
|
|
|
$phoneCountryLabels = implode(', ', array_map(
|
|
|
|
|
static fn(Country $country): string => $country->label('fr'),
|
|
|
|
|
self::ALLOWED_PHONE_COUNTRIES
|
|
|
|
|
));
|
|
|
|
|
|
2026-08-31 12:05:37 +02:00
|
|
|
return [
|
2026-09-08 09:52:16 +02:00
|
|
|
'community.in' => 'Veuillez sélectionner une communauté valide.',
|
|
|
|
|
'phone.phone' => "Le numéro de téléphone doit être un numéro valide pour : {$phoneCountryLabels}.",
|
|
|
|
|
'acceptsUsage.accepted' => "Vous devez accepter l'utilisation de vos données personnelles.",
|
|
|
|
|
'g-recaptcha-response.required' => 'Veuillez valider le reCAPTCHA.',
|
2026-09-04 15:14:37 +02:00
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[\Override]
|
|
|
|
|
public function attributes(): array
|
|
|
|
|
{
|
|
|
|
|
return [
|
2026-09-08 09:52:16 +02:00
|
|
|
'lastName' => 'nom',
|
|
|
|
|
'firstName' => 'prénom',
|
|
|
|
|
'email' => 'adresse e-mail',
|
|
|
|
|
'role' => 'fonction',
|
|
|
|
|
'company' => 'société',
|
|
|
|
|
'community' => 'communauté',
|
|
|
|
|
'phone' => 'numéro de téléphone',
|
|
|
|
|
'message' => 'message',
|
|
|
|
|
'supportsManifesto' => 'soutien au manifeste',
|
|
|
|
|
'acceptsUsage' => 'conditions d\'utilisation',
|
|
|
|
|
'g-recaptcha-response' => 'reCAPTCHA',
|
2026-08-31 12:05:37 +02:00
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function rateLimitPrefix(): string
|
|
|
|
|
{
|
|
|
|
|
return 'join-group';
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-04 15:14:37 +02:00
|
|
|
protected function rateLimitMaxAttempts(): int
|
|
|
|
|
{
|
|
|
|
|
return 3;
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-31 12:05:37 +02:00
|
|
|
protected function rateLimitMessageKey(): string
|
|
|
|
|
{
|
2026-09-04 15:14:37 +02:00
|
|
|
return 'validation.rate_limit.too_many_attempts';
|
2026-08-31 12:05:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function withValidator(Validator $validator): void
|
|
|
|
|
{
|
2026-09-04 15:14:37 +02:00
|
|
|
$validator->after(fn(Validator $v) => $this->applyEmailRateLimit($v));
|
2026-08-31 12:05:37 +02:00
|
|
|
}
|
|
|
|
|
}
|