. */ declare(strict_types=1); namespace FireflyIII\Http\Middleware; use Closure; use FireflyIII\User; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; use Session; /** * Class IsDemoUser. */ class IsDemoUser { /** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @param string[] ...$guards * * @return mixed */ public function handle(Request $request, Closure $next) { /** @var User $user */ $user = $request->user(); if (is_null($user)) { return $next($request); } if ($user->hasRole('demo')) { Session::flash('info', strval(trans('firefly.not_available_demo_user'))); redirect($request->session()->previousUrl()); return $next($request); } return $next($request); } }