diff options
author | rstular <rok@stular.eu> | 2020-05-20 21:32:12 +0200 |
---|---|---|
committer | rstular <rok@stular.eu> | 2020-05-20 21:32:12 +0200 |
commit | 1df0f474227ffeb901e6c1a26d51e8bd04a9e25d (patch) | |
tree | 8676dad6195658317a1e2258461b4f07a2b12dbb /dist/js/login.js | |
parent | Changelog (diff) | |
parent | forgot i'm not doing anything (diff) | |
download | beziapp-1df0f474227ffeb901e6c1a26d51e8bd04a9e25d.tar beziapp-1df0f474227ffeb901e6c1a26d51e8bd04a9e25d.tar.gz beziapp-1df0f474227ffeb901e6c1a26d51e8bd04a9e25d.tar.bz2 beziapp-1df0f474227ffeb901e6c1a26d51e8bd04a9e25d.tar.lz beziapp-1df0f474227ffeb901e6c1a26d51e8bd04a9e25d.tar.xz beziapp-1df0f474227ffeb901e6c1a26d51e8bd04a9e25d.tar.zst beziapp-1df0f474227ffeb901e6c1a26d51e8bd04a9e25d.zip |
Diffstat (limited to 'dist/js/login.js')
-rw-r--r-- | dist/js/login.js | 62 |
1 files changed, 4 insertions, 58 deletions
diff --git a/dist/js/login.js b/dist/js/login.js index ab59058..88cf081 100644 --- a/dist/js/login.js +++ b/dist/js/login.js @@ -1,59 +1,5 @@ -// 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; - try { - gsecInstance = new gsec(); - } catch (error) { - $.ajax({ - url: 'js/gsec.js?ajaxload', - async: false, - dataType: "script", - }); - try { - gsecInstance = new gsec(); - } catch (error) { - alert(D("browserNotSupported")); - } - } - 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(""); - }); -} +document.addEventListener("DOMContentLoaded",()=>{setupEventListeners();}) +function setupEventListeners(){$("#login-button").click(()=>{login();});window.addEventListener("keyup",(event)=>{if(event.keyCode===13){event.preventDefault();login();}});} +function login(){let username=$("#username").val();let password=$("#password").val();var gsecInstance;try{gsecInstance=new gsec();}catch(error){$.ajax({url:'js/gsec.js?ajaxload',async:false,dataType:"script",});try{gsecInstance=new gsec();}catch(error){alert(D("browserNotSupported"));}} +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("");});}
\ No newline at end of file |