46 lines
1.2 KiB
PHP
46 lines
1.2 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Http\Requests\Back;
|
||
|
|
|
||
|
|
use Illuminate\Foundation\Http\FormRequest;
|
||
|
|
use Illuminate\Support\Facades\Crypt;
|
||
|
|
use Illuminate\Validation\Rules\Enum;
|
||
|
|
|
||
|
|
class RetrieveDataFromTokenRequest extends FormRequest
|
||
|
|
{
|
||
|
|
/**
|
||
|
|
* Determine if the user is authorized to make this request.
|
||
|
|
*
|
||
|
|
* @return boolean
|
||
|
|
*/
|
||
|
|
public function authorize(): bool
|
||
|
|
{
|
||
|
|
return auth('backend')->check() and $this->ajax();
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Get the validation rules that apply to the request.
|
||
|
|
*
|
||
|
|
* @return array
|
||
|
|
*/
|
||
|
|
public function rules(): array
|
||
|
|
{
|
||
|
|
return [
|
||
|
|
'token' => [
|
||
|
|
'required',
|
||
|
|
'string',
|
||
|
|
function ($attribute, $value, $fail) {
|
||
|
|
try {
|
||
|
|
$payload = json_decode(Crypt::decryptString($value), true);
|
||
|
|
if (!is_array($payload) || !isset($payload['modelName'], $payload['modelId'])) {
|
||
|
|
$fail("Le {$attribute} est invalide.");
|
||
|
|
}
|
||
|
|
} catch (\Illuminate\Contracts\Encryption\DecryptException $e) {
|
||
|
|
$fail("Le {$attribute} est invalide.");
|
||
|
|
}
|
||
|
|
},
|
||
|
|
],
|
||
|
|
];
|
||
|
|
}
|
||
|
|
}
|