Remove some debug logging, use Facade.

This commit is contained in:
James Cole
2025-10-08 06:31:47 +02:00
parent 634a43c361
commit d91d30c8f0
2 changed files with 20 additions and 19 deletions

View File

@@ -49,14 +49,14 @@ class RemoteUserGuard implements Guard
{ {
/** @var null|Request $request */ /** @var null|Request $request */
$request = $app->get('request'); $request = $app->get('request');
Log::debug(sprintf('Created RemoteUserGuard for %s "%s"', $request?->getMethod(), $request?->getRequestUri())); // Log::debug(sprintf('Created RemoteUserGuard for %s "%s"', $request?->getMethod(), $request?->getRequestUri()));
$this->application = $app; $this->application = $app;
$this->user = null; $this->user = null;
} }
public function authenticate(): void public function authenticate(): void
{ {
Log::debug(sprintf('Now at %s', __METHOD__)); // Log::debug(sprintf('Now at %s', __METHOD__));
if ($this->user instanceof User) { if ($this->user instanceof User) {
Log::debug(sprintf('%s is found: #%d, "%s".', $this->user::class, $this->user->id, $this->user->email)); Log::debug(sprintf('%s is found: #%d, "%s".', $this->user::class, $this->user->id, $this->user->email));
@@ -104,21 +104,21 @@ class RemoteUserGuard implements Guard
public function check(): bool public function check(): bool
{ {
Log::debug(sprintf('Now at %s', __METHOD__)); // Log::debug(sprintf('Now at %s', __METHOD__));
return $this->user() instanceof User; return $this->user() instanceof User;
} }
public function guest(): bool public function guest(): bool
{ {
Log::debug(sprintf('Now at %s', __METHOD__)); // Log::debug(sprintf('Now at %s', __METHOD__));
return !$this->check(); return !$this->check();
} }
public function hasUser(): bool public function hasUser(): bool
{ {
Log::debug(sprintf('Now at %s', __METHOD__)); // Log::debug(sprintf('Now at %s', __METHOD__));
throw new FireflyException('Did not implement RemoteUserGuard::hasUser()'); throw new FireflyException('Did not implement RemoteUserGuard::hasUser()');
} }
@@ -128,14 +128,14 @@ class RemoteUserGuard implements Guard
*/ */
public function id(): int|string|null public function id(): int|string|null
{ {
Log::debug(sprintf('Now at %s', __METHOD__)); // Log::debug(sprintf('Now at %s', __METHOD__));
return $this->user?->id; return $this->user?->id;
} }
public function setUser(Authenticatable|User|null $user): void // @phpstan-ignore-line public function setUser(Authenticatable|User|null $user): void // @phpstan-ignore-line
{ {
Log::debug(sprintf('Now at %s', __METHOD__)); // Log::debug(sprintf('Now at %s', __METHOD__));
if ($user instanceof User) { if ($user instanceof User) {
$this->user = $user; $this->user = $user;
@@ -146,7 +146,7 @@ class RemoteUserGuard implements Guard
public function user(): ?User public function user(): ?User
{ {
Log::debug(sprintf('Now at %s', __METHOD__)); // Log::debug(sprintf('Now at %s', __METHOD__));
$user = $this->user; $user = $this->user;
if (!$user instanceof User) { if (!$user instanceof User) {
Log::debug('User is NULL'); Log::debug('User is NULL');
@@ -164,14 +164,14 @@ class RemoteUserGuard implements Guard
*/ */
public function validate(array $credentials = []): bool public function validate(array $credentials = []): bool
{ {
Log::debug(sprintf('Now at %s', __METHOD__)); // Log::debug(sprintf('Now at %s', __METHOD__));
throw new FireflyException('Did not implement RemoteUserGuard::validate()'); throw new FireflyException('Did not implement RemoteUserGuard::validate()');
} }
public function viaRemember(): bool public function viaRemember(): bool
{ {
Log::debug(sprintf('Now at %s', __METHOD__)); // Log::debug(sprintf('Now at %s', __METHOD__));
return false; return false;
} }

View File

@@ -25,6 +25,7 @@ declare(strict_types=1);
namespace FireflyIII\Support\System; namespace FireflyIII\Support\System;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Support\Facades\FireflyConfig;
use Illuminate\Contracts\Encryption\DecryptException; use Illuminate\Contracts\Encryption\DecryptException;
use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Crypt; use Illuminate\Support\Facades\Crypt;
@@ -63,10 +64,10 @@ class OAuthKeys
$privateKey = ''; $privateKey = '';
$publicKey = ''; $publicKey = '';
// better check if keys are in the database: // better check if keys are in the database:
if (app('fireflyconfig')->has(self::PRIVATE_KEY) && app('fireflyconfig')->has(self::PUBLIC_KEY)) { if (FireflyConfig::has(self::PRIVATE_KEY) && FireflyConfig::has(self::PUBLIC_KEY)) {
try { try {
$privateKey = (string)app('fireflyconfig')->get(self::PRIVATE_KEY)?->data; $privateKey = (string)FireflyConfig::get(self::PRIVATE_KEY)?->data;
$publicKey = (string)app('fireflyconfig')->get(self::PUBLIC_KEY)?->data; $publicKey = (string)FireflyConfig::get(self::PUBLIC_KEY)?->data;
} catch (ContainerExceptionInterface|FireflyException|NotFoundExceptionInterface $e) { } catch (ContainerExceptionInterface|FireflyException|NotFoundExceptionInterface $e) {
app('log')->error(sprintf('Could not validate keysInDatabase(): %s', $e->getMessage())); app('log')->error(sprintf('Could not validate keysInDatabase(): %s', $e->getMessage()));
app('log')->error($e->getTraceAsString()); app('log')->error($e->getTraceAsString());
@@ -87,8 +88,8 @@ class OAuthKeys
*/ */
public static function restoreKeysFromDB(): bool public static function restoreKeysFromDB(): bool
{ {
$privateKey = (string)app('fireflyconfig')->get(self::PRIVATE_KEY)?->data; $privateKey = (string)FireflyConfig::get(self::PRIVATE_KEY)?->data;
$publicKey = (string)app('fireflyconfig')->get(self::PUBLIC_KEY)?->data; $publicKey = (string)FireflyConfig::get(self::PUBLIC_KEY)?->data;
try { try {
$privateContent = Crypt::decrypt($privateKey); $privateContent = Crypt::decrypt($privateKey);
@@ -98,8 +99,8 @@ class OAuthKeys
app('log')->error($e->getMessage()); app('log')->error($e->getMessage());
// delete config vars from DB: // delete config vars from DB:
app('fireflyconfig')->delete(self::PRIVATE_KEY); FireflyConfig::delete(self::PRIVATE_KEY);
app('fireflyconfig')->delete(self::PUBLIC_KEY); FireflyConfig::delete(self::PUBLIC_KEY);
return false; return false;
} }
@@ -115,8 +116,8 @@ class OAuthKeys
{ {
$private = storage_path('oauth-private.key'); $private = storage_path('oauth-private.key');
$public = storage_path('oauth-public.key'); $public = storage_path('oauth-public.key');
app('fireflyconfig')->set(self::PRIVATE_KEY, Crypt::encrypt(file_get_contents($private))); FireflyConfig::set(self::PRIVATE_KEY, Crypt::encrypt(file_get_contents($private)));
app('fireflyconfig')->set(self::PUBLIC_KEY, Crypt::encrypt(file_get_contents($public))); FireflyConfig::set(self::PUBLIC_KEY, Crypt::encrypt(file_get_contents($public)));
} }
public static function verifyKeysRoutine(): void public static function verifyKeysRoutine(): void