Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 10 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
UpdateUserRequest | |
0.00% |
0 / 10 |
|
0.00% |
0 / 3 |
20 | |
0.00% |
0 / 1 |
authorize | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
failedAuthorization | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
rules | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace App\Http\Requests; |
4 | |
5 | use App\Http\Models\Auth\User; |
6 | use Illuminate\Validation\Rule; |
7 | use Illuminate\Foundation\Http\FormRequest; |
8 | use App\Http\Models\Admin\AdminUserInvitation; |
9 | use Illuminate\Auth\Access\AuthorizationException; |
10 | |
11 | class UpdateUserRequest extends FormRequest |
12 | { |
13 | /** |
14 | * Determine if the user is authorized to make this request. |
15 | */ |
16 | public function authorize(): bool |
17 | { |
18 | return User::where('_id', $this->user)->exists(); |
19 | } |
20 | |
21 | /** |
22 | * Handle a failed authorization attempt. |
23 | * |
24 | * |
25 | * @throws \Illuminate\Auth\Access\AuthorizationException |
26 | */ |
27 | protected function failedAuthorization(): void |
28 | { |
29 | $error = "Resource not found"; |
30 | |
31 | if (AdminUserInvitation::where('_id', $this->user)->exists()){ |
32 | $error = "This user has not signed up yet. Please try again later."; |
33 | } |
34 | |
35 | throw new AuthorizationException($error); |
36 | } |
37 | |
38 | /** |
39 | * Get the validation rules that apply to the request. |
40 | * |
41 | * @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string> |
42 | */ |
43 | public function rules(): array |
44 | { |
45 | return [ |
46 | 'first_name' => "required|string|max:12", |
47 | 'last_name' => "required|string|max:12", |
48 | 'email' => ['required', 'string', 'email', 'max:255', Rule::unique('users')->ignore($this->user, '_id')], |
49 | ]; |
50 | } |
51 | } |