summaryrefslogtreecommitdiff
path: root/scripts/login.js
diff options
context:
space:
mode:
authorKai Gunger <kgunger12@gmail.com>2026-11-17 02:19:46 -0500
committerKai Gunger <kgunger12@gmail.com>2026-11-17 02:19:46 -0500
commit0c9e372e9076749a7603cd0dd822d60cc3de9531 (patch)
tree953357333ad85b81ff858772bef4667d38a4070e /scripts/login.js
parentedca74d8558e7fd212e5cd19abaeafada5a0b73e (diff)
Add scriptingHEADmain
Diffstat (limited to 'scripts/login.js')
-rw-r--r--scripts/login.js31
1 files changed, 31 insertions, 0 deletions
diff --git a/scripts/login.js b/scripts/login.js
new file mode 100644
index 0000000..bc41fd4
--- /dev/null
+++ b/scripts/login.js
@@ -0,0 +1,31 @@
+(() => {
+ /**
+ * Login to the api layer
+ * @param {ProgressEvent} e
+ * @this {XMLHttpRequest}
+ */
+ function login (e) {
+ if (this.status == 200) {
+ // Go back to home
+ window.location = "/";
+ } else {
+ // Show invalid username/password text
+ alert("Invalid username or password!");
+ }
+ }
+
+ /** @type {HTMLInputElement} */
+ let username = document.getElementById("username");
+ /** @type {HTMLInputElement} */
+ let password = document.getElementById("password");
+
+ document.getElementById("login").addEventListener("click", () => {
+ let login_req = new XMLHttpRequest();
+ login_req.addEventListener("load", login);
+ login_req.open("POST", API_BASE_URL + "/user/login");
+ login_req.send(JSON.stringify({
+ username: username.value,
+ password: password.value,
+ }));
+ })
+})(); \ No newline at end of file