From 2457b4b76f744838f0442c4b8a587f8197ba75fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anton=20Luka=20=C5=A0ijanec?= Date: Wed, 11 Mar 2020 18:50:02 +0100 Subject: gsec --- js/gsec.js | 39 +++++++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/js/gsec.js b/js/gsec.js index ecc156b..55d9dab 100644 --- a/js/gsec.js +++ b/js/gsec.js @@ -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); + } + }); + }); } } -- cgit v1.2.3