mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2026-05-03 20:56:21 +00:00
Code cleanup.
This commit is contained in:
@@ -24,7 +24,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Auth\AuthenticationException;
|
||||
@@ -38,17 +37,11 @@ class Authenticate
|
||||
{
|
||||
/**
|
||||
* The authentication factory instance.
|
||||
*
|
||||
* @var Auth
|
||||
*/
|
||||
protected Auth $auth;
|
||||
|
||||
/**
|
||||
* Create a new middleware instance.
|
||||
*
|
||||
* @param Auth $auth
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Auth $auth)
|
||||
{
|
||||
@@ -59,7 +52,6 @@ class Authenticate
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param Request $request
|
||||
* @param Closure $next
|
||||
* @param string[] ...$guards
|
||||
*
|
||||
* @return mixed
|
||||
@@ -67,7 +59,7 @@ class Authenticate
|
||||
* @throws FireflyException
|
||||
* @throws AuthenticationException
|
||||
*/
|
||||
public function handle($request, Closure $next, ...$guards)
|
||||
public function handle($request, \Closure $next, ...$guards)
|
||||
{
|
||||
$this->authenticate($request, $guards);
|
||||
|
||||
@@ -78,18 +70,19 @@ class Authenticate
|
||||
* Determine if the user is logged in to any of the given guards.
|
||||
*
|
||||
* @param mixed $request
|
||||
* @param array $guards
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
* @throws FireflyException
|
||||
* @throws AuthenticationException
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
protected function authenticate($request, array $guards)
|
||||
{
|
||||
if (0 === count($guards)) {
|
||||
// go for default guard:
|
||||
/** @noinspection PhpUndefinedMethodInspection */
|
||||
// @noinspection PhpUndefinedMethodInspection
|
||||
if ($this->auth->check()) {
|
||||
// do an extra check on user object.
|
||||
/** @noinspection PhpUndefinedMethodInspection */
|
||||
@@ -98,7 +91,7 @@ class Authenticate
|
||||
$this->validateBlockedUser($user, $guards);
|
||||
}
|
||||
|
||||
/** @noinspection PhpUndefinedMethodInspection */
|
||||
// @noinspection PhpUndefinedMethodInspection
|
||||
return $this->auth->authenticate();
|
||||
}
|
||||
|
||||
@@ -110,6 +103,7 @@ class Authenticate
|
||||
if ($result) {
|
||||
$user = $this->auth->guard($guard)->user();
|
||||
$this->validateBlockedUser($user, $guards);
|
||||
|
||||
// According to PHPstan the method returns void, but we'll see.
|
||||
return $this->auth->shouldUse($guard); // @phpstan-ignore-line
|
||||
}
|
||||
@@ -119,10 +113,6 @@ class Authenticate
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User|null $user
|
||||
* @param array $guards
|
||||
*
|
||||
* @return void
|
||||
* @throws AuthenticationException
|
||||
*/
|
||||
private function validateBlockedUser(?User $user, array $guards): void
|
||||
@@ -139,7 +129,7 @@ class Authenticate
|
||||
}
|
||||
app('log')->warning('User is blocked, cannot use authentication method.');
|
||||
app('session')->flash('logoutMessage', $message);
|
||||
/** @noinspection PhpUndefinedMethodInspection */
|
||||
// @noinspection PhpUndefinedMethodInspection
|
||||
$this->auth->logout(); // @phpstan-ignore-line (thinks function is undefined)
|
||||
|
||||
throw new AuthenticationException('Blocked account.', $guards);
|
||||
|
||||
Reference in New Issue
Block a user