diff --git a/README.MD b/README.MD index 1c3ea05..5ef95db 100644 --- a/README.MD +++ b/README.MD @@ -23,7 +23,7 @@ - +Note: This app is not intended for production use, but for personal or educational purposes. ### Built With diff --git a/components/account/main.php b/components/account/main.php new file mode 100644 index 0000000..62cf702 --- /dev/null +++ b/components/account/main.php @@ -0,0 +1,73 @@ +prepare("SELECT email, firstName, lastName FROM users WHERE id = ?"); + $query->execute([$userId]); + return $query->fetch(PDO::FETCH_ASSOC); + } catch(PDOException $e) { + return null; + } +} + +function updateUserDetails($userId, $email, $firstName, $lastName, $password = null) { + global $conn; + try { + if ($password) { + $query = $conn->prepare("UPDATE users SET email = ?, firstName = ?, lastName = ?, password = ? WHERE id = ?"); + $hashedPassword = password_hash($password, PASSWORD_DEFAULT); + $query->execute([$email, $firstName, $lastName, $hashedPassword, $userId]); + } else { + $query = $conn->prepare("UPDATE users SET email = ?, firstName = ?, lastName = ? WHERE id = ?"); + $query->execute([$email, $firstName, $lastName, $userId]); + } + return true; + } catch(PDOException $e) { + return false; + } +} + +if ($_SERVER['REQUEST_METHOD'] === 'POST') { + $success = updateUserDetails($_SESSION['user_id'], $_POST['email'], $_POST['firstName'], $_POST['lastName'], $_POST['password']); + + if ($success) { + $_SESSION['message'] = ''; + } else { + $_SESSION['message'] = ''; + } + + header("Location: " . $_SERVER['REQUEST_URI']); + exit(); +} + +$userDetails = getUserDetails($_SESSION['user_id']); +?> + +
+ +

Edit Account

+
+
+ + +
+
+ + +
+
+ + +
+
+ + + Leave blank if you do not want to change the password +
+ +
+
\ No newline at end of file diff --git a/components/admin/main.php b/components/admin/main.php new file mode 100644 index 0000000..8865de0 --- /dev/null +++ b/components/admin/main.php @@ -0,0 +1,73 @@ +prepare("SELECT id, email, firstName, lastName FROM users"); + $query->execute(); + return $query->fetchAll(PDO::FETCH_ASSOC); + } catch (PDOException $e) { + return []; + } +} + +$users = getUsers(); + +function updateUserDetails($userId, $email, $firstName, $lastName, $password = null) { + global $conn; + try { + if ($password) { + $query = $conn->prepare("UPDATE users SET email = ?, firstName = ?, lastName = ?, password = ? WHERE id = ?"); + $hashedPassword = password_hash($password, PASSWORD_DEFAULT); + $query->execute([$email, $firstName, $lastName, $hashedPassword, $userId]); + } else { + $query = $conn->prepare("UPDATE users SET email = ?, firstName = ?, lastName = ? WHERE id = ?"); + $query->execute([$email, $firstName, $lastName, $userId]); + } + return true; + } catch(PDOException $e) { + return false; + } +} + +if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['userId'])) { + $password = !empty($_POST['password']) ? $_POST['password'] : null; + + $success = updateUserDetails($_POST['userId'], $_POST['email'], $_POST['firstName'], $_POST['lastName'], $password); + + if ($success) { + $_SESSION['message'] = ''; + } else { + $_SESSION['message'] = ''; + } + + header("Location: " . $_SERVER['REQUEST_URI']); + exit(); +} + +?> + +
+ +

Administration

+ +
+ + + diff --git a/components/admin/modal.php b/components/admin/modal.php new file mode 100644 index 0000000..1d5dcfb --- /dev/null +++ b/components/admin/modal.php @@ -0,0 +1,33 @@ + \ No newline at end of file diff --git a/components/admin/users_list.php b/components/admin/users_list.php new file mode 100644 index 0000000..3adefdc --- /dev/null +++ b/components/admin/users_list.php @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + +
#EmailFirst NameLast Name
+ +
\ No newline at end of file diff --git a/components/homepage/line.php b/components/homepage/line.php index a8ce6a9..a2aee3b 100644 --- a/components/homepage/line.php +++ b/components/homepage/line.php @@ -10,7 +10,7 @@ foreach ($favoriteStops as $stop) { $stop_name = getStopName($stop['stopId']); - include 'components/homepage/stop.php'; + include 'stop.php'; if (count($favoriteStops) > 1) { echo '
'; } diff --git a/components/homepage/main.php b/components/homepage/main.php index 4a8350a..414aa66 100644 --- a/components/homepage/main.php +++ b/components/homepage/main.php @@ -38,7 +38,7 @@ $lineIds = $query->fetchAll(PDO::FETCH_COLUMN);
- +
@@ -72,7 +72,7 @@ document.addEventListener('DOMContentLoaded', function() { var action = this.classList.contains('add-stop') ? 'add' : 'remove'; var buttonElement = this; - fetch('/endpoints/updateFavorite.php', { + fetch('/updateFavorite.php', { method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded' diff --git a/components/register/main.php b/components/register/main.php index dda6fad..96ac001 100644 --- a/components/register/main.php +++ b/components/register/main.php @@ -1,8 +1,6 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/structure/main.php b/components/structure/main.php similarity index 76% rename from structure/main.php rename to components/structure/main.php index a821d8a..0ec7994 100644 --- a/structure/main.php +++ b/components/structure/main.php @@ -1,7 +1,7 @@ @@ -22,7 +22,7 @@ include 'services/db.php'; - +