mirror of
https://github.com/solidtime-io/solidtime.git
synced 2026-08-09 00:32:15 +01:00
49 lines
1.2 KiB
PHP
49 lines
1.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Http\Requests\V1\User;
|
|
|
|
use App\Http\Requests\V1\BaseFormRequest;
|
|
use Illuminate\Support\Facades\Hash;
|
|
use Illuminate\Validation\Validator;
|
|
|
|
class UserDestroyRequest extends BaseFormRequest
|
|
{
|
|
/**
|
|
* Get the validation rules that apply to the request.
|
|
*
|
|
* @return array<string, array<string>>
|
|
*/
|
|
public function rules(): array
|
|
{
|
|
return [
|
|
'password' => [
|
|
'required',
|
|
'string',
|
|
],
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @return array<int, callable(Validator): void>
|
|
*/
|
|
public function after(): array
|
|
{
|
|
return [
|
|
function (Validator $validator): void {
|
|
if ($validator->errors()->has('password')) {
|
|
return;
|
|
}
|
|
|
|
$user = $this->user();
|
|
$password = $this->input('password');
|
|
|
|
if (! is_string($password) || $user === null || ! Hash::check($password, (string) $user->password)) {
|
|
$validator->errors()->add('password', __('The password is incorrect.'));
|
|
}
|
|
},
|
|
];
|
|
}
|
|
}
|