mirror of
https://github.com/InvoiceShelf/InvoiceShelf.git
synced 2026-04-15 17:24:10 +00:00
Add IdnEmail validation rule that converts IDN domains to Punycode via idn_to_ascii() before validating with FILTER_VALIDATE_EMAIL. Applied to all email fields: customers, members, profiles, admin users, customer portal profiles, and mail configuration. Includes unit tests for standard emails, IDN emails, and invalid inputs. Fixes #388
75 lines
1.6 KiB
PHP
75 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests;
|
|
|
|
use App\Rules\IdnEmail;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Validation\Rule;
|
|
|
|
class MemberRequest extends FormRequest
|
|
{
|
|
/**
|
|
* Determine if the user is authorized to make this request.
|
|
*/
|
|
public function authorize(): bool
|
|
{
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Get the validation rules that apply to the request.
|
|
*/
|
|
public function rules(): array
|
|
{
|
|
$rules = [
|
|
'name' => [
|
|
'required',
|
|
],
|
|
'email' => [
|
|
'required',
|
|
new IdnEmail,
|
|
Rule::unique('users'),
|
|
],
|
|
'phone' => [
|
|
'nullable',
|
|
],
|
|
'password' => [
|
|
'required',
|
|
'min:8',
|
|
],
|
|
'companies' => [
|
|
'required',
|
|
],
|
|
'companies.*.id' => [
|
|
'required',
|
|
],
|
|
'companies.*.role' => [
|
|
'required',
|
|
],
|
|
];
|
|
|
|
if ($this->getMethod() == 'PUT') {
|
|
$rules['email'] = [
|
|
'required',
|
|
new IdnEmail,
|
|
Rule::unique('users')->ignore($this->user),
|
|
];
|
|
$rules['password'] = [
|
|
'nullable',
|
|
'min:8',
|
|
];
|
|
}
|
|
|
|
return $rules;
|
|
}
|
|
|
|
public function getUserPayload()
|
|
{
|
|
return collect($this->validated())
|
|
->merge([
|
|
'creator_id' => $this->user()->id,
|
|
])
|
|
->toArray();
|
|
}
|
|
}
|