Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
85.71% covered (warning)
85.71%
6 / 7
50.00% covered (danger)
50.00%
1 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
AdminSetPasswordRequest
85.71% covered (warning)
85.71%
6 / 7
50.00% covered (danger)
50.00%
1 / 2
3.03
0.00% covered (danger)
0.00%
0 / 1
 authorize
75.00% covered (warning)
75.00%
3 / 4
0.00% covered (danger)
0.00%
0 / 1
2.06
 rules
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3namespace App\Http\Requests\v2\User;
4
5use App\Http\Models\Auth\Role;
6use Illuminate\Foundation\Http\FormRequest;
7
8/**
9 * Request for force-setting a user's password (VENGRESO_ADMIN only).
10 *
11 * Does not require the user's current password. Only admins with the
12 * VENGRESO_ADMIN role are authorised to use this endpoint.
13 *
14 * @property string $password The new plain-text password
15 * @property string $password_confirmation Confirmation of the new password (must match)
16 */
17class AdminSetPasswordRequest extends FormRequest
18{
19    /**
20     * Determine if the user is authorized to make this request.
21     *
22     * Only users with the VENGRESO_ADMIN role may force-reset another user's password.
23     */
24    public function authorize(): bool
25    {
26        $user = $this->user();
27
28        if (! $user) {
29            return false;
30        }
31
32        return in_array(Role::VENGRESO_ADMIN, $user->roles());
33    }
34
35    /**
36     * Get the validation rules that apply to the request.
37     *
38     * @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
39     */
40    public function rules(): array
41    {
42        return [
43            'password' => 'required|string|min:8|confirmed',
44        ];
45    }
46}