. */ declare(strict_types=1); namespace FireflyIII\Http\Middleware; use Closure; use FireflyIII\Exceptions\IsDemoUserException; use FireflyIII\User; use Illuminate\Http\Request; /** * Class IsDemoUser. */ class IsDemoUser { /** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * * @return mixed * @throws \RuntimeException */ public function handle(Request $request, Closure $next) { /** @var User $user */ $user = $request->user(); if (is_null($user)) { return $next($request); } if ($user->hasRole('demo')) { $request->session()->flash('info', strval(trans('firefly.not_available_demo_user'))); $current = $request->url(); $previous = $request->session()->previousUrl(); if ($current !== $previous) { return response()->redirectTo($previous); } return response()->redirectTo(route('index')); } return $next($request); } }