Various code cleanup

This commit is contained in:
James Cole
2023-10-29 12:10:03 +01:00
parent 9a17a11b37
commit 5e32878d01
21 changed files with 87 additions and 77 deletions

View File

@@ -75,9 +75,9 @@ class HomeController extends Controller
// admin notification settings:
$notifications = [];
foreach (config('firefly.admin_notifications') as $item) {
$notifications[$item] = FireflyConfig::get(sprintf('notification_%s', $item), true)->data;
$notifications[$item] = app('fireflyconfig')->get(sprintf('notification_%s', $item), true)->data;
}
$slackUrl = FireflyConfig::get('slack_webhook_url', '')->data;
$slackUrl = app('fireflyconfig')->get('slack_webhook_url', '')->data;
return view('admin.index', compact('title', 'mainTitleIcon', 'email', 'notifications', 'slackUrl'));
}
@@ -94,14 +94,14 @@ class HomeController extends Controller
if ($request->has(sprintf('notification_%s', $item))) {
$value = true;
}
FireflyConfig::set(sprintf('notification_%s', $item), $value);
app('fireflyconfig')->set(sprintf('notification_%s', $item), $value);
}
$url = (string)$request->get('slackUrl');
if ('' === $url) {
FireflyConfig::delete('slack_webhook_url');
app('fireflyconfig')->delete('slack_webhook_url');
}
if (UrlValidator::isValidWebhookURL($url)) {
FireflyConfig::set('slack_webhook_url', $url);
app('fireflyconfig')->set('slack_webhook_url', $url);
}
session()->flash('success', (string)trans('firefly.notification_settings_saved'));

View File

@@ -61,7 +61,7 @@ class TwoFactorController extends Controller
public function submitMFA(Request $request)
{
/** @var array $mfaHistory */
$mfaHistory = Preferences::get('mfa_history', [])->data;
$mfaHistory = app('preferences')->get('mfa_history', [])->data;
$mfaCode = (string)$request->get('one_time_password');
// is in history? then refuse to use it.
@@ -127,7 +127,7 @@ class TwoFactorController extends Controller
private function filterMFAHistory(): void
{
/** @var array $mfaHistory */
$mfaHistory = Preferences::get('mfa_history', [])->data;
$mfaHistory = app('preferences')->get('mfa_history', [])->data;
$newHistory = [];
$now = time();
foreach ($mfaHistory as $entry) {
@@ -140,7 +140,7 @@ class TwoFactorController extends Controller
];
}
}
Preferences::set('mfa_history', $newHistory);
app('preferences')->set('mfa_history', $newHistory);
}
/**
@@ -149,14 +149,14 @@ class TwoFactorController extends Controller
private function addToMFAHistory(string $mfaCode): void
{
/** @var array $mfaHistory */
$mfaHistory = Preferences::get('mfa_history', [])->data;
$mfaHistory = app('preferences')->get('mfa_history', [])->data;
$entry = [
'time' => time(),
'code' => $mfaCode,
];
$mfaHistory[] = $entry;
Preferences::set('mfa_history', $mfaHistory);
app('preferences')->set('mfa_history', $mfaHistory);
$this->filterMFAHistory();
}
@@ -169,7 +169,7 @@ class TwoFactorController extends Controller
*/
private function isBackupCode(string $mfaCode): bool
{
$list = Preferences::get('mfa_recovery', [])->data;
$list = app('preferences')->get('mfa_recovery', [])->data;
if (in_array($mfaCode, $list, true)) {
return true;
}
@@ -184,8 +184,8 @@ class TwoFactorController extends Controller
*/
private function removeFromBackupCodes(string $mfaCode): void
{
$list = Preferences::get('mfa_recovery', [])->data;
$list = app('preferences')->get('mfa_recovery', [])->data;
$newList = array_values(array_diff($list, [$mfaCode]));
Preferences::set('mfa_recovery', $newList);
app('preferences')->set('mfa_recovery', $newList);
}
}

View File

@@ -201,7 +201,7 @@ class DebugController extends Controller
if (file_exists('/var/www/counter-main.txt')) {
$return['build'] = trim(file_get_contents('/var/www/counter-main.txt'));
}
} catch (Exception $e) { // generic catch for open basedir.
} catch (Exception $e) { // @phpstan-ignore-line
app('log')->debug('Could not check build counter, but thats ok.');
app('log')->warning($e->getMessage());
}
@@ -209,7 +209,7 @@ class DebugController extends Controller
if (file_exists('/var/www/build-date-main.txt')) {
$return['build_date'] = trim(file_get_contents('/var/www/build-date-main.txt'));
}
} catch (Exception $e) { // generic catch for open basedir.
} catch (Exception $e) { // @phpstan-ignore-line
app('log')->debug('Could not check build date, but thats ok.');
app('log')->warning($e->getMessage());
}

View File

@@ -67,6 +67,8 @@ class HomeController extends Controller
*/
public function dateRange(Request $request): JsonResponse
{
$stringStart = '';
$stringEnd = '';
try {
$stringStart = e((string)$request->get('start'));
$start = Carbon::createFromFormat('Y-m-d', $stringStart);

View File

@@ -84,7 +84,7 @@ class EditController extends Controller
$startDate = $piggyBank->startdate?->format('Y-m-d');
$currency = $this->accountRepository->getAccountCurrency($piggyBank->account);
if (null === $currency) {
$currency = Amount::getDefaultCurrency();
$currency = app('amount')->getDefaultCurrency();
}
$preFilled = [

View File

@@ -114,14 +114,14 @@ class ProfileController extends Controller
return redirect(route('profile.index'));
}
$domain = $this->getDomain();
$secretPreference = Preferences::get('temp-mfa-secret');
$codesPreference = Preferences::get('temp-mfa-codes');
$secretPreference = app('preferences')->get('temp-mfa-secret');
$codesPreference = app('preferences')->get('temp-mfa-codes');
// generate secret if not in session
if (null === $secretPreference) {
// generate secret + store + flash
$secret = Google2FA::generateSecretKey();
Preferences::set('temp-mfa-secret', $secret);
app('preferences')->set('temp-mfa-secret', $secret);
}
// re-use secret if in session
@@ -137,7 +137,7 @@ class ProfileController extends Controller
// generate codes + store + flash:
$recovery = app(Recovery::class);
$recoveryCodes = $recovery->lowercase()->setCount(8)->setBlocks(2)->setChars(6)->toArray();
Preferences::set('temp-mfa-codes', $recoveryCodes);
app('preferences')->set('temp-mfa-codes', $recoveryCodes);
}
// get codes from session if present already:
@@ -227,8 +227,8 @@ class ProfileController extends Controller
/** @var User $user */
$user = auth()->user();
Preferences::delete('temp-mfa-secret');
Preferences::delete('temp-mfa-codes');
app('preferences')->delete('temp-mfa-secret');
app('preferences')->delete('temp-mfa-codes');
$repository->setMFACode($user, null);
app('preferences')->mark();
@@ -498,12 +498,12 @@ class ProfileController extends Controller
$user = auth()->user();
/** @var UserRepositoryInterface $repository */
$repository = app(UserRepositoryInterface::class);
$secret = Preferences::get('temp-mfa-secret')?->data;
$secret = app('preferences')->get('temp-mfa-secret')?->data;
$repository->setMFACode($user, $secret);
Preferences::delete('temp-mfa-secret');
Preferences::delete('temp-mfa-codes');
app('preferences')->delete('temp-mfa-secret');
app('preferences')->delete('temp-mfa-codes');
session()->flash('success', (string)trans('firefly.saved_preferences'));
app('preferences')->mark();