69 lines
2 KiB
PHP
69 lines
2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests;
|
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
|
|
class EmployeePasswordChangeRequest extends FormRequest
|
|
{
|
|
/**
|
|
* Determine if the user is authorized to make this request.
|
|
*
|
|
* @return bool
|
|
*/
|
|
public function authorize()
|
|
{
|
|
return auth('employee')->check();
|
|
}
|
|
|
|
/**
|
|
* Get the validation rules that apply to the request.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function rules()
|
|
{
|
|
/** @var \App\Models\Employee */
|
|
$employee = auth('employee')->user();
|
|
return [
|
|
'password' => [
|
|
'required',
|
|
'string',
|
|
//phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed
|
|
function ($attribute, $value, $fail) use ($employee) {
|
|
if (
|
|
!auth('employee')->validate([
|
|
'matricule' => $employee->matricule,
|
|
'password' => $value
|
|
])
|
|
) {
|
|
$fail(trans('Votre ancien mot de passe est invalide'));
|
|
}
|
|
}
|
|
],
|
|
'newpassword' => [
|
|
'required',
|
|
'string',
|
|
'regex:/^(?=.*[A-Z])(?=.*[²&~"#\'\{\(\[\-|`_\\^@\)\°=+\}¨^$£¤%?,;.:\/!§*<>])(?=.*[0-9].*)(?=.*[a-z]).{8,}$/'
|
|
],
|
|
'newpasswordConfirm' => 'required|same:newpassword'
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Get the error messages for the defined validation rules.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function messages()
|
|
{
|
|
return [
|
|
'newpassword.regex' => trans("
|
|
Votre mot de passe doit être d'au moins 8 charactères,
|
|
il doit comporter au moins un caractère en majuscule,
|
|
un caractère en minuscule,
|
|
un nombre et
|
|
un caractère spécial parmis les suivants : ²&~\"#'{([-|`_\^@)°=+}¨^\$£¤%?,;.:\/!§*<>"),
|
|
];
|
|
}
|
|
}
|