From 6ba597ed42a0ebbb340112ab1b9a8316dc8f26cd Mon Sep 17 00:00:00 2001 From: Robert Kaiser Date: Fri, 10 Nov 2017 21:25:51 +0100 Subject: [PATCH] move login window functions into a separate JS file and add debug statements --- js/loginwindow.js | 19 +++++++++++++++++++ js/ui.js | 15 --------------- login.html | 4 ++-- manifest.appcache | 3 ++- 4 files changed, 23 insertions(+), 18 deletions(-) create mode 100644 js/loginwindow.js diff --git a/js/loginwindow.js b/js/loginwindow.js new file mode 100644 index 0000000..ebbdde4 --- /dev/null +++ b/js/loginwindow.js @@ -0,0 +1,19 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ +console.log("JS-load"); + +window.onload = function() { + // Complete the login process by calling the main window. + console.log("onload"); + if (window.opener) { + console.log("opener"); + window.opener.finishLogin(getParameterByName("code"), getParameterByName("state")); + console.log("finished"); + window.close(); + } + else { + console.log("no-opener"); + document.getElementById("logininfo").textContent = "You have called this document outside of the login flow, which is not supported."; + } +} diff --git a/js/ui.js b/js/ui.js index f451fbe..7526763 100644 --- a/js/ui.js +++ b/js/ui.js @@ -17,11 +17,6 @@ var gBackendURL = "https://backend.lantea.kairo.at"; var gAuthClientID = "lantea"; window.onload = function() { - if (/\/login\.html/.test(window.location)) { - // If we are in the login window, call a function to complete the process and don't do anything else here. - completeLoginWindow(); - return; - } gAction = document.getElementById("action"); gActionLabel = document.getElementById("actionlabel"); @@ -175,16 +170,6 @@ function prepareLoginButton(aCallback) { ); } -function completeLoginWindow() { - if (window.opener) { - window.opener.finishLogin(getParameterByName("code"), getParameterByName("state")); - window.close(); - } - else { - document.getElementById("logininfo").textContent = "You have called this document outside of the login flow, which is not supported."; - } -} - function finishLogin(aCode, aState) { if (aState == authData["state"]) { fetchBackend("login?code=" + aCode + "&state=" + aState + "&redirect_uri=" + encodeURIComponent(getRedirectURI()), "GET", null, diff --git a/login.html b/login.html index 8eafcbd..b406349 100644 --- a/login.html +++ b/login.html @@ -10,8 +10,8 @@ https://developer.mozilla.org/en/Mobile/Viewport_meta_tag --> Lantea Login - - + + diff --git a/manifest.appcache b/manifest.appcache index 67b8bc1..9ead495 100644 --- a/manifest.appcache +++ b/manifest.appcache @@ -1,12 +1,13 @@ CACHE MANIFEST -# 2017-10-23 +# 2017-11-10 index.html login.html manifest.webapp js/map.js js/ui.js js/library.js +js/loginwindow.js style/lantea.css style/loading.png style/loading_action.png -- 2.35.3