From 9c6682e7edf8cbad828088cbeeef66c7ecefdd9a Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Sat, 2 Jan 2021 21:20:19 +0100 Subject: Avoid manual initialisations of system or user configuration (#3070) * Avoid manual intialisations of system or user configuration More consistent use of Context * Simplify FreshRSS_Context::initUser * Remove a few manual get_user_configuration * A bit of debugging * Fix context user init * Fix install * Fix concurrency Concurrent requests could lead to bad race condition * Fix actualize cron Fix case when system i initialised several times --- app/Models/FormAuth.php | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'app/Models/FormAuth.php') diff --git a/app/Models/FormAuth.php b/app/Models/FormAuth.php index 86742e2f2..1aca7c3d1 100644 --- a/app/Models/FormAuth.php +++ b/app/Models/FormAuth.php @@ -24,8 +24,7 @@ class FreshRSS_FormAuth { $token_file = DATA_PATH . '/tokens/' . $token . '.txt'; $mtime = @filemtime($token_file); - $conf = Minz_Configuration::get('system'); - $limits = $conf->limits; + $limits = FreshRSS_Context::$system_conf->limits; $cookie_duration = empty($limits['cookie_duration']) ? FreshRSS_Auth::DEFAULT_COOKIE_DURATION : $limits['cookie_duration']; if ($mtime + $cookie_duration < time()) { // Token has expired (> cookie_duration) or does not exist. @@ -43,8 +42,7 @@ class FreshRSS_FormAuth { private static function renewCookie($token) { $token_file = DATA_PATH . '/tokens/' . $token . '.txt'; if (touch($token_file)) { - $conf = Minz_Configuration::get('system'); - $limits = $conf->limits; + $limits = FreshRSS_Context::$system_conf->limits; $cookie_duration = empty($limits['cookie_duration']) ? FreshRSS_Auth::DEFAULT_COOKIE_DURATION : $limits['cookie_duration']; $expire = time() + $cookie_duration; Minz_Session::setLongTermCookie('FreshRSS_login', $token, $expire); @@ -54,9 +52,8 @@ class FreshRSS_FormAuth { } public static function makeCookie($username, $password_hash) { - $conf = Minz_Configuration::get('system'); do { - $token = sha1($conf->salt . $username . uniqid(mt_rand(), true)); + $token = sha1(FreshRSS_Context::$system_conf->salt . $username . uniqid(mt_rand(), true)); $token_file = DATA_PATH . '/tokens/' . $token . '.txt'; } while (file_exists($token_file)); @@ -80,8 +77,7 @@ class FreshRSS_FormAuth { } public static function purgeTokens() { - $conf = Minz_Configuration::get('system'); - $limits = $conf->limits; + $limits = FreshRSS_Context::$system_conf->limits; $cookie_duration = empty($limits['cookie_duration']) ? FreshRSS_Auth::DEFAULT_COOKIE_DURATION : $limits['cookie_duration']; $oldest = time() - $cookie_duration; foreach (new DirectoryIterator(DATA_PATH . '/tokens/') as $file_info) { -- cgit v1.2.3