<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;

class ForzarCambioPassword
{
    public function handle(Request $request, Closure $next)
    {
        $user = auth()->user();

        if (
            auth()->check() &&
            $user->hasRole('Denunciante') &&
            $user->change_password == false &&
            !$request->routeIs('denunciante.password.cambiar') &&
            !$request->routeIs('denunciante.password.actualizar') &&
            !$request->routeIs('denunciante.logout')
        ) {
            return redirect()->route('denunciante.password.cambiar');
        }

        return $next($request);
    }
}