Subversion-Projekte lars-tiefland.webanos.marine-sales.de

Revision

Revision 336 | Details | Vergleich mit vorheriger | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
322 lars 1
<?php
2
 
3
    namespace App\Http\Requests;
4
 
5
    use App\Models\BackendUser;
6
    use Illuminate\Foundation\Http\FormRequest;
338 lars 7
    use Illuminate\Support\Facades\Hash;
322 lars 8
    use Illuminate\Validation\Rule;
9
 
332 lars 10
    class StoreBackendUserRequest extends FormRequest
322 lars 11
    {
12
        /**
13
         * Determine if the user is authorized to make this request.
14
         *
15
         * @return bool
16
         */
17
        public function authorize(): bool
18
        {
19
            if ( $_SESSION["admin"]["uid"] == $this->user()->id || $_SESSION["admin"]["user"]->admin == 1 || isset( $GLOBALS["user_rechte"]["admin"]["admin"] ) )
20
            {
21
                return true;
22
            }
23
            return false;
24
        }
25
 
26
        /**
27
         * Get the validation rules that apply to the request.
28
         *
29
         * @return array<string, mixed>
30
         */
31
        public function rules(): array
32
        {
33
            return [
334 lars 34
                'password'          => 'bail|min:8|required|confirmed',
332 lars 35
                'email'             => 'bail|required|email|max:255', Rule::unique( BackendUser::class ),
322 lars 36
                'employee'          => 'integer|in:0,1',
37
                'rank'              => 'integer|min:0|max:500',
38
                'terminpflege'      => 'integer|in:0,1',
39
                'ignoreRemoteHosts' => 'integer|in:0,1',
40
                'description'       => 'sometimes',
41
                'phone'             => 'sometimes',
42
                'fax'               => 'sometimes',
43
                'save_session'      => 'integer|in:0,1',
44
                'app_user'          => 'integer|in:0,1',
45
            ];
46
        }
47
 
48
        protected function prepareForValidation(): void
49
        {
50
            $this->merge( [ "email" => $this->user . "@" . env( "shop" ) ] );
51
        }
332 lars 52
 
325 lars 53
        protected function passedValidation(): void
54
        {
55
            foreach ( $this as $key => $val )
56
            {
57
                if ( is_null( $val ) )
58
                {
59
                    $this->$key = "";
60
                }
335 lars 61
                elseif ( $key == "password" && $this->password )
62
                {
336 lars 63
                    $this->password = Hash::make( $this->password );
335 lars 64
                }
325 lars 65
            }
66
        }
322 lars 67
    }