mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-29 18:20:01 +00:00
Merge branch 'develop' into 5.8-dev
# Conflicts: # app/Http/Middleware/Authenticate.php # app/Models/Account.php # app/Support/Authentication/RemoteUserGuard.php
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;
|
||||
|
||||
/**
|
||||
@@ -49,26 +50,40 @@ class RemoteUserGuard implements Guard
|
||||
*/
|
||||
public function __construct(UserProvider $provider, Application $app)
|
||||
{
|
||||
/** @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 = request()->server($header) ?? null;
|
||||
if (function_exists('apache_request_headers')) {
|
||||
$userID = request()->server($header) ?? apache_request_headers()[$header] ?? null;
|
||||
}
|
||||
if (null === $userID) {
|
||||
Log::error(sprintf('No user in header "%s".', $header));
|
||||
throw new FireflyException('The guard header was unexpectedly empty. See the logs.');
|
||||
@@ -102,6 +117,8 @@ class RemoteUserGuard implements Guard
|
||||
*/
|
||||
public function guest(): bool
|
||||
{
|
||||
Log::debug(sprintf('Now at %s', __METHOD__));
|
||||
$this->authenticate();
|
||||
return !$this->check();
|
||||
}
|
||||
|
||||
@@ -110,6 +127,8 @@ class RemoteUserGuard implements Guard
|
||||
*/
|
||||
public function check(): bool
|
||||
{
|
||||
Log::debug(sprintf('Now at %s', __METHOD__));
|
||||
$this->authenticate();
|
||||
return !is_null($this->user());
|
||||
}
|
||||
|
||||
@@ -118,6 +137,8 @@ class RemoteUserGuard implements Guard
|
||||
*/
|
||||
public function user(): ?User
|
||||
{
|
||||
Log::debug(sprintf('Now at %s', __METHOD__));
|
||||
$this->authenticate();
|
||||
return $this->user;
|
||||
}
|
||||
|
||||
@@ -126,7 +147,8 @@ class RemoteUserGuard implements Guard
|
||||
*/
|
||||
public function hasUser(): bool
|
||||
{
|
||||
throw new FireflyException(sprintf('%s is not implemented', __METHOD__));
|
||||
Log::debug(sprintf('Now at %s', __METHOD__));
|
||||
// TODO: Implement hasUser() method.
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -134,6 +156,7 @@ class RemoteUserGuard implements Guard
|
||||
*/
|
||||
public function id(): ?User
|
||||
{
|
||||
Log::debug(sprintf('Now at %s', __METHOD__));
|
||||
return $this->user;
|
||||
}
|
||||
|
||||
@@ -142,6 +165,7 @@ class RemoteUserGuard implements Guard
|
||||
*/
|
||||
public function setUser(Authenticatable $user)
|
||||
{
|
||||
Log::debug(sprintf('Now at %s', __METHOD__));
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
@@ -150,6 +174,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