summaryrefslogtreecommitdiffstats
path: root/dist/js/login.js
diff options
context:
space:
mode:
authorsijanec <sijanecantonluka@gmail.com>2020-05-20 14:12:06 +0200
committersijanec <sijanecantonluka@gmail.com>2020-05-20 14:12:06 +0200
commit7820ea23532aa6ffa3611d8379681aa44a3f3864 (patch)
treea8e0f9b1133a535b207724d20e75d1305b292040 /dist/js/login.js
parentinstall scritp fix (diff)
downloadbeziapp-7820ea23532aa6ffa3611d8379681aa44a3f3864.tar
beziapp-7820ea23532aa6ffa3611d8379681aa44a3f3864.tar.gz
beziapp-7820ea23532aa6ffa3611d8379681aa44a3f3864.tar.bz2
beziapp-7820ea23532aa6ffa3611d8379681aa44a3f3864.tar.lz
beziapp-7820ea23532aa6ffa3611d8379681aa44a3f3864.tar.xz
beziapp-7820ea23532aa6ffa3611d8379681aa44a3f3864.tar.zst
beziapp-7820ea23532aa6ffa3611d8379681aa44a3f3864.zip
Diffstat (limited to '')
-rw-r--r--dist/js/login.js45
1 files changed, 45 insertions, 0 deletions
diff --git a/dist/js/login.js b/dist/js/login.js
new file mode 100644
index 0000000..4633306
--- /dev/null
+++ b/dist/js/login.js
@@ -0,0 +1,45 @@
+// const API_ENDPOINT = "https://gimb.tk/test.php"; // deprecated
+document.addEventListener("DOMContentLoaded", () => {
+ setupEventListeners();
+})
+
+function setupEventListeners() {
+ // Setup login button listener
+ $("#login-button").click(() => {
+ login();
+ });
+
+ window.addEventListener("keyup", (event) => {
+ // Number 13 is the "Enter" key on the keyboard
+ if (event.keyCode === 13) {
+ // Cancel the default action, if needed
+ event.preventDefault();
+ login();
+ }
+ });
+}
+
+// Handle login button click
+function login() {
+ let username = $("#username").val();
+ let password = $("#password").val();
+ var gsecInstance = new gsec();
+ gsecInstance.login(username, password).then( (value) => {
+ if (typeof value == "string") {
+ let promises_to_run = [
+ localforage.setItem("logged_in", true),
+ localforage.setItem("username", username),
+ localforage.setItem("password", password)
+ ];
+ Promise.all(promises_to_run).then(function () {
+ window.location.replace("/pages/timetable.html");
+ });
+ } else {
+ UIAlert("loginFailed");
+ $("#password").val("");
+ }
+ }).catch((err) => {
+ gsecErrorHandlerUI(err);
+ $("#password").val("");
+ });
+}