diff options
author | Anton Luka Šijanec <sijanecantonluka@gmail.com> | 2020-03-21 00:58:21 +0100 |
---|---|---|
committer | Anton Luka Šijanec <sijanecantonluka@gmail.com> | 2020-03-21 00:58:21 +0100 |
commit | a4e25ed95b896f39aadec6123543dae1bc80e8fd (patch) | |
tree | e1143b3e1e7ec390f5a655cb497ada5db1a0a0bd /js/login.js | |
parent | gsec.js fix (diff) | |
download | beziapp-a4e25ed95b896f39aadec6123543dae1bc80e8fd.tar beziapp-a4e25ed95b896f39aadec6123543dae1bc80e8fd.tar.gz beziapp-a4e25ed95b896f39aadec6123543dae1bc80e8fd.tar.bz2 beziapp-a4e25ed95b896f39aadec6123543dae1bc80e8fd.tar.lz beziapp-a4e25ed95b896f39aadec6123543dae1bc80e8fd.tar.xz beziapp-a4e25ed95b896f39aadec6123543dae1bc80e8fd.tar.zst beziapp-a4e25ed95b896f39aadec6123543dae1bc80e8fd.zip |
Diffstat (limited to '')
-rw-r--r-- | js/login.js | 67 |
1 files changed, 22 insertions, 45 deletions
diff --git a/js/login.js b/js/login.js index d7c9579..281f7bc 100644 --- a/js/login.js +++ b/js/login.js @@ -1,4 +1,4 @@ -const API_ENDPOINT = "https://gimb.tk/test.php"; +// const API_ENDPOINT = "https://gimb.tk/test.php"; // deprecated document.addEventListener("DOMContentLoaded", () => { setupEventListeners(); }) @@ -21,48 +21,25 @@ function setupEventListeners() { // Handle login button click function login() { - // Get text input values - let username = $("#username").val(); - let password = $("#password").val(); - - // Make a request - $.ajax({ - url: API_ENDPOINT, - crossDomain: true, - - data: { - "u": username, - "p": password, - "m": "fetchprofil" - }, - dataType: "json", - - cache: false, - type: "GET", - - success: function (data) { - - // If ime is null, the password was incorrect - if (data["ime"] === null) { - UIAlert( S("loginFailed"), "login(): fetchprofil null name; bad login info." ); - $("#password").val(""); - } else { - - 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"); - }); - - } - }, - - error: function () { - UIAlert( S("noInternetConnection"), "login(): $.ajax error" ); - } - - }) + 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(""); + }); } |