48 lines
1.4 KiB
PHP
48 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests\Fo\Customers;
|
|
|
|
use App\Rules\CrmCustomerPassword;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Ldc\LDCCRM\Models\Customer as CrmCustomer;
|
|
|
|
class UpdateEmailRequest extends FormRequest
|
|
{
|
|
/**
|
|
* Determine if the user is authorized to make this request.
|
|
*
|
|
* @return boolean
|
|
*/
|
|
public function authorize()
|
|
{
|
|
return \auth('frontend')->check();
|
|
}
|
|
|
|
/**
|
|
* Get the validation rules that apply to the request.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function rules()
|
|
{
|
|
/** @var \Ldc\LDCCRM\Models\Customer */
|
|
$crmCustomer = \auth('frontend')->user()->api_data;
|
|
return [
|
|
'password' => [
|
|
'required',
|
|
new CrmCustomerPassword($crmCustomer)
|
|
],
|
|
'email' => [
|
|
'required', 'email:rfc,dns,spoof', 'max:255', 'unique:customers,email',
|
|
// * Does email already exists in CRM ?
|
|
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed
|
|
function (string $attribute, $value, \Closure $fail) {
|
|
if (CrmCustomer::findWithEmail(\strval($value))) {
|
|
$fail('Un compte existe déjà avec cette adresse.');
|
|
}
|
|
},
|
|
'unique:customers,email',
|
|
],
|
|
];
|
|
}
|
|
}
|