X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=testing%2FMCTXWeb%2Fpublic_html%2Fstatic%2Fmctx.gui.js;fp=testing%2FMCTXWeb%2Fpublic_html%2Fstatic%2Fmctx.gui.js;h=fc50ed560965d8e247df00a4e5434dd9929cd9ba;hb=82a6b5b578988edff1288628a838dcd63bc07909;hp=247484d77f4087421ebd0c5e36b627627a12fd36;hpb=bb0959bbec05c36ab1118ddefc4894faf28f0fa0;p=matches%2FMCTX3420.git diff --git a/testing/MCTXWeb/public_html/static/mctx.gui.js b/testing/MCTXWeb/public_html/static/mctx.gui.js index 247484d..fc50ed5 100644 --- a/testing/MCTXWeb/public_html/static/mctx.gui.js +++ b/testing/MCTXWeb/public_html/static/mctx.gui.js @@ -3,9 +3,9 @@ */ mctx = {}; -mctx.api = location.protocol + "//" + location.host + "/api/"; +mctx.location = location.protocol + "//" + location.host; +mctx.api = mctx.location + "/api/"; mctx.expected_api_version = 0; -mctx.key = undefined; mctx.has_control = false; mctx.return_codes = { @@ -154,30 +154,27 @@ $.fn.setStrainGraphs = function () { $.fn.login = function () { var username = this.find("input[name='username']").val(); var password = this.find("input[name='pass']").val(); - var force = this.find("input[name='force']").is(":checked"); - var url = mctx.api + "control"; - - var authFunc = function(xhr) { - xhr.setRequestHeader("Authorization", - "Basic " + base64.encode(username + ":" + password)); + var out = this.find("#result"); + var redirect = function () { + window.location.href = mctx.location; }; - + + out.removeAttr("class"); + out.text("Logging in..."); + $.ajax({ - url : url, - data : {action : "lock", force : (force ? true : undefined)}, - beforeSend : authFunc + url : mctx.api + "bind", + data : {user: username, pass : password} }).done(function (data) { - mctx.key = data.key; - if (data.status < 0) { - alert("no - " + data.description); - } else { - mctx.has_control = true; - alert("yes - " + mctx.key); - } + //todo: error check + mctx.has_control = true; + out.attr("class", "pass"); + out.text("Login ok!"); + setTimeout(redirect, 1000); }).fail(function (jqXHR) { - mctx.key = undefined; mctx.has_control = false; - alert("no"); + out.attr("class", "fail"); + out.text("Login request failed - connection issues.") }); };