From a94ab600048f8a4a58f144b03829615baae0db37 Mon Sep 17 00:00:00 2001 From: Carl-Tabuso Date: Fri, 24 May 2024 17:58:12 +0800 Subject: [PATCH 01/11] chore: Ignore text file used for error logging. --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..ab01c12a --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +# Ignore +src/includes/error-logs.txt \ No newline at end of file From 880d13c9bf619fe378f200c94f2f7faaa2afc502 Mon Sep 17 00:00:00 2001 From: Carl-Tabuso Date: Fri, 24 May 2024 18:01:20 +0800 Subject: [PATCH 02/11] SPD-82-Add a preloader/spinner for every webpage. --- src/includes/preloader.html | 5 +++++ src/javascript/preloader.js | 9 +++++++++ src/styles/main.css | 24 +++++++++++++++++++----- src/styles/main.scss | 17 +++++++++++++++++ 4 files changed, 50 insertions(+), 5 deletions(-) create mode 100644 src/includes/preloader.html create mode 100644 src/javascript/preloader.js diff --git a/src/includes/preloader.html b/src/includes/preloader.html new file mode 100644 index 00000000..fc185a37 --- /dev/null +++ b/src/includes/preloader.html @@ -0,0 +1,5 @@ +
+
+ +
+
\ No newline at end of file diff --git a/src/javascript/preloader.js b/src/javascript/preloader.js new file mode 100644 index 00000000..4146f362 --- /dev/null +++ b/src/javascript/preloader.js @@ -0,0 +1,9 @@ +const spinnerWrapper = document.querySelector(".spinner-wrapper"); + +window.addEventListener("load", () => { + spinnerWrapper.style.opacity = "0"; + + setTimeout(() => { + spinnerWrapper.style.display = "none"; + }, 200); +}); diff --git a/src/styles/main.css b/src/styles/main.css index 210aec54..11bf7bb1 100644 --- a/src/styles/main.css +++ b/src/styles/main.css @@ -13,6 +13,20 @@ font-weight: 500; } +.spinner-wrapper { + background-color: rgba(0, 0, 0, 0.8); + position: fixed; + top: 0; + left: 0; + width: 100%; + height: 100%; + z-index: 9999; + display: flex; + justify-content: center; + align-items: center; + transition: all 0.3s; +} + /*! * Bootstrap v5.3.3 (https://getbootstrap.com/) * Copyright 2011-2024 The Bootstrap Authors @@ -6630,10 +6644,10 @@ textarea.form-control-lg { } } .spinner-border { - --bs-spinner-width: 2rem; - --bs-spinner-height: 2rem; + --bs-spinner-width: 4rem; + --bs-spinner-height: 4rem; --bs-spinner-vertical-align: -0.125em; - --bs-spinner-border-width: 0.25em; + --bs-spinner-border-width: 0.45em; --bs-spinner-animation-speed: 0.75s; --bs-spinner-animation-name: spinner-border; border: var(--bs-spinner-border-width) solid currentcolor; @@ -6656,8 +6670,8 @@ textarea.form-control-lg { } } .spinner-grow { - --bs-spinner-width: 2rem; - --bs-spinner-height: 2rem; + --bs-spinner-width: 4rem; + --bs-spinner-height: 4rem; --bs-spinner-vertical-align: -0.125em; --bs-spinner-animation-speed: 0.75s; --bs-spinner-animation-name: spinner-grow; diff --git a/src/styles/main.scss b/src/styles/main.scss index ad0e13cb..de935d22 100644 --- a/src/styles/main.scss +++ b/src/styles/main.scss @@ -47,6 +47,23 @@ $custom-table-variants: ( box-shadow: 0 0 10px rgba(0, 0, 0, 0.25); font-weight: 500; } +.spinner-wrapper { + background-color: rgba(0, 0, 0, 0.8); + position: fixed; + top: 0; + left: 0; + width: 100%; + height: 100%; + z-index: 9999; + display: flex; + justify-content: center; + align-items: center; + transition: all 0.3s; +} + +$spinner-width: 4rem; +$spinner-height: $spinner-width; +$spinner-border-width: .45em; $table-variants: map-merge($table-variants , $custom-table-variants); $theme-colors: map-merge($theme-colors, $custom-colors); From c80aa8cb0eec8cf6fae184a1a4d3f637f23daf09 Mon Sep 17 00:00:00 2001 From: Carl-Tabuso Date: Fri, 24 May 2024 18:04:39 +0800 Subject: [PATCH 03/11] style: SPD-82-Add style for the preloader and its wrapper --- src/styles/main.css | 24 +++++------------------- src/styles/main.scss | 17 ----------------- 2 files changed, 5 insertions(+), 36 deletions(-) diff --git a/src/styles/main.css b/src/styles/main.css index 11bf7bb1..210aec54 100644 --- a/src/styles/main.css +++ b/src/styles/main.css @@ -13,20 +13,6 @@ font-weight: 500; } -.spinner-wrapper { - background-color: rgba(0, 0, 0, 0.8); - position: fixed; - top: 0; - left: 0; - width: 100%; - height: 100%; - z-index: 9999; - display: flex; - justify-content: center; - align-items: center; - transition: all 0.3s; -} - /*! * Bootstrap v5.3.3 (https://getbootstrap.com/) * Copyright 2011-2024 The Bootstrap Authors @@ -6644,10 +6630,10 @@ textarea.form-control-lg { } } .spinner-border { - --bs-spinner-width: 4rem; - --bs-spinner-height: 4rem; + --bs-spinner-width: 2rem; + --bs-spinner-height: 2rem; --bs-spinner-vertical-align: -0.125em; - --bs-spinner-border-width: 0.45em; + --bs-spinner-border-width: 0.25em; --bs-spinner-animation-speed: 0.75s; --bs-spinner-animation-name: spinner-border; border: var(--bs-spinner-border-width) solid currentcolor; @@ -6670,8 +6656,8 @@ textarea.form-control-lg { } } .spinner-grow { - --bs-spinner-width: 4rem; - --bs-spinner-height: 4rem; + --bs-spinner-width: 2rem; + --bs-spinner-height: 2rem; --bs-spinner-vertical-align: -0.125em; --bs-spinner-animation-speed: 0.75s; --bs-spinner-animation-name: spinner-grow; diff --git a/src/styles/main.scss b/src/styles/main.scss index de935d22..ad0e13cb 100644 --- a/src/styles/main.scss +++ b/src/styles/main.scss @@ -47,23 +47,6 @@ $custom-table-variants: ( box-shadow: 0 0 10px rgba(0, 0, 0, 0.25); font-weight: 500; } -.spinner-wrapper { - background-color: rgba(0, 0, 0, 0.8); - position: fixed; - top: 0; - left: 0; - width: 100%; - height: 100%; - z-index: 9999; - display: flex; - justify-content: center; - align-items: center; - transition: all 0.3s; -} - -$spinner-width: 4rem; -$spinner-height: $spinner-width; -$spinner-border-width: .45em; $table-variants: map-merge($table-variants , $custom-table-variants); $theme-colors: map-merge($theme-colors, $custom-colors); From 615ec91b2590bc96ac4ef1d9598c04e0d86e75af Mon Sep 17 00:00:00 2001 From: Carl-Tabuso Date: Fri, 24 May 2024 18:08:17 +0800 Subject: [PATCH 04/11] Revert "style: SPD-82-Add style for the preloader and its wrapper" This reverts commit c80aa8cb0eec8cf6fae184a1a4d3f637f23daf09. --- src/styles/main.css | 24 +++++++++++++++++++----- src/styles/main.scss | 17 +++++++++++++++++ 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/src/styles/main.css b/src/styles/main.css index 210aec54..11bf7bb1 100644 --- a/src/styles/main.css +++ b/src/styles/main.css @@ -13,6 +13,20 @@ font-weight: 500; } +.spinner-wrapper { + background-color: rgba(0, 0, 0, 0.8); + position: fixed; + top: 0; + left: 0; + width: 100%; + height: 100%; + z-index: 9999; + display: flex; + justify-content: center; + align-items: center; + transition: all 0.3s; +} + /*! * Bootstrap v5.3.3 (https://getbootstrap.com/) * Copyright 2011-2024 The Bootstrap Authors @@ -6630,10 +6644,10 @@ textarea.form-control-lg { } } .spinner-border { - --bs-spinner-width: 2rem; - --bs-spinner-height: 2rem; + --bs-spinner-width: 4rem; + --bs-spinner-height: 4rem; --bs-spinner-vertical-align: -0.125em; - --bs-spinner-border-width: 0.25em; + --bs-spinner-border-width: 0.45em; --bs-spinner-animation-speed: 0.75s; --bs-spinner-animation-name: spinner-border; border: var(--bs-spinner-border-width) solid currentcolor; @@ -6656,8 +6670,8 @@ textarea.form-control-lg { } } .spinner-grow { - --bs-spinner-width: 2rem; - --bs-spinner-height: 2rem; + --bs-spinner-width: 4rem; + --bs-spinner-height: 4rem; --bs-spinner-vertical-align: -0.125em; --bs-spinner-animation-speed: 0.75s; --bs-spinner-animation-name: spinner-grow; diff --git a/src/styles/main.scss b/src/styles/main.scss index ad0e13cb..de935d22 100644 --- a/src/styles/main.scss +++ b/src/styles/main.scss @@ -47,6 +47,23 @@ $custom-table-variants: ( box-shadow: 0 0 10px rgba(0, 0, 0, 0.25); font-weight: 500; } +.spinner-wrapper { + background-color: rgba(0, 0, 0, 0.8); + position: fixed; + top: 0; + left: 0; + width: 100%; + height: 100%; + z-index: 9999; + display: flex; + justify-content: center; + align-items: center; + transition: all 0.3s; +} + +$spinner-width: 4rem; +$spinner-height: $spinner-width; +$spinner-border-width: .45em; $table-variants: map-merge($table-variants , $custom-table-variants); $theme-colors: map-merge($theme-colors, $custom-colors); From c10430a23578b53df8bdabb825d17dc71d286719 Mon Sep 17 00:00:00 2001 From: Carl-Tabuso Date: Fri, 24 May 2024 18:09:32 +0800 Subject: [PATCH 05/11] refactor: Move to includes folder and normalized file path. --- src/includes/logout.php | 9 +++++++++ src/logout.php | 6 ------ 2 files changed, 9 insertions(+), 6 deletions(-) create mode 100644 src/includes/logout.php delete mode 100644 src/logout.php diff --git a/src/includes/logout.php b/src/includes/logout.php new file mode 100644 index 00000000..719907ad --- /dev/null +++ b/src/includes/logout.php @@ -0,0 +1,9 @@ + \ No newline at end of file diff --git a/src/logout.php b/src/logout.php deleted file mode 100644 index 36966d9c..00000000 --- a/src/logout.php +++ /dev/null @@ -1,6 +0,0 @@ - \ No newline at end of file From a7776a456ab55596d102916873c37b278b834157 Mon Sep 17 00:00:00 2001 From: Carl-Tabuso Date: Fri, 24 May 2024 18:11:04 +0800 Subject: [PATCH 06/11] chore: This file create a new text file called error-logs.txt, where all system-generated errors get logged. This file is included shall be included in all pages. --- src/includes/error-reporting.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 src/includes/error-reporting.php diff --git a/src/includes/error-reporting.php b/src/includes/error-reporting.php new file mode 100644 index 00000000..40dd730e --- /dev/null +++ b/src/includes/error-reporting.php @@ -0,0 +1,19 @@ + Date: Fri, 24 May 2024 18:11:45 +0800 Subject: [PATCH 07/11] refactor: Add the login authenticator to a separate file inside the includes folder. --- src/includes/login-authenticator.php | 48 ++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 src/includes/login-authenticator.php diff --git a/src/includes/login-authenticator.php b/src/includes/login-authenticator.php new file mode 100644 index 00000000..5dba3bf7 --- /dev/null +++ b/src/includes/login-authenticator.php @@ -0,0 +1,48 @@ +prepare("SELECT id, username, password FROM user WHERE BINARY username = ?"); + $stmt->bind_param('s', $username); + $stmt->execute(); + $result = $stmt->get_result(); + + // Check if a user of this username exists + if($result->num_rows > 0) { + $row = $result->fetch_assoc(); + + // Verify if password match the entered username + if (password_verify($password, $row['password'])) { + $_SESSION['id'] = $row['id']; + session_regenerate_id(true); + header("location: ../index.php"); + exit(); + } + // If username and password mismatched, display this + else { + $_SESSION['error_message'] = 'Username and password mismatched.'; + header("Location: ../login.php"); + exit(); + } + } + // If there is no user with the username, display this + else { + $_SESSION['error_message'] = 'User is not found.'; + header("Location: ../login.php"); + exit(); + } +} \ No newline at end of file From 6f3e395db1c03505fbe6a2d88db43f2564f07601 Mon Sep 17 00:00:00 2001 From: Carl-Tabuso Date: Fri, 24 May 2024 18:16:38 +0800 Subject: [PATCH 08/11] refactor: Normalize file path traversal to make it compatible with different OS. --- src/add-account.php | 4 +++- src/create-order.php | 14 +++++++++----- src/delete-account.php | 4 +++- src/delete-sale.php | 5 ++++- src/get-product-details.php | 4 +++- src/get-products.php | 4 +++- src/includes/db-connector.php | 4 ++++ src/includes/execute-prediction-script.php | 4 +++- src/includes/mailer.php | 4 +++- src/includes/process-reset-password.php | 5 +++-- src/includes/send-password-reset.php | 8 +++++--- src/includes/session-handler.php | 3 +++ src/reset-password.php | 9 +++++++-- src/update-account.php | 4 +++- src/view-sales.php | 4 +++- 15 files changed, 59 insertions(+), 21 deletions(-) diff --git a/src/add-account.php b/src/add-account.php index 3671d98a..c57bbfef 100644 --- a/src/add-account.php +++ b/src/add-account.php @@ -1,5 +1,7 @@ @@ -82,7 +85,7 @@ @@ -93,7 +96,7 @@ @@ -107,6 +110,7 @@ + diff --git a/src/delete-account.php b/src/delete-account.php index 12107279..9597073b 100644 --- a/src/delete-account.php +++ b/src/delete-account.php @@ -1,6 +1,8 @@ + +
@@ -94,5 +97,7 @@
+ + \ No newline at end of file diff --git a/src/update-account.php b/src/update-account.php index effbcb51..34d9ea6b 100644 --- a/src/update-account.php +++ b/src/update-account.php @@ -1,5 +1,7 @@ Date: Fri, 24 May 2024 18:17:10 +0800 Subject: [PATCH 09/11] feat: SPD-82-Show a spinner preloader with a 2-3 seconds interval for smooth feel everytime the page is access. Also, traversal of file path is normalized to make it compatible with different OS. --- src/accounts.php | 44 ++++++++++++++++++++--------------- src/index.php | 29 +++++++++++------------ src/login.php | 60 ++++++------------------------------------------ src/product.php | 10 +++++--- src/report.php | 10 +++++--- src/sales.php | 10 +++++--- 6 files changed, 68 insertions(+), 95 deletions(-) diff --git a/src/accounts.php b/src/accounts.php index 2e04a40e..385178dd 100644 --- a/src/accounts.php +++ b/src/accounts.php @@ -1,9 +1,15 @@ query($sql); + $row = $result->fetch_assoc(); + ?> @@ -28,7 +34,8 @@ @@ -73,21 +80,21 @@ query($sql); - - while($row = $result->fetch_assoc()) { - echo ' - - - '.$row['last_name'].' - '.$row["first_name"].' - '.$row['middle_name'].' - '.$row['email'].' - - '; - } - ?> + $sql = "SELECT * FROM user"; + $result = $db->query($sql); + while($row = $result->fetch_assoc()) { + echo ' + + + '.$row['last_name'].' + '.$row["first_name"].' + '.$row['middle_name'].' + '.$row['email'].' + + '; + } + $db->close(); + ?> @@ -204,6 +211,7 @@ class="btn fw-medium btn-medium-brown text-capitalize py-2 px-4">add account + + \ No newline at end of file diff --git a/src/login.php b/src/login.php index f996857e..c5a38bbc 100644 --- a/src/login.php +++ b/src/login.php @@ -1,7 +1,7 @@ prepare("SELECT id, username, password FROM user WHERE BINARY username = ?"); - $stmt->bind_param('s', $username); - $stmt->execute(); - $result = $stmt->get_result(); - - // Check if a user of this username exists - if($result->num_rows > 0) { - $row = $result->fetch_assoc(); - - // Verify if password match the entered username - if (password_verify($password, $row['password'])) { - $_SESSION['id'] = $row['id']; - session_regenerate_id(true); - header("location: index.php"); - exit(); - } - // If username and password mismatched, display this - else { - $_SESSION['error_message'] = 'Username and password mismatched.'; - header("Location: login.php"); - exit(); - } - } - // If there is no user with the username, display this - else { - $_SESSION['error_message'] = 'User is not found.'; - header("Location: login.php"); - exit(); - } -} - if (isset($_SESSION['error_message'])) { $errorMessage = $_SESSION['error_message']; unset($_SESSION['error_message']); @@ -93,6 +50,8 @@ + + - - - - - - + diff --git a/src/product.php b/src/product.php index bd0233a4..bd037f3a 100644 --- a/src/product.php +++ b/src/product.php @@ -1,6 +1,8 @@ @@ -317,6 +320,7 @@ + + +