diff options
author | Anton Luka Šijanec <sijanecantonluka@gmail.com> | 2020-03-11 18:50:02 +0100 |
---|---|---|
committer | Anton Luka Šijanec <sijanecantonluka@gmail.com> | 2020-03-11 18:50:02 +0100 |
commit | 2457b4b76f744838f0442c4b8a587f8197ba75fb (patch) | |
tree | 584021c28e4d16ce796a150781541469eeb04197 | |
parent | started rewriting gsec to JS (diff) | |
download | beziapp-2457b4b76f744838f0442c4b8a587f8197ba75fb.tar beziapp-2457b4b76f744838f0442c4b8a587f8197ba75fb.tar.gz beziapp-2457b4b76f744838f0442c4b8a587f8197ba75fb.tar.bz2 beziapp-2457b4b76f744838f0442c4b8a587f8197ba75fb.tar.lz beziapp-2457b4b76f744838f0442c4b8a587f8197ba75fb.tar.xz beziapp-2457b4b76f744838f0442c4b8a587f8197ba75fb.tar.zst beziapp-2457b4b76f744838f0442c4b8a587f8197ba75fb.zip |
-rw-r--r-- | js/gsec.js | 39 |
1 files changed, 29 insertions, 10 deletions
@@ -1,15 +1,13 @@ // tab = 2 || any spaces; use tabs -const GSE_URL = "https://zgimsis.gimb.tk/gse/" +const GSE_URL = "https://zgimsis.gimb.tk/gse/"; class gsec { - constructor(gseuser = null, gsepass = null) { - this.gseuser = gseuser; - this.gsepass = gsepass; + constructor() { } - postback(theUrl, params, formId = null) { - return Promise( (resolve, reject) => { + postback(getUrl, params, formId = null) { + return new Promise( (resolve, reject) => { $.ajax({ crossDomain: true, - url: theUrl, + url: getUrl, cache: false, type: "GET", dataType: "html", @@ -22,19 +20,40 @@ class gsec { var form = parsed.getElementById(formId); } var otherParams = $(form).serializeArray(); - var action = form.getAttribute("action"); // absolute url + for(const input of otherParams) { + if(!(input.name in params)) { + params[input.name] = input.value; // so we don't overwrite existing values + } + } + var action = new URL($(form).attr("action"), GSE_URL); // absolute == relative + base $.ajax({ crossDomain: true, url: action, cache: false, type: "POST", + data: params, dataType: "text", - success: (postData) { + success: (postData) => { resolve(postData); } }); } }); - } + }); + } + login(usernameToLogin, passwordToLogin) { + return new Promise((resolve, reject) => { + var dataToSend = {"edtGSEUserId": usernameToLogin, "edtGSEUserPassword": passwordToLogin, "btnLogin": "Prijava"}; + this.postback(GSE_URL+"Logon.aspx", dataToSend).then( (response) => { + var parsed = document.createElement("html"); + parsed.innerHTML = response; + var simpleResponse = parsed.getElementById("lblMsg"); + if( simpleResponse = "Napaka pri prijavi.") { + reject(new Error(false)); + } else { + resolve(true); + } + }); + }); } } |