From a82e4ba363b5969d95b2df72ac87bf8255cd1bd7 Mon Sep 17 00:00:00 2001 From: Skylar Ittner Date: Tue, 24 Jul 2018 01:16:27 -0600 Subject: [PATCH] Add notification view/delete UI to homepage (closes #10) --- action.php | 31 +++++++++++++++++++++-- langs/en/notifications.json | 6 +++++ langs/messages.php | 9 +++---- pages/home.php | 50 +++++++++++++++++++++++++++++++++++++ settings.template.php | 5 ++++ 5 files changed, 94 insertions(+), 7 deletions(-) create mode 100644 langs/en/notifications.json diff --git a/action.php b/action.php index 79b342c..58658f5 100644 --- a/action.php +++ b/action.php @@ -21,8 +21,6 @@ if ($VARS['action'] == 'signout' && $_SESSION['loggedin'] != true) { dieifnotloggedin(); -engageRateLimit(); - function returnToSender($msg, $arg = "") { global $VARS; if ($arg == "") { @@ -40,6 +38,7 @@ switch ($VARS['action']) { header('Location: index.php'); die("Logged out."); case "chpasswd": + engageRateLimit(); $error = []; $user = new User($_SESSION['uid']); try { @@ -59,6 +58,7 @@ switch ($VARS['action']) { } break; case "chpin": + engageRateLimit(); $error = []; if (!($VARS['newpin'] == "" || (is_numeric($VARS['newpin']) && strlen($VARS['newpin']) >= 1 && strlen($VARS['newpin']) <= 8))) { returnToSender("invalid_pin_format"); @@ -82,8 +82,35 @@ switch ($VARS['action']) { Log::insert(LogType::ADDED_2FA, $user); returnToSender("2fa_enabled"); case "rm2fa": + engageRateLimit(); (new User($_SESSION['uid']))->save2fa(""); Log::insert(LogType::REMOVED_2FA, $_SESSION['uid']); returnToSender("2fa_removed"); break; + case "readnotification": + $user = new User($_SESSION['uid']); + + if (empty($VARS['id'])) { + returnToSender("invalid_parameters#notifications"); + } + try { + Notifications::read($user, $VARS['id']); + returnToSender("#notifications"); + } catch (Exception $ex) { + returnToSender("invalid_parameters#notifications"); + } + break; + case "deletenotification": + $user = new User($_SESSION['uid']); + + if (empty($VARS['id'])) { + returnToSender("invalid_parameters#notifications"); + } + try { + Notifications::delete($user, $VARS['id']); + returnToSender("notification_deleted#notifications"); + } catch (Exception $ex) { + returnToSender("invalid_parameters#notifications"); + } + break; } \ No newline at end of file diff --git a/langs/en/notifications.json b/langs/en/notifications.json new file mode 100644 index 0000000..a9fd348 --- /dev/null +++ b/langs/en/notifications.json @@ -0,0 +1,6 @@ +{ + "Notifications": "Notifications", + "Notification deleted.": "Notification deleted.", + "Mark as read": "Mark as read", + "Delete": "Delete" +} diff --git a/langs/messages.php b/langs/messages.php index 97528de..fd007e1 100644 --- a/langs/messages.php +++ b/langs/messages.php @@ -45,10 +45,6 @@ define("MESSAGES", [ "string" => "account state error", "type" => "danger" ], - "ldap_error" => [ - "string" => "ldap server error", - "type" => "danger" - ], "passwords_same" => [ "string" => "old and new passwords match", "type" => "danger" @@ -72,6 +68,9 @@ define("MESSAGES", [ "invalid_pin_format" => [ "string" => "invalid pin format", "type" => "danger" + ], + "notification_deleted" => [ + "string" => "Notification deleted.", + "type" => "success" ] - ]); diff --git a/pages/home.php b/pages/home.php index 588c62b..53f83c0 100644 --- a/pages/home.php +++ b/pages/home.php @@ -90,4 +90,54 @@ + + +

get("Notifications"); ?>

+
+ +
+
+
"> +
+
+
+
+ + + +
+
+ + + +
+
+
+
+
+ +
+
+
\ No newline at end of file diff --git a/settings.template.php b/settings.template.php index d66f5ed..6c94373 100644 --- a/settings.template.php +++ b/settings.template.php @@ -131,6 +131,11 @@ define('EXTERNAL_APPS', [ ], ]); +// Used for notification timestamp display. +define("DATETIME_FORMAT", "M j, g:i a"); +define("TIME_FORMAT", "g:i"); + + // Email settings for receiving admin alerts. define("USE_SMTP", TRUE); // if FALSE, will use PHP's mail() instead define("ADMIN_EMAIL", "");