From f0acacec6a3db86693a981589e69fe0ca09fc854 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Fri, 18 Dec 2015 14:30:53 +0100 Subject: [PATCH 1/3] Intermediary page needs to remove fragments for baseUrl Otherwise image pinging won't work properly. --- src/octoprint/static/intermediary.html | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/octoprint/static/intermediary.html b/src/octoprint/static/intermediary.html index 7e28c6ad..b315210a 100644 --- a/src/octoprint/static/intermediary.html +++ b/src/octoprint/static/intermediary.html @@ -133,6 +133,9 @@ var timeout = 1500; var baseUrl = window.location.href; + if (baseUrl.indexOf("#") > -1) { + baseUrl = baseUrl.substring(0, baseUrl.indexOf("#")); + } if (baseUrl.indexOf("/static") > -1) { baseUrl = baseUrl.substring(0, baseUrl.indexOf("/static")) + "/"; } From c120261e2b8fbc2d79f4268627bf5f79aabf8d57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Fri, 18 Dec 2015 17:29:31 +0100 Subject: [PATCH 2/3] Increased backend fail counter for intermediary page Also made sure that baseURL always ends in a / --- src/octoprint/static/intermediary.html | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/octoprint/static/intermediary.html b/src/octoprint/static/intermediary.html index b315210a..4aa7276a 100644 --- a/src/octoprint/static/intermediary.html +++ b/src/octoprint/static/intermediary.html @@ -109,6 +109,8 @@ urlToUse += "?" + postfix; } + console.log("Pinging " + url); + img.onload = function() { callback("load"); calledBack = true; @@ -119,6 +121,7 @@ calledBack = true; } }; + img.src = urlToUse; setTimeout(function() { if (!calledBack) { @@ -137,7 +140,10 @@ baseUrl = baseUrl.substring(0, baseUrl.indexOf("#")); } if (baseUrl.indexOf("/static") > -1) { - baseUrl = baseUrl.substring(0, baseUrl.indexOf("/static")) + "/"; + baseUrl = baseUrl.substring(0, baseUrl.indexOf("/static")); + } + if (baseUrl[baseUrl.length - 1] != "/") { + baseUrl += "/"; } var serverOnlineUrl = baseUrl + "online.gif"; var backendOnlineUrl = baseUrl + "intermediary.gif"; @@ -161,7 +167,6 @@ interval = intervals.shift(); } serverTimeout = setTimeout(function() { - console.log("Pinging " + serverOnlineUrl); ping(serverOnlineUrl, timeout, serverOnlineCallback); }, interval * 1000) } @@ -181,7 +186,7 @@ } backendOfflineCounter++; - if (backendOfflineCounter > 5) { + if (backendOfflineCounter > 10) { if (serverTimeout) { window.clearTimeout(serverTimeout); } From 34ceb935094e5c906a934a452a33fcd3a1304cc2 Mon Sep 17 00:00:00 2001 From: Paul de Vries Date: Sun, 3 Jan 2016 22:02:49 +0100 Subject: [PATCH 3/3] Initialize loginUser and loginPass with an empty string Clear loginUser and loginPass after a successful login (e.g. the user made a typo) --- .../static/js/app/viewmodels/loginstate.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/octoprint/static/js/app/viewmodels/loginstate.js b/src/octoprint/static/js/app/viewmodels/loginstate.js index 25e126c6..5d071740 100644 --- a/src/octoprint/static/js/app/viewmodels/loginstate.js +++ b/src/octoprint/static/js/app/viewmodels/loginstate.js @@ -2,8 +2,8 @@ $(function() { function LoginStateViewModel() { var self = this; - self.loginUser = ko.observable(); - self.loginPass = ko.observable(); + self.loginUser = ko.observable(""); + self.loginPass = ko.observable(""); self.loginRemember = ko.observable(false); self.loggedIn = ko.observable(false); @@ -79,10 +79,6 @@ $(function() { var password = self.loginPass(); var remember = self.loginRemember(); - self.loginUser(""); - self.loginPass(""); - self.loginRemember(false); - $.ajax({ url: API_BASEURL + "login", type: "POST", @@ -90,6 +86,10 @@ $(function() { success: function(response) { new PNotify({title: gettext("Login successful"), text: _.sprintf(gettext('You are now logged in as "%(username)s"'), {username: response.name}), type: "success"}); self.fromResponse(response); + + self.loginUser(""); + self.loginPass(""); + self.loginRemember(false); }, error: function(jqXHR, textStatus, errorThrown) { new PNotify({title: gettext("Login failed"), text: gettext("User unknown or wrong password"), type: "error"}); @@ -138,4 +138,4 @@ $(function() { [], [] ]); -}); \ No newline at end of file +});