. */ declare(strict_types=1); namespace FireflyIII\Http\Middleware; use Closure; use FireflyIII\Repositories\User\UserRepositoryInterface; use FireflyIII\User; use Illuminate\Http\Request; use Log; /** * Class IsDemoUser. */ class IsDemoUser { /** * Handle an incoming request. * * @param Request $request * @param Closure $next * * @return mixed */ public function handle(Request $request, Closure $next) { /** @var User $user */ $user = $request->user(); if (null === $user) { return $next($request); } /** @var UserRepositoryInterface $repository */ $repository = app(UserRepositoryInterface::class); if ($repository->hasRole($user, 'demo')) { Log::info('User is a demo user.'); $request->session()->flash('info', (string) 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')); // @codeCoverageIgnore } return $next($request); } }