summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--js/gsec.js39
1 files 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);
+ }
+ });
+ });
}
}