diff options
| author | 2023-12-22 11:03:32 +0100 | |
|---|---|---|
| committer | 2023-12-22 11:03:32 +0100 | |
| commit | c7a3281a73839590bfa9d8a9e73c41fc35fc2847 (patch) | |
| tree | 14064171417219063004c232d3e63a7a777b7335 | |
| parent | bd9e33a25cfc16125c1484656ff1b4cd7c3991d7 (diff) | |
Fix notifications (#5959)
The notification about wrong login was not working. Noticed while working on https://github.com/FreshRSS/FreshRSS/pull/5955
This was due to timing of when the notification is retrieved.
Simplified code to make the logic easier and more robust.
| -rw-r--r-- | app/Controllers/authController.php | 1 | ||||
| -rw-r--r-- | app/FreshRSS.php | 9 | ||||
| -rw-r--r-- | app/Models/View.php | 2 | ||||
| -rw-r--r-- | app/layout/layout.phtml | 8 | ||||
| -rw-r--r-- | app/layout/simple.phtml | 7 | ||||
| -rw-r--r-- | lib/Minz/Request.php | 11 |
6 files changed, 16 insertions, 22 deletions
diff --git a/app/Controllers/authController.php b/app/Controllers/authController.php index ac3fcb0be..82dfefddd 100644 --- a/app/Controllers/authController.php +++ b/app/Controllers/authController.php @@ -182,7 +182,6 @@ class FreshRSS_auth_Controller extends FreshRSS_ActionController { Minz_Request::good(_t('feedback.auth.login.success'), $url); } else { Minz_Log::warning("Password mismatch for user={$username}, nonce={$nonce}, c={$challenge}"); - header('HTTP/1.1 403 Forbidden'); Minz_Session::_param('POST_to_GET', true); //Prevent infinite internal redirect Minz_Request::setBadNotification(_t('feedback.auth.login.invalid')); diff --git a/app/FreshRSS.php b/app/FreshRSS.php index 264d8ff1a..c31655aa0 100644 --- a/app/FreshRSS.php +++ b/app/FreshRSS.php @@ -16,7 +16,6 @@ class FreshRSS extends Minz_FrontController { * - Init i18n (need context) * - Init sharing system (need user conf and i18n) * - Init generic styles and scripts (need user conf) - * - Init notifications * - Enable user extensions (need all the other initializations) */ public function init(): void { @@ -58,7 +57,6 @@ class FreshRSS extends Minz_FrontController { // Complete initialization of the other FreshRSS / Minz components. self::initI18n(); - self::loadNotifications(); // Enable extensions for the current (logged) user. if (FreshRSS_Auth::hasAccess() || FreshRSS_Context::systemConf()->allow_anonymous) { $ext_list = FreshRSS_Context::userConf()->extensions_enabled; @@ -151,13 +149,6 @@ class FreshRSS extends Minz_FrontController { FreshRSS_View::prependScript(Minz_Url::display('/scripts/main.js?' . @filemtime(PUBLIC_PATH . '/scripts/main.js'))); } - private static function loadNotifications(): void { - $notif = Minz_Request::getNotification(); - if (!empty($notif)) { - FreshRSS_View::_param('notification', $notif); - } - } - public static function preLayout(): void { header("X-Content-Type-Options: nosniff"); diff --git a/app/Models/View.php b/app/Models/View.php index 8346b3ce8..9c601b1d1 100644 --- a/app/Models/View.php +++ b/app/Models/View.php @@ -27,8 +27,6 @@ class FreshRSS_View extends Minz_View { public array $tagsForEntry; /** @var array<string,array<string>> */ public array $tagsForEntries; - /** @var array<string,string> */ - public array $notification; public bool $excludeMutedFeeds; // Substriptions diff --git a/app/layout/layout.phtml b/app/layout/layout.phtml index adbd52327..ba6dc4a96 100644 --- a/app/layout/layout.phtml +++ b/app/layout/layout.phtml @@ -77,10 +77,10 @@ if (_t('gen.dir') === 'rtl') { <?php $msg = ''; $status = 'closed'; - if (!empty($this->notification)) { - $msg = $this->notification['content']; - $status = $this->notification['type']; - + $notif = Minz_Request::getNotification(); + if (!empty($notif)) { + $msg = $notif['content']; + $status = $notif['type']; invalidateHttpCache(); } ?> diff --git a/app/layout/simple.phtml b/app/layout/simple.phtml index f2e6bbd25..065b69fb9 100644 --- a/app/layout/simple.phtml +++ b/app/layout/simple.phtml @@ -59,9 +59,10 @@ <?php $msg = ''; $status = 'closed'; - if (!empty($this->notification)) { - $msg = $this->notification['content']; - $status = $this->notification['type']; + $notif = Minz_Request::getNotification(); + if (!empty($notif)) { + $msg = $notif['content']; + $status = $notif['type']; invalidateHttpCache(); } ?> diff --git a/lib/Minz/Request.php b/lib/Minz/Request.php index f39982be1..80d503048 100644 --- a/lib/Minz/Request.php +++ b/lib/Minz/Request.php @@ -352,8 +352,11 @@ class Minz_Request { self::setNotification('bad', $content); } - /** @return array{type:string,content:string}|null */ - public static function getNotification(): ?array { + /** + * @param $pop true (default) to remove the notification, false to keep it. + * @return array{type:string,content:string}|null + */ + public static function getNotification(bool $pop = true): ?array { $notif = null; Minz_Session::lock(); /** @var array<string,array{time:int,notification:array{type:string,content:string}}> */ @@ -365,7 +368,9 @@ class Minz_Request { $requestId = self::requestId(); if (!empty($requests[$requestId]['notification'])) { $notif = $requests[$requestId]['notification']; - unset($requests[$requestId]); + if ($pop) { + unset($requests[$requestId]); + } } Minz_Session::_param('requests', $requests); } |
