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
120 lines
2.9 KiB
PHP
120 lines
2.9 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests\Customer;
|
|
|
|
use App\Models\Address;
|
|
use App\Rules\IdnEmail;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Illuminate\Validation\Rule;
|
|
|
|
class CustomerProfileRequest 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
|
|
{
|
|
return [
|
|
'name' => [
|
|
'nullable',
|
|
],
|
|
'password' => [
|
|
'nullable',
|
|
'min:8',
|
|
],
|
|
'email' => [
|
|
'nullable',
|
|
new IdnEmail,
|
|
Rule::unique('customers')->where('company_id', $this->header('company'))->ignore(Auth::id(), 'id'),
|
|
],
|
|
'billing.name' => [
|
|
'nullable',
|
|
],
|
|
'billing.address_street_1' => [
|
|
'nullable',
|
|
],
|
|
'billing.address_street_2' => [
|
|
'nullable',
|
|
],
|
|
'billing.city' => [
|
|
'nullable',
|
|
],
|
|
'billing.state' => [
|
|
'nullable',
|
|
],
|
|
'billing.country_id' => [
|
|
'nullable',
|
|
],
|
|
'billing.zip' => [
|
|
'nullable',
|
|
],
|
|
'billing.phone' => [
|
|
'nullable',
|
|
],
|
|
'billing.fax' => [
|
|
'nullable',
|
|
],
|
|
'shipping.name' => [
|
|
'nullable',
|
|
],
|
|
'shipping.address_street_1' => [
|
|
'nullable',
|
|
],
|
|
'shipping.address_street_2' => [
|
|
'nullable',
|
|
],
|
|
'shipping.city' => [
|
|
'nullable',
|
|
],
|
|
'shipping.state' => [
|
|
'nullable',
|
|
],
|
|
'shipping.country_id' => [
|
|
'nullable',
|
|
],
|
|
'shipping.zip' => [
|
|
'nullable',
|
|
],
|
|
'shipping.phone' => [
|
|
'nullable',
|
|
],
|
|
'shipping.fax' => [
|
|
'nullable',
|
|
],
|
|
'customer_avatar' => [
|
|
'nullable',
|
|
'file',
|
|
'mimes:gif,jpg,png',
|
|
'max:20000',
|
|
],
|
|
];
|
|
}
|
|
|
|
public function getShippingAddress()
|
|
{
|
|
return collect($this->shipping)
|
|
->merge([
|
|
'type' => Address::SHIPPING_TYPE,
|
|
])
|
|
->toArray();
|
|
}
|
|
|
|
public function getBillingAddress()
|
|
{
|
|
return collect($this->billing)
|
|
->merge([
|
|
'type' => Address::BILLING_TYPE,
|
|
])
|
|
->toArray();
|
|
}
|
|
}
|