diff options
| author | Pliable Pixels <pliablepixels@gmail.com> | 2018-07-25 12:39:05 -0400 |
|---|---|---|
| committer | Pliable Pixels <pliablepixels@gmail.com> | 2018-07-25 12:39:05 -0400 |
| commit | c086ac875e6e63b82fc37659c651459391ed05ae (patch) | |
| tree | 0374fc4bfb249599cd401af8dd0cb58258c06420 /www/js/app.js | |
| parent | 64e24b64b1cb303963cfd3b723dc80cb289b4f0e (diff) | |
#676 fixes for viewByName and other cleanup
Diffstat (limited to 'www/js/app.js')
| -rwxr-xr-x | www/js/app.js | 283 |
1 files changed, 162 insertions, 121 deletions
diff --git a/www/js/app.js b/www/js/app.js index c5c9c8ba..6be6d91a 100755 --- a/www/js/app.js +++ b/www/js/app.js @@ -1060,7 +1060,26 @@ angular.module('zmApp', [ //$http.get(loginAPI) .then(function (succ) { - NVRDataModel.debug ("API based login returned: "+JSON.stringify(succ)); + + if (!succ.data.version) { + + NVRDataModel.debug ("API login returned fake success, going back to webscrape"); + var ld = NVRDataModel.getLogin(); + ld.loginAPISupported = false; + NVRDataModel.setLogin(ld); + + loginWebScrape() + .then ( function (succ) { + d.resolve("Login Success"); + return d.promise; + }, + function (err) { + d.reject("Login Error"); + return (d.promise); + }); + return d.promise; + } + NVRDataModel.debug ("API based login returned... "); NVRDataModel.setCurrentServerVersion(succ.data.version); $ionicLoading.hide(); $rootScope.loggedIntoZm = 1; @@ -1074,9 +1093,9 @@ angular.module('zmApp', [ } } - var ld = NVRDataModel.getLogin(); - ld.loginAPISupported = true; - NVRDataModel.setLogin(ld); + var ldg = NVRDataModel.getLogin(); + ldg.loginAPISupported = true; + NVRDataModel.setLogin(ldg); NVRDataModel.log("Stream authentication construction: " + $rootScope.authSession); @@ -1098,156 +1117,178 @@ angular.module('zmApp', [ if ('success' in err.data) { console.log("API based login not supported, need to use web scraping..."); // login using old web scraping + var ld = NVRDataModel.getLogin(); + ld.loginAPISupported = false; + NVRDataModel.setLogin(ld); + loginWebScrape() + .then ( function (succ) { + d.resolve("Login Success"); + return d.promise; + }, + function (err) { + d.reject("Login Error"); + return (d.promise); + }); - NVRDataModel.debug("Logging in using old web-scrape method"); - NVRDataModel.isReCaptcha() - .then(function (result) { - if (result == true) { - $ionicLoading.hide(); - NVRDataModel.displayBanner('error', ['reCaptcha must be disabled', ], "", 8000); - var alertPopup = $ionicPopup.alert({ - title: 'reCaptcha enabled', - template: $translate.instant('kRecaptcha'), - okText: $translate.instant('kButtonOk'), - cancelText: $translate.instant('kButtonCancel'), - }); - - // close it after 5 seconds - $timeout(function () { - alertPopup.close(); - }, 5000); + } + else { + $rootScope.loggedIntoZm = -1; + //console.log("**** ZM Login FAILED"); + NVRDataModel.log("zmAutologin Error via API: some meta foo", "error"); + $rootScope.$broadcast('auth-error', "I'm confused why"); - d.reject("Error-disable recaptcha"); - return (d.promise); - } + d.reject("Login Error"); + return (d.promise); - }); + } - var hDelay = loginData.enableSlowLoading ? zm.largeHttpTimeout : zm.httpTimeout; - //NVRDataModel.debug ("*** AUTH LOGIN URL IS " + loginData.url); - $http({ - - method: 'POST', - timeout: hDelay, - //withCredentials: true, - url: loginData.url + '/index.php', - headers: { - 'Content-Type': 'application/x-www-form-urlencoded', - 'Accept': 'application/json', - }, - transformRequest: function (obj) { - var str = []; - for (var p in obj) - str.push(encodeURIComponent(p) + "=" + - encodeURIComponent(obj[p])); - var params = str.join("&"); - return params; - }, - - data: { - username: loginData.username, - password: loginData.password, - action: "login", - view: "console" - } - }) - .success(function (data, status, headers) { - // console.log(">>>>>>>>>>>>>> PARALLEL POST SUCCESS"); - $ionicLoading.hide(); + + } + ); - // Coming here does not mean success - // it could also be a bad login, but - // ZM returns you to login.php and returns 200 OK - // so we will check if the data has - // <title>ZM - Login</title> -- it it does then its the login page - if (data.indexOf(zm.loginScreenString) == -1) { - //eventServer.start(); - $rootScope.loggedIntoZm = 1; - NVRDataModel.log("zmAutologin successfully logged into Zoneminder"); + return d.promise; + } - d.resolve("Login Success"); + return d.promise; - $rootScope.$broadcast('auth-success', data); + } - } else // this means login error - { - $rootScope.loggedIntoZm = -1; - //console.log("**** ZM Login FAILED"); - NVRDataModel.log("zmAutologin Error: Bad Credentials ", "error"); - $rootScope.$broadcast('auth-error', "incorrect credentials"); + function loginWebScrape() { + var loginData = NVRDataModel.getLogin(); + var d = $q.defer(); + NVRDataModel.debug("Logging in using old web-scrape method"); + NVRDataModel.isReCaptcha() + .then(function (result) { + if (result == true) { + $ionicLoading.hide(); + NVRDataModel.displayBanner('error', ['reCaptcha must be disabled', ], "", 8000); + var alertPopup = $ionicPopup.alert({ + title: 'reCaptcha enabled', + template: $translate.instant('kRecaptcha'), + okText: $translate.instant('kButtonOk'), + cancelText: $translate.instant('kButtonCancel'), + }); - d.reject("Login Error"); - return (d.promise); - } + // close it after 5 seconds + $timeout(function () { - // Now go ahead and re-get auth key - // if login was a success - $rootScope.authSession = "undefined"; - var ld = NVRDataModel.getLogin(); - NVRDataModel.getAuthKey($rootScope.validMonitorId) - .then(function (success) { + alertPopup.close(); + }, 5000); - //console.log(success); - $rootScope.authSession = success; - NVRDataModel.log("Stream authentication construction: " + - $rootScope.authSession); + d.reject("Error-disable recaptcha"); + return (d.promise); + } - }, - function (error) { - //console.log(error); + }); - NVRDataModel.log("Modal: Error returned Stream authentication construction. Retaining old value of: " + $rootScope.authSession); - NVRDataModel.debug("Error was: " + JSON.stringify(error)); - }); + var hDelay = loginData.enableSlowLoading ? zm.largeHttpTimeout : zm.httpTimeout; + //NVRDataModel.debug ("*** AUTH LOGIN URL IS " + loginData.url); + $http({ + + method: 'POST', + timeout: hDelay, + //withCredentials: true, + url: loginData.url + '/index.php', + headers: { + 'Content-Type': 'application/x-www-form-urlencoded', + 'Accept': 'application/json', + }, + transformRequest: function (obj) { + var str = []; + for (var p in obj) + str.push(encodeURIComponent(p) + "=" + + encodeURIComponent(obj[p])); + var params = str.join("&"); + return params; + }, - return (d.promise); + data: { + username: loginData.username, + password: loginData.password, + action: "login", + view: "console" + } + }) + .success(function (data, status, headers) { + // console.log(">>>>>>>>>>>>>> PARALLEL POST SUCCESS"); + $ionicLoading.hide(); - }) - .error(function (error, status) { + // Coming here does not mean success + // it could also be a bad login, but + // ZM returns you to login.php and returns 200 OK + // so we will check if the data has + // <title>ZM - Login</title> -- it it does then its the login page - // console.log(">>>>>>>>>>>>>> PARALLEL POST ERROR"); - $ionicLoading.hide(); + if (data.indexOf(zm.loginScreenString) == -1) { + //eventServer.start(); + $rootScope.loggedIntoZm = 1; - //console.log("**** ZM Login FAILED"); + NVRDataModel.log("zmAutologin successfully logged into Zoneminder"); + $rootScope.apiValid = true; - // FIXME: Is this sometimes results in null + // now go to authKey part, so don't return yet... - NVRDataModel.log("zmAutologin Error " + JSON.stringify(error) + " and status " + status); - // bad urls etc come here - $rootScope.loggedIntoZm = -1; - $rootScope.$broadcast('auth-error', error); + } else // this means login error + { + $rootScope.loggedIntoZm = -1; + //console.log("**** ZM Login FAILED"); + NVRDataModel.log("zmAutologin Error: Bad Credentials ", "error"); + $rootScope.$broadcast('auth-error', "incorrect credentials"); + + d.reject("Login Error"); + return (d.promise); + // no need to go to next code, so return above + } - d.reject("Login Error"); - return d.promise; - }); + // Now go ahead and re-get auth key + // if login was a success + $rootScope.authSession = "undefined"; + var ld = NVRDataModel.getLogin(); + NVRDataModel.getAuthKey($rootScope.validMonitorId) + .then(function (success) { + //console.log(success); + $rootScope.authSession = success; + NVRDataModel.log("Stream authentication construction: " + + $rootScope.authSession); + d.resolve("Login Success"); + $rootScope.$broadcast('auth-success', data); + return d.promise; - } - else { - $rootScope.loggedIntoZm = -1; - //console.log("**** ZM Login FAILED"); - NVRDataModel.log("zmAutologin Error via API: some meta foo", "error"); - $rootScope.$broadcast('auth-error', "I'm confused why"); + }, + function (error) { + //console.log(error); - d.reject("Login Error"); - return (d.promise); + NVRDataModel.log("Modal: Error returned Stream authentication construction. Retaining old value of: " + $rootScope.authSession); + NVRDataModel.debug("Error was: " + JSON.stringify(error)); + d.resolve("Login Success"); + $rootScope.$broadcast('auth-success', data); + }); - } + return (d.promise); - - } - ); + }) + .error(function (error, status) { + // console.log(">>>>>>>>>>>>>> PARALLEL POST ERROR"); + $ionicLoading.hide(); + //console.log("**** ZM Login FAILED"); - return d.promise; - } + // FIXME: Is this sometimes results in null - return d.promise; + NVRDataModel.log("zmAutologin Error " + JSON.stringify(error) + " and status " + status); + // bad urls etc come here + $rootScope.loggedIntoZm = -1; + $rootScope.$broadcast('auth-error', error); + d.reject("Login Error"); + return d.promise; + }); + return d.promise; } function start() { |
