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

Revision

Revision 334 | Revision 336 | Zur aktuellen Revision | Blame | Vergleich mit vorheriger | Letzte Änderung | Log anzeigen | RSS feed

<?php

    namespace App\Http\Requests;

    use App\Models\BackendUser;
    use Illuminate\Foundation\Http\FormRequest;
    use Illuminate\Validation\Rule;

    class StoreBackendUserRequest extends FormRequest
    {
        /**
         * Determine if the user is authorized to make this request.
         *
         * @return bool
         */
        public function authorize(): bool
        {
            if ( $_SESSION["admin"]["uid"] == $this->user()->id || $_SESSION["admin"]["user"]->admin == 1 || isset( $GLOBALS["user_rechte"]["admin"]["admin"] ) )
            {
                return true;
            }
            return false;
        }

        /**
         * Get the validation rules that apply to the request.
         *
         * @return array<string, mixed>
         */
        public function rules(): array
        {
            return [
                'password'          => 'bail|min:8|required|confirmed',
                'email'             => 'bail|required|email|max:255', Rule::unique( BackendUser::class ),
                'employee'          => 'integer|in:0,1',
                'rank'              => 'integer|min:0|max:500',
                'terminpflege'      => 'integer|in:0,1',
                'ignoreRemoteHosts' => 'integer|in:0,1',
                'description'       => 'sometimes',
                'phone'             => 'sometimes',
                'fax'               => 'sometimes',
                'save_session'      => 'integer|in:0,1',
                'app_user'          => 'integer|in:0,1',
            ];
        }

        protected function prepareForValidation(): void
        {
            $this->merge( [ "email" => $this->user . "@" . env( "shop" ) ] );
        }

        protected function passedValidation(): void
        {
            foreach ( $this as $key => $val )
            {
                if ( is_null( $val ) )
                {
                    $this->$key = "";
                }
                elseif ( $key == "password" && $this->password )
                {
                    $this->password = Hash::make( $this->password )
                }
            }
        }
    }