Skip to content

Firefly III: a personal finances manager

768 B
Raw Blame
<?php

declare(strict_types=1);

namespace FireflyIII\Http\Middleware;

use Closure;
use Illuminate\Auth\AuthenticationException;
use Illuminate\Http\Request;

class CatchBlockedUsers
{
    /**
     * Handle an incoming request.
     *
     * @param Request $request
     *
     * @return mixed
     *
     * @throws AuthenticationException
     */
    public function handle($request, Closure $next)
    {
        if (auth()->check()) {
            $user = auth()->user();
            if (null !== $user) {
                if (true === $user->blocked) {
                    throw new AuthenticationException(sprintf('User is not allowed to use the API ("%s")', $user->blocked_code));
                }
            }
        }

        return $next($request);
    }
}