diff options
| author | pliablepixels <pliablepixels@gmail.com> | 2016-02-23 10:08:01 -0500 |
|---|---|---|
| committer | pliablepixels <pliablepixels@gmail.com> | 2016-02-23 10:08:01 -0500 |
| commit | 66699eb8355d86982449f990d77af5838c08bac6 (patch) | |
| tree | 6ccb719fc0f6cfcf4831c45c80e8ebfa84d9c5c9 /www/js/LoginCtrl.js | |
| parent | 5604519f5a9f1e46269442a4e430e05f0e84d7a9 (diff) | |
#167 - logs out of current session before logging in again, so that old credentials are not borrowed
Former-commit-id: b59025e7725392ca2228fad0e3b8ccb684aaf08d
Diffstat (limited to 'www/js/LoginCtrl.js')
| -rw-r--r-- | www/js/LoginCtrl.js | 168 |
1 files changed, 97 insertions, 71 deletions
diff --git a/www/js/LoginCtrl.js b/www/js/LoginCtrl.js index a6d39e91..1f601149 100644 --- a/www/js/LoginCtrl.js +++ b/www/js/LoginCtrl.js @@ -406,82 +406,108 @@ angular.module('zmApp.controllers').controller('zmApp.LoginCtrl', ['$scope', '$r } + + // lets logout + ZMDataModel.zmDebug ("Logging out of current session..."); + $rootScope.authSession = "undefined"; + $http({ + method: 'POST', + //withCredentials: true, + url: $scope.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; + }, - - - - zmAutoLogin.doLogin("<button class='button button-clear' style='line-height: normal; min-height: 0; min-width: 0;' ng-click='$root.cancelAuth()'><i class='ion-close-circled'></i> authenticating...</button>") - // Do the happy menu only if authentication works - // if it does not work, there is an emitter for auth - // fail in app.js that will be called to show an error - // box - - .then(function (data) { - - // Now let's validate if the API works - - ZMDataModel.zmLog("Validating APIs at " + apiurl); - $http.get(apiurl) - .success(function (data) { - - var loginStatus = "Please explore the menu and enjoy zmNinja!"; - EventServer.refresh(); - - - - // now grab and report PATH_ZMS - ZMDataModel.getPathZms() - .then(function (data) { - var ld = ZMDataModel.getLogin(); - var zm_cgi = data.toLowerCase(); - - var user_cgi = (ld.streamingurl).toLowerCase(); - ZMDataModel.zmLog("ZM relative cgi-path: " + zm_cgi + ", you entered: " + user_cgi); - - $http.get(ld.streamingurl + "/zms") - .success(function (data) { - ZMDataModel.zmDebug("Urk! cgi-path returned success, but it should not have come here"); - loginStatus = "Login validated, but could not validate cgi-path. If live streams don't work please check your cgi-bin path"; - $rootScope.zmPopup = $ionicPopup.alert({ - title: 'Login validated', - template: loginStatus - }).then(function (res) { - $ionicSideMenuDelegate.toggleLeft(); - ZMDataModel.zmDebug("Force reloading monitors..."); - var refresh = ZMDataModel.getMonitors(1); - }); - }) - .error(function (error, status) { - // If its 5xx, then the cgi-bin path is valid - // if its 4xx then the cgi-bin path is not valid - - if (status < 500) { - loginStatus = "The cgi-bin path you entered may be wrong. I can't make sure, but if your live views don't work, please review your cgi path."; - } - - $rootScope.zmPopup = $ionicPopup.alert({ - title: 'Login validated', - template: loginStatus - }).then(function (res) { - $ionicSideMenuDelegate.toggleLeft(); - ZMDataModel.zmDebug("Force reloading monitors..."); - var refresh = ZMDataModel.getMonitors(1); - }); - - + data: { + action: "logout", + view: "login" + } + }) + .finally ( function (ans) + { + + zmAutoLogin.doLogin("<button class='button button-clear' style='line-height: normal; min-height: 0; min-width: 0;' ng-click='$root.cancelAuth()'><i class='ion-close-circled'></i> authenticating...</button>") + // Do the happy menu only if authentication works + // if it does not work, there is an emitter for auth + // fail in app.js that will be called to show an error + // box + + .then(function (data) { + + // Now let's validate if the API works + + ZMDataModel.zmLog("Validating APIs at " + apiurl); + $http.get(apiurl) + .success(function (data) { + + var loginStatus = "Please explore the menu and enjoy zmNinja!"; + EventServer.refresh(); + + + + // now grab and report PATH_ZMS + ZMDataModel.getPathZms() + .then(function (data) { + var ld = ZMDataModel.getLogin(); + var zm_cgi = data.toLowerCase(); + + var user_cgi = (ld.streamingurl).toLowerCase(); + ZMDataModel.zmLog("ZM relative cgi-path: " + zm_cgi + ", you entered: " + user_cgi); + + $http.get(ld.streamingurl + "/zms") + .success(function (data) { + ZMDataModel.zmDebug("Urk! cgi-path returned success, but it should not have come here"); + loginStatus = "Login validated, but could not validate cgi-path. If live streams don't work please check your cgi-bin path"; + $rootScope.zmPopup = $ionicPopup.alert({ + title: 'Login validated', + template: loginStatus + }).then(function (res) { + $ionicSideMenuDelegate.toggleLeft(); + ZMDataModel.zmDebug("Force reloading monitors..."); + var refresh = ZMDataModel.getMonitors(1); + }); + }) + .error(function (error, status) { + // If its 5xx, then the cgi-bin path is valid + // if its 4xx then the cgi-bin path is not valid + + if (status < 500) { + loginStatus = "The cgi-bin path you entered may be wrong. I can't make sure, but if your live views don't work, please review your cgi path."; + } + + $rootScope.zmPopup = $ionicPopup.alert({ + title: 'Login validated', + template: loginStatus + }).then(function (res) { + $ionicSideMenuDelegate.toggleLeft(); + ZMDataModel.zmDebug("Force reloading monitors..."); + var refresh = ZMDataModel.getMonitors(1); + }); + + + }); }); - }); - }) - .error(function (error) { - ZMDataModel.displayBanner('error', ['ZoneMinder API check failed', 'Please check API settings']); - ZMDataModel.zmLog("API login error " + JSON.stringify(error)); - $rootScope.zmPopup= $ionicPopup.alert({ - title: 'Login validated but API failed', - template: 'Please check your API settings' - }); + }) + .error(function (error) { + ZMDataModel.displayBanner('error', ['ZoneMinder API check failed', 'Please check API settings']); + ZMDataModel.zmLog("API login error " + JSON.stringify(error)); + $rootScope.zmPopup= $ionicPopup.alert({ + title: 'Login validated but API failed', + template: 'Please check your API settings' + }); + }); }); |
