Update public/index.html
Browse files- public/index.html +65 -50
public/index.html
CHANGED
|
@@ -65,68 +65,83 @@
|
|
| 65 |
|
| 66 |
<script>
|
| 67 |
function showSignUp() {
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
function showLogin() {
|
| 73 |
-
document.getElementById("signupSection").style.display = "none";
|
| 74 |
-
document.getElementById("loginSection").style.display = "block";
|
| 75 |
-
}
|
| 76 |
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
|
|
|
|
|
|
| 80 |
|
| 81 |
-
|
| 82 |
-
|
|
|
|
| 83 |
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
return;
|
| 87 |
-
}
|
| 88 |
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
});
|
| 94 |
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
alert(`Login failed: ${message}`);
|
| 101 |
-
}
|
| 102 |
});
|
| 103 |
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 107 |
|
| 108 |
-
|
| 109 |
-
|
|
|
|
| 110 |
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
return;
|
| 114 |
-
}
|
| 115 |
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
});
|
| 121 |
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
alert(`Sign-up failed: ${message}`);
|
| 128 |
-
}
|
| 129 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 130 |
</script>
|
| 131 |
</body>
|
| 132 |
</html>
|
|
|
|
| 65 |
|
| 66 |
<script>
|
| 67 |
function showSignUp() {
|
| 68 |
+
document.getElementById("loginSection").style.display = "none";
|
| 69 |
+
document.getElementById("signupSection").style.display = "block";
|
| 70 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
|
| 72 |
+
// Show login form
|
| 73 |
+
function showLogin() {
|
| 74 |
+
document.getElementById("signupSection").style.display = "none";
|
| 75 |
+
document.getElementById("loginSection").style.display = "block";
|
| 76 |
+
}
|
| 77 |
|
| 78 |
+
// Login handler
|
| 79 |
+
document.getElementById("loginForm").addEventListener("submit", async (event) => {
|
| 80 |
+
event.preventDefault();
|
| 81 |
|
| 82 |
+
const username = document.getElementById("loginUsername").value.trim();
|
| 83 |
+
const password = document.getElementById("loginPassword").value.trim();
|
|
|
|
|
|
|
| 84 |
|
| 85 |
+
if (!username || !password) {
|
| 86 |
+
alert("Both fields are required!");
|
| 87 |
+
return;
|
| 88 |
+
}
|
|
|
|
| 89 |
|
| 90 |
+
try {
|
| 91 |
+
const response = await fetch("/login", {
|
| 92 |
+
method: "POST",
|
| 93 |
+
headers: { "Content-Type": "application/json" },
|
| 94 |
+
body: JSON.stringify({ username, password }),
|
|
|
|
|
|
|
| 95 |
});
|
| 96 |
|
| 97 |
+
if (response.ok) {
|
| 98 |
+
const data = await response.json(); // Expecting { message, username }
|
| 99 |
+
localStorage.setItem("username", data.username); // Save username to localStorage
|
| 100 |
+
alert("Login successful!");
|
| 101 |
+
window.location.href = "/terminal.html"; // Redirect to terminal page
|
| 102 |
+
} else {
|
| 103 |
+
const message = await response.text();
|
| 104 |
+
alert(`Login failed: ${message}`);
|
| 105 |
+
}
|
| 106 |
+
} catch (error) {
|
| 107 |
+
console.error("Login error:", error);
|
| 108 |
+
alert("An unexpected error occurred. Please try again.");
|
| 109 |
+
}
|
| 110 |
+
});
|
| 111 |
|
| 112 |
+
// Sign-up handler
|
| 113 |
+
document.getElementById("signupForm").addEventListener("submit", async (event) => {
|
| 114 |
+
event.preventDefault();
|
| 115 |
|
| 116 |
+
const username = document.getElementById("signupUsername").value.trim();
|
| 117 |
+
const password = document.getElementById("signupPassword").value.trim();
|
|
|
|
|
|
|
| 118 |
|
| 119 |
+
if (!username || !password) {
|
| 120 |
+
alert("Both fields are required!");
|
| 121 |
+
return;
|
| 122 |
+
}
|
|
|
|
| 123 |
|
| 124 |
+
try {
|
| 125 |
+
const response = await fetch("/signup", {
|
| 126 |
+
method: "POST",
|
| 127 |
+
headers: { "Content-Type": "application/json" },
|
| 128 |
+
body: JSON.stringify({ username, password }),
|
|
|
|
|
|
|
| 129 |
});
|
| 130 |
+
|
| 131 |
+
if (response.ok) {
|
| 132 |
+
const data = await response.json(); // Expecting a success message
|
| 133 |
+
localStorage.setItem("username", username); // Save username to localStorage
|
| 134 |
+
alert("Sign-up successful! Redirecting to terminal...");
|
| 135 |
+
window.location.href = "/terminal.html"; // Redirect to terminal page
|
| 136 |
+
} else {
|
| 137 |
+
const message = await response.text();
|
| 138 |
+
alert(`Sign-up failed: ${message}`);
|
| 139 |
+
}
|
| 140 |
+
} catch (error) {
|
| 141 |
+
console.error("Sign-up error:", error);
|
| 142 |
+
alert("An unexpected error occurred. Please try again.");
|
| 143 |
+
}
|
| 144 |
+
});
|
| 145 |
</script>
|
| 146 |
</body>
|
| 147 |
</html>
|