mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
This commit is contained in:
@@ -30,6 +30,7 @@ use Illuminate\Contracts\Auth\Authenticatable;
|
||||
use Illuminate\Contracts\Auth\Guard;
|
||||
use Illuminate\Contracts\Auth\UserProvider;
|
||||
use Illuminate\Contracts\Foundation\Application;
|
||||
use Illuminate\Http\Request;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
@@ -50,26 +51,37 @@ class RemoteUserGuard implements Guard
|
||||
// @phpstan-ignore-next-line
|
||||
public function __construct(UserProvider $provider, Application $app) // @phpstan-ignore-line
|
||||
{
|
||||
/** @var Request $request */
|
||||
$request = $app->get('request');
|
||||
Log::debug(sprintf('Created RemoteUserGuard for "%s"', $request?->getRequestUri()));
|
||||
$this->application = $app;
|
||||
$this->provider = $provider;
|
||||
$this->user = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function viaRemember(): bool {
|
||||
Log::debug(sprintf('Now at %s', __METHOD__));
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function authenticate(): void
|
||||
{
|
||||
Log::debug(sprintf('Now at %s', __METHOD__));
|
||||
if (!is_null($this->user)) {
|
||||
Log::debug('User is found.');
|
||||
if (null !== $this->user) {
|
||||
Log::debug(sprintf('%s is found: #%d, "%s".', get_class($this->user), $this->user->id, $this->user->email));
|
||||
|
||||
return;
|
||||
}
|
||||
// Get the user identifier from $_SERVER or apache filtered headers
|
||||
$header = config('auth.guard_header', 'REMOTE_USER');
|
||||
$userID = request()->server($header) ?? apache_request_headers()[$header] ?? null;
|
||||
|
||||
$userID = 'james@firefly';
|
||||
if (null === $userID) {
|
||||
Log::error(sprintf('No user in header "%s".', $header));
|
||||
throw new FireflyException('The guard header was unexpectedly empty. See the logs.');
|
||||
@@ -103,6 +115,8 @@ class RemoteUserGuard implements Guard
|
||||
*/
|
||||
public function guest(): bool
|
||||
{
|
||||
Log::debug(sprintf('Now at %s', __METHOD__));
|
||||
$this->authenticate();
|
||||
return !$this->check();
|
||||
}
|
||||
|
||||
@@ -111,6 +125,8 @@ class RemoteUserGuard implements Guard
|
||||
*/
|
||||
public function check(): bool
|
||||
{
|
||||
Log::debug(sprintf('Now at %s', __METHOD__));
|
||||
$this->authenticate();
|
||||
return !is_null($this->user());
|
||||
}
|
||||
|
||||
@@ -119,6 +135,8 @@ class RemoteUserGuard implements Guard
|
||||
*/
|
||||
public function user(): ?User
|
||||
{
|
||||
Log::debug(sprintf('Now at %s', __METHOD__));
|
||||
$this->authenticate();
|
||||
return $this->user;
|
||||
}
|
||||
|
||||
@@ -127,6 +145,7 @@ class RemoteUserGuard implements Guard
|
||||
*/
|
||||
public function hasUser()
|
||||
{
|
||||
Log::debug(sprintf('Now at %s', __METHOD__));
|
||||
// TODO: Implement hasUser() method.
|
||||
}
|
||||
|
||||
@@ -135,6 +154,7 @@ class RemoteUserGuard implements Guard
|
||||
*/
|
||||
public function id(): ?User
|
||||
{
|
||||
Log::debug(sprintf('Now at %s', __METHOD__));
|
||||
return $this->user;
|
||||
}
|
||||
|
||||
@@ -143,6 +163,7 @@ class RemoteUserGuard implements Guard
|
||||
*/
|
||||
public function setUser(Authenticatable $user)
|
||||
{
|
||||
Log::debug(sprintf('Now at %s', __METHOD__));
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
@@ -151,6 +172,7 @@ class RemoteUserGuard implements Guard
|
||||
*/
|
||||
public function validate(array $credentials = [])
|
||||
{
|
||||
Log::debug(sprintf('Now at %s', __METHOD__));
|
||||
throw new FireflyException('Did not implement RemoteUserGuard::validate()');
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user