Filippo Bertilotti
2024-09-02 56f8c80f9a610c80810b24718340bc9cfd14df07
commit | author | age
ebf6bb 1 <?php
D 2
3 namespace App\Http\Requests;
4
5 use App\Rules\KeysiteCheck;
6 use App\Rules\TokenCheck;
7 use Illuminate\Contracts\Validation\Validator;
8 use Illuminate\Foundation\Http\FormRequest;
9 use Illuminate\Http\Exceptions\HttpResponseException;
10 use Illuminate\Validation\ValidationException;
11
12 class genericSSO extends FormRequest
13 {
14
15     public function attributes()
16     {
17         return [
18             'format' => 'formato',
19             'k' => 'keysite',
20         ];
21     }
22
23     /**
24      * Determine if the user is authorized to make this request.
25      *
26      * @return bool
27      */
28     public function authorize()
29     {
30         return true;
31     }
32
33     /**
34      * Get the validation rules that apply to the request.
35      *
36      * @return array<string, mixed>
37      */
38     public function rules()
39     {
40         return [
41             'format' => 'in:xml,json',
42             'k' => ['required', new KeysiteCheck( request()->headers->get('referer') )],
43             't' => [ new TokenCheck( request() ) ]
44         ];
45     }
46
47     public function messages()
48     {
49         return [
50             'required' => 'Il campo :attribute รจ obbligatorio',
51             'in' => 'Il campo :attribute dev\'essere valorizzato con: :values',
52         ];
53     }
54
55     protected function failedValidation(Validator $validator)
56     {
57         $errors = (new ValidationException($validator))->errors();
58         throw new HttpResponseException(
59             response($errors, 422)
60         );
61     }
62 }