Fix behaviour with unset global message

This commit is contained in:
Florine W. Dekker 2022-11-18 12:37:35 +01:00
parent 661e430f6a
commit 9eccbf5486
Signed by: FWDekker
GPG Key ID: D3DCFAA8A4560BE0
8 changed files with 22 additions and 19 deletions

View File

@ -9,6 +9,9 @@ This tool regularly checks if people are still alive according to Wikipedia, and
## Development
### Requirements
* PHP 8.1+ (i.e. `apt install php php-cgi`)
* [PHP cURL](https://www.php.net/manual/en/book.curl.php) (i.e. `apt install php-curl`)
* [PHP SQLite 3](https://www.php.net/manual/en/book.sqlite3.php) (i.e. `apt install php-sqlite3`)
* [composer](https://getcomposer.org/)
* [npm](https://www.npmjs.com/)

View File

@ -1,7 +1,7 @@
{
"name": "fwdekker/death-notifier",
"description": "Get notified when a famous person dies.",
"version": "0.11.2", "_comment_version": "Also update version in `package.json`!",
"version": "0.12.0", "_comment_version": "Also update version in `package.json`!",
"type": "project",
"license": "MIT",
"homepage": "https://git.fwdekker.com/tools/death-notifier",

BIN
composer.lock generated

Binary file not shown.

BIN
package-lock.json generated

Binary file not shown.

View File

@ -1,6 +1,6 @@
{
"name": "death-notifier",
"version": "0.11.2", "_comment_version": "Also update version in `composer.json`!",
"version": "0.12.0", "_comment_version": "Also update version in `composer.json`!",
"description": "Get notified when a famous person dies.",
"author": "Florine W. Dekker",
"browser": "dist/bundle.js",

View File

@ -189,20 +189,20 @@ if (isset($_POST["action"])) {
switch ($_GET["action"]) {
case "start-session":
if (!isset($_SESSION["uuid"])) {
$response = Response::unsatisfied(null);
$response = Response::satisfied(["logged_in" => false]);
} else if (!$user_manager->user_exists($_SESSION["uuid"])) {
// User account was deleted
session_destroy();
session_start();
$_SESSION["token"] = Util::generate_csrf_token($logger) ?? Util::http_exit(500);
$response = Response::unsatisfied(null);
$response = Response::satisfied(["logged_in" => false]);
} else {
$response = Response::satisfied();
$response = Response::satisfied(["logged_in" => true]);
}
if (trim($config["server"]["global_message"]) !== "")
$response->payload = trim($config["server"]["global_message"]);
$response->payload["global_message"] = trim($config["server"]["global_message"]);
break;
case "validate-password-reset-token":
$response =

View File

@ -11,7 +11,7 @@
<title>Death Notifier | FWDekker</title>
<link rel="stylesheet" href="https://static.fwdekker.com/fonts/roboto/roboto.css" />
<link rel="stylesheet" href="https://static.fwdekker.com/lib/template/2.x.x/template.css" />
<link rel="stylesheet" href="https://static.fwdekker.com/lib/template/2.x.x/template.css?v=%%VERSION_NUMBER%%" />
<!--suppress HtmlUnknownTarget -->
<link rel="stylesheet" href="main.css?v=%%VERSION_NUMBER%%" />
<script async src="https://stats.fwdekker.com/count.js"
@ -288,7 +288,7 @@
<div id="footer"></div>
</main>
<script src="https://static.fwdekker.com/lib/template/2.x.x/template.js"></script>
<script src="https://static.fwdekker.com/lib/template/2.x.x/template.js?v=%%VERSION_NUMBER%%"></script>
<!--suppress HtmlUnknownTarget -->
<script src="bundle.js?v=%%VERSION_NUMBER%%"></script>
</body>

View File

@ -580,21 +580,21 @@ doAfterLoad(() => {
getApi(
{action: "start-session"},
sharedMessageElement,
() => {
// User is already logged in
if (!params.has("action"))
loginHandler.invokeListeners();
},
() => {
// User is not logged in
if (!params.has("action"))
logoutHandler.invokeListeners();
(response: ServerResponse) => {
if (!params.has("action")) {
if (response.payload["logged_in"] === true)
loginHandler.invokeListeners();
else
logoutHandler.invokeListeners();
}
},
emptyFunction,
emptyFunction,
(response) => {
// Always execute the following
if (response?.payload != null)
showInfo($("#globalMessage"), response.payload);
const message = (response?.payload ?? {})["global_message"];
if (message != null)
showInfo($("#globalMessage"), message);
handleAction(params);
}