From bab84747b67100fa45886cc70678027c68133a8f Mon Sep 17 00:00:00 2001 From: "nate@necloud.us" Date: Wed, 2 Jul 2025 13:25:23 -0400 Subject: [PATCH] bugs --- public/index.html | 5 ++-- public/script.js | 71 +++++++++++++++++++++++++++++++++++++++++------ public/styles.css | 36 ++++++++++++++++++++++++ public/users.json | 7 ++++- 4 files changed, 108 insertions(+), 11 deletions(-) diff --git a/public/index.html b/public/index.html index 21626ea..7acee64 100644 --- a/public/index.html +++ b/public/index.html @@ -10,7 +10,7 @@

Spelling Practice

- +

User Login

@@ -26,7 +26,7 @@ @@ -93,5 +93,6 @@
+
diff --git a/public/script.js b/public/script.js index 1c3f580..139f5a9 100644 --- a/public/script.js +++ b/public/script.js @@ -53,38 +53,84 @@ window.addEventListener('DOMContentLoaded', async () => { // ๐Ÿง‘โ€๐Ÿซ Admin setup async function setupSession(user) { + // ๐Ÿ”’ Hide everything first for clean slate document.getElementById('loginPanel').classList.add('hidden') + document.getElementById('adminPanel').classList.add('hidden') + document.getElementById('studentPanel').classList.add('hidden') + + // ๐Ÿ”“ Show navigation and user info document.getElementById('nav').classList.remove('hidden') document.getElementById('userInfo').textContent = `${user.username} (${user.role})` + // ๐ŸŽจ Role-colored banner setup + const roleBanner = document.getElementById('roleBanner') + roleBanner.classList.remove('hidden', 'admin', 'student') + roleBanner.classList.add(user.role) + roleBanner.textContent = user.role === "admin" + ? "๐Ÿ‘จโ€๐Ÿซ Admin Access Enabled" + : "๐ŸŽ“ Student Mode Active" + + // ๐Ÿ™ˆ Hide/show Student Panel button appropriately + const studentBtn = document.getElementById('studentBtn') if (user.role === "admin") { + studentBtn.classList.remove('hidden') document.getElementById('adminBtn').classList.remove('hidden') + console.log("๐Ÿ›  Logged in as Admin") await showAdmin() - await loadUsers() - displayUserDropdown() - populateWordUserDropdown() - } else { + } else if (user.role === "student") { + studentBtn.classList.add('hidden') document.getElementById('adminBtn').classList.add('hidden') + console.log("๐ŸŽ“ Logged in as Student") showStudent() + } else { + console.warn("โ“ Unknown role:", user.role) + logoutUser() + alert("Unknown role detected. Logging out for security.") + return } + + // ๐Ÿ“ฃ Toast message + showToast(`Welcome, ${user.role}!`) } - function logoutUser() { + // Clear stored user session localStorage.removeItem('loggedInUser') - document.getElementById('loginPanel').classList.remove('hidden') - document.getElementById('nav').classList.add('hidden') + + // ๐Ÿ”„ Reset all visible panels document.getElementById('adminPanel').classList.add('hidden') document.getElementById('studentPanel').classList.add('hidden') + document.getElementById('nav').classList.add('hidden') + document.getElementById('loginPanel').classList.remove('hidden') + document.getElementById('username').value = '' + document.getElementById('password').value = '' + + // ๐Ÿงผ Reset role banner styling and content + const roleBanner = document.getElementById('roleBanner') + roleBanner.classList.add('hidden') + roleBanner.classList.remove('admin', 'student') + roleBanner.textContent = '' + + // Optional: reset login message (if present) + const loginMessage = document.getElementById('loginMessage') + if (loginMessage) loginMessage.textContent = '' } async function showAdmin() { + const user = JSON.parse(localStorage.getItem('loggedInUser')) + if (!user || user.role !== "admin") { + console.warn("โ›” Access denied: not an admin") + return + } + document.getElementById('adminPanel').classList.remove('hidden') document.getElementById('studentPanel').classList.add('hidden') - loadWords() + + await loadWords() displayWordList() await loadUsers() displayUserDropdown() + populateWordUserDropdown() } // โž• Add User @@ -341,3 +387,12 @@ async function loadWordsForSelectedUser() { allWords = await res.json() displayWordList() } +function showToast(message, duration = 3000) { + const toast = document.getElementById("toast") + toast.textContent = message + toast.classList.add("show") + + setTimeout(() => { + toast.classList.remove("show") + }, duration) +} \ No newline at end of file diff --git a/public/styles.css b/public/styles.css index 226a042..1b0c396 100644 --- a/public/styles.css +++ b/public/styles.css @@ -87,3 +87,39 @@ body.galaxy button { body.nature button { background-color: #81c784; } +.banner { + padding: 0.5em; + text-align: center; + font-weight: bold; + color: white; +} + +.banner.admin { + background-color: #b22222; /* Firebrick red */ +} + +.banner.student { + background-color: #1e90ff; /* Dodger blue */ +} + +.hidden { + display: none; +} +.toast { + position: fixed; + bottom: 20px; + right: 20px; + background: #333; + color: #fff; + padding: 0.75em 1.25em; + border-radius: 5px; + opacity: 0; + pointer-events: none; + transition: opacity 0.4s ease; + z-index: 999; +} + +.toast.show { + opacity: 1; + pointer-events: auto; +} \ No newline at end of file diff --git a/public/users.json b/public/users.json index a8241a2..4f2a0a2 100644 --- a/public/users.json +++ b/public/users.json @@ -8,5 +8,10 @@ "username": "student1", "hash": "8d969eef6ecad3c29a3a629280e686cf", "role": "student" + }, + { + "username": "nate", + "hash": "5a2a558c78d3717db731600c4f354fa1d9c84b556f108091a891f444f1bdec40", + "role": "student" } -] +] \ No newline at end of file