mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Code cleanup
This commit is contained in:
@@ -39,9 +39,10 @@ trait GeneratesInstallationId
|
||||
protected function generateInstallationId(): void
|
||||
{
|
||||
try {
|
||||
$config = app('fireflyconfig')->get('installation_id', null);
|
||||
} catch(FireflyException $e) {
|
||||
$config = app('fireflyconfig')->get('installation_id', null);
|
||||
} catch (FireflyException $e) {
|
||||
Log::info('Could not create or generate installation ID. Do not continue.');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -52,7 +53,7 @@ trait GeneratesInstallationId
|
||||
|
||||
if (null === $config) {
|
||||
$uuid4 = Uuid::uuid4();
|
||||
$uniqueId = (string) $uuid4;
|
||||
$uniqueId = (string)$uuid4;
|
||||
Log::info(sprintf('Created Firefly III installation ID %s', $uniqueId));
|
||||
app('fireflyconfig')->set('installation_id', $uniqueId);
|
||||
}
|
||||
|
@@ -36,58 +36,6 @@ class OAuthKeys
|
||||
private const PRIVATE_KEY = 'oauth_private_key';
|
||||
private const PUBLIC_KEY = 'oauth_public_key';
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static function generateKeys(): void
|
||||
{
|
||||
Artisan::registerCommand(new KeysCommand());
|
||||
Artisan::call('passport:keys');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public static function hasKeyFiles(): bool
|
||||
{
|
||||
$private = storage_path('oauth-private.key');
|
||||
$public = storage_path('oauth-public.key');
|
||||
|
||||
return file_exists($private) && file_exists($public);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public static function keysInDatabase(): bool
|
||||
{
|
||||
return app('fireflyconfig')->has(self::PRIVATE_KEY) && app('fireflyconfig')->has(self::PUBLIC_KEY);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static function restoreKeysFromDB(): void
|
||||
{
|
||||
$privateContent = Crypt::decrypt(app('fireflyconfig')->get(self::PRIVATE_KEY)->data);
|
||||
$publicContent = Crypt::decrypt(app('fireflyconfig')->get(self::PUBLIC_KEY)->data);
|
||||
$private = storage_path('oauth-private.key');
|
||||
$public = storage_path('oauth-public.key');
|
||||
file_put_contents($private, $privateContent);
|
||||
file_put_contents($public, $publicContent);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static function storeKeysInDB(): void
|
||||
{
|
||||
$private = storage_path('oauth-private.key');
|
||||
$public = storage_path('oauth-public.key');
|
||||
app('fireflyconfig')->set(self::PRIVATE_KEY, Crypt::encrypt(file_get_contents($private)));
|
||||
app('fireflyconfig')->set(self::PUBLIC_KEY, Crypt::encrypt(file_get_contents($public)));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@@ -109,4 +57,56 @@ class OAuthKeys
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public static function keysInDatabase(): bool
|
||||
{
|
||||
return app('fireflyconfig')->has(self::PRIVATE_KEY) && app('fireflyconfig')->has(self::PUBLIC_KEY);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public static function hasKeyFiles(): bool
|
||||
{
|
||||
$private = storage_path('oauth-private.key');
|
||||
$public = storage_path('oauth-public.key');
|
||||
|
||||
return file_exists($private) && file_exists($public);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static function generateKeys(): void
|
||||
{
|
||||
Artisan::registerCommand(new KeysCommand());
|
||||
Artisan::call('passport:keys');
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static function storeKeysInDB(): void
|
||||
{
|
||||
$private = storage_path('oauth-private.key');
|
||||
$public = storage_path('oauth-public.key');
|
||||
app('fireflyconfig')->set(self::PRIVATE_KEY, Crypt::encrypt(file_get_contents($private)));
|
||||
app('fireflyconfig')->set(self::PUBLIC_KEY, Crypt::encrypt(file_get_contents($public)));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static function restoreKeysFromDB(): void
|
||||
{
|
||||
$privateContent = Crypt::decrypt(app('fireflyconfig')->get(self::PRIVATE_KEY)->data);
|
||||
$publicContent = Crypt::decrypt(app('fireflyconfig')->get(self::PUBLIC_KEY)->data);
|
||||
$private = storage_path('oauth-private.key');
|
||||
$public = storage_path('oauth-public.key');
|
||||
file_put_contents($private, $privateContent);
|
||||
file_put_contents($public, $publicContent);
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user