diff options
| author | Pliable Pixels <pliablepixels@gmail.com> | 2016-11-18 09:28:08 -0500 |
|---|---|---|
| committer | Pliable Pixels <pliablepixels@gmail.com> | 2016-11-18 09:28:08 -0500 |
| commit | 31ca68739126f5740681238539a8c6a1b66e0000 (patch) | |
| tree | ddd6317b70ae500f63a3231a0639c54a02129c20 /www/js/PortalLoginCtrl.js | |
| parent | cf93ca01f3d54fca62d4222f110c2a63b526badb (diff) | |
mass formatting and normalization - tweaked JSBeautify options
Diffstat (limited to 'www/js/PortalLoginCtrl.js')
| -rw-r--r-- | www/js/PortalLoginCtrl.js | 221 |
1 files changed, 138 insertions, 83 deletions
diff --git a/www/js/PortalLoginCtrl.js b/www/js/PortalLoginCtrl.js index f99932a2..ff2f61d0 100644 --- a/www/js/PortalLoginCtrl.js +++ b/www/js/PortalLoginCtrl.js @@ -3,90 +3,108 @@ /*This is for the loop closure I am using in line 143 */ /* jslint browser: true*/ /* global vis,cordova,StatusBar,angular,console,moment */ -angular.module('zmApp.controllers').controller('zmApp.PortalLoginCtrl', ['$ionicPlatform', '$scope', 'zm', 'NVRDataModel', '$ionicSideMenuDelegate', '$rootScope', '$http', '$q', '$state', '$ionicLoading', '$ionicPopover', '$ionicScrollDelegate', '$ionicModal', '$timeout', 'zmAutoLogin', '$ionicHistory', '$cordovaTouchID', 'EventServer', '$translate', function($ionicPlatform, $scope, zm, NVRDataModel, $ionicSideMenuDelegate, $rootScope, $http, $q, $state, $ionicLoading, $ionicPopover, $ionicScrollDelegate, $ionicModal, $timeout, zmAutoLogin, $ionicHistory, $cordovaTouchID, EventServer, $translate) { - +angular.module('zmApp.controllers').controller('zmApp.PortalLoginCtrl', ['$ionicPlatform', '$scope', 'zm', 'NVRDataModel', '$ionicSideMenuDelegate', '$rootScope', '$http', '$q', '$state', '$ionicLoading', '$ionicPopover', '$ionicScrollDelegate', '$ionicModal', '$timeout', 'zmAutoLogin', '$ionicHistory', '$cordovaTouchID', 'EventServer', '$translate', function($ionicPlatform, $scope, zm, NVRDataModel, $ionicSideMenuDelegate, $rootScope, $http, $q, $state, $ionicLoading, $ionicPopover, $ionicScrollDelegate, $ionicModal, $timeout, zmAutoLogin, $ionicHistory, $cordovaTouchID, EventServer, $translate) +{ $scope.$on('$ionicView.enter', - function() { + function() + { NVRDataModel.debug("Inside Portal login Enter handler"); loginData = NVRDataModel.getLogin(); - $ionicHistory.nextViewOptions({ + $ionicHistory.nextViewOptions( + { disableBack: true }); - $scope.pindata = {}; - if ($ionicSideMenuDelegate.isOpen()) { + if ($ionicSideMenuDelegate.isOpen()) + { $ionicSideMenuDelegate.toggleLeft(); NVRDataModel.debug("Sliding menu close"); } - $scope.pinPrompt = false; // if true, then PIN is displayed else skip - if (NVRDataModel.isLoggedIn()) { + if (NVRDataModel.isLoggedIn()) + { NVRDataModel.log("User credentials are provided"); - - // You can login either via touch ID or typing in your code - if ($ionicPlatform.is('ios') && loginData.usePin) { + if ($ionicPlatform.is('ios') && loginData.usePin) + { $cordovaTouchID.checkSupport() - .then(function() { + .then(function() + { // success, TouchID supported $cordovaTouchID.authenticate("") - .then(function() { + .then(function() + { NVRDataModel.log("Touch Success"); // Don't assign pin as it may be alphanum unlock(true); }, - function() { + function() + { NVRDataModel.log("Touch Failed"); }); - }, function(error) { + }, function(error) + { NVRDataModel.log("TouchID not supported"); }); - } else // touch was not used + } + else // touch was not used { NVRDataModel.log("not checking for touchID"); } - if (loginData.usePin) { + if (loginData.usePin) + { // this shows the pin prompt on screen $scope.pinPrompt = true; // dont call unlock, let the user type in code - } else // no PIN Code so go directly to auth + } + else // no PIN Code so go directly to auth { unlock(true); } - } else // login creds are not present + } + else // login creds are not present { NVRDataModel.debug("PortalLogin: Not logged in, so going to login"); - if (NVRDataModel.isFirstUse()) { + if (NVRDataModel.isFirstUse()) + { NVRDataModel.debug("First use, showing warm and fuzzy..."); - $ionicHistory.nextViewOptions({ + $ionicHistory.nextViewOptions( + { disableAnimate: true, disableBack: true }); $state.go('first-use'); return; - } else { - if (!$rootScope.userCancelledAuth) { - $ionicHistory.nextViewOptions({ + } + else + { + if (!$rootScope.userCancelledAuth) + { + $ionicHistory.nextViewOptions( + { disableAnimate: true, disableBack: true }); - $state.go("login", { + $state.go("login", + { "wizard": false }); return; - } else { + } + else + { // do this only once - rest for next time $rootScope.userCancelledAuth = false; } @@ -99,8 +117,10 @@ angular.module('zmApp.controllers').controller('zmApp.PortalLoginCtrl', ['$ionic // remove status is pin is empty //------------------------------------------------------------------------------- - $scope.pinChange = function() { - if ($scope.pindata.pin == null) { + $scope.pinChange = function() + { + if ($scope.pindata.pin == null) + { $scope.pindata.status = ""; } }; @@ -108,17 +128,18 @@ angular.module('zmApp.controllers').controller('zmApp.PortalLoginCtrl', ['$ionic //------------------------------------------------------------------------------- // unlock app if PIN is correct //------------------------------------------------------------------------------- - $scope.unlock = function() { + $scope.unlock = function() + { // call with false meaning check for pin unlock(false); }; - //------------------------------------------------------------------------ // Aaron Lager hack - can't figure out why he gets a 401 after // successful login and then it works after resaving //------------------------------------------------------------------------ - function tryLoggingSecondTimeHack() { + function tryLoggingSecondTimeHack() + { var d = $q.defer(); zmAutoLogin.doLogin("<button class='button button-clear' style='line-height: normal; min-height: 0; min-width: 0;color:#fff;' ng-click='$root.cancelAuth()'><i class='ion-close-circled'></i> " + $translate.instant('kAuthenticating') + "...</button>") @@ -126,32 +147,39 @@ angular.module('zmApp.controllers').controller('zmApp.PortalLoginCtrl', ['$ionic { NVRDataModel.debug("2nd auth login worked"); NVRDataModel.getAPIversion() - .then(function(data) { + .then(function(data) + { NVRDataModel.getKeyConfigParams(1); NVRDataModel.log("2nd auth:Got API version: " + data); $rootScope.apiVersion = data; var ld = NVRDataModel.getLogin(); - if (NVRDataModel.versionCompare(data, zm.minAppVersion) == -1 && data != "0.0.0") { + if (NVRDataModel.versionCompare(data, zm.minAppVersion) == -1 && data != "0.0.0") + { - $state.go('lowversion', { + $state.go('lowversion', + { "ver": data }); return; } - if (NVRDataModel.versionCompare(data, zm.recommendedAppVersion) == -1 && data != "0.0.0") { + if (NVRDataModel.versionCompare(data, zm.recommendedAppVersion) == -1 && data != "0.0.0") + { - $state.go('importantmessage', { + $state.go('importantmessage', + { "ver": data }); return; } - if (data == "0.0.0") { + if (data == "0.0.0") + { NVRDataModel.log("2nd Auth:API getVersion succeeded but returned 0.0.0 " + JSON.stringify(data)); NVRDataModel.displayBanner('error', ['ZoneMinder authentication failed']); - $state.go("login", { + $state.go("login", + { "wizard": false }); return; @@ -159,8 +187,6 @@ angular.module('zmApp.controllers').controller('zmApp.PortalLoginCtrl', ['$ionic // coming here means continue EventServer.refresh(); - - var statetoGo = $rootScope.lastState ? $rootScope.lastState : 'montage'; //NVRDataModel.debug ("logging state transition"); NVRDataModel.debug("2nd Auth: Transitioning state to: " + @@ -169,16 +195,17 @@ angular.module('zmApp.controllers').controller('zmApp.PortalLoginCtrl', ['$ionic return; }, - function(error) { + function(error) + { NVRDataModel.debug("2nd auth API failed, going to login"); d.reject("failed 2nd auth"); return (d.promise); }); - }, - function(error) { + function(error) + { NVRDataModel.debug("2nd auth hack failed, going to login"); d.reject("failed 2nd auth"); return (d.promise); @@ -187,14 +214,16 @@ angular.module('zmApp.controllers').controller('zmApp.PortalLoginCtrl', ['$ionic return (d.promise); } - function unlock(idVerified) { + function unlock(idVerified) + { /* idVerified == true means no pin check needed == false means check PIN */ NVRDataModel.debug("unlock called with check PIN=" + idVerified); - if (idVerified || ($scope.pindata.pin == loginData.pinCode)) { + if (idVerified || ($scope.pindata.pin == loginData.pinCode)) + { NVRDataModel.debug("PIN code entered is correct, or there is no PIN set"); $rootScope.rand = Math.floor((Math.random() * 100000) + 1); zmAutoLogin.stop(); //safety @@ -211,33 +240,40 @@ angular.module('zmApp.controllers').controller('zmApp.PortalLoginCtrl', ['$ionic // $state.go("login" ,{"wizard": false}); //login was ok, so get API details NVRDataModel.getAPIversion() - .then(function(data) { + .then(function(data) + { NVRDataModel.log("Got API version: " + data); $rootScope.apiVersion = data; var ld = NVRDataModel.getLogin(); - if (NVRDataModel.versionCompare(data, zm.minAppVersion) == -1 && data != "0.0.0") { + if (NVRDataModel.versionCompare(data, zm.minAppVersion) == -1 && data != "0.0.0") + { - $state.go('lowversion', { + $state.go('lowversion', + { "ver": data }); return; } - if (NVRDataModel.versionCompare(data, zm.recommendedAppVersion) == -1 && data != "0.0.0") { + if (NVRDataModel.versionCompare(data, zm.recommendedAppVersion) == -1 && data != "0.0.0") + { // console.log (">>>>>>>>>>>>> HERE AND VERSION SAYS " +NVRDataModel.versionCompare(data, zm.recommendedAppVersion)); //console.log ("GOING TO IMPORTANT"); - $state.go('importantmessage', { + $state.go('importantmessage', + { "ver": data }); return; } - if (data == "0.0.0") { + if (data == "0.0.0") + { NVRDataModel.log("API getVersion succeeded but returned 0.0.0 " + JSON.stringify(data)); NVRDataModel.displayBanner('error', ['ZoneMinder authentication failed']); - $state.go("login", { + $state.go("login", + { "wizard": false }); return; @@ -247,31 +283,33 @@ angular.module('zmApp.controllers').controller('zmApp.PortalLoginCtrl', ['$ionic // console.log (">>>>>>>>>>>>>>>>>>>>>>>>>NEVER"); EventServer.refresh(); - - var statetoGo = $rootScope.lastState ? $rootScope.lastState : 'montage'; NVRDataModel.debug("logging state transition"); NVRDataModel.debug("Transitioning state to: " + statetoGo + " with param " + JSON.stringify($rootScope.lastStateParam)); - $state.go(statetoGo, $rootScope.lastStateParam); return; }, - function(error) { // API Error + function(error) + { // API Error NVRDataModel.log("API Error handler: going to login getAPI returned error: " + JSON.stringify(error)); //NVRDataModel.displayBanner('error', ['ZoneMinder authentication failed']); NVRDataModel.debug("Doing the Aaron Hack after 1 sec...."); - $timeout(function() { + $timeout(function() + { tryLoggingSecondTimeHack() - .then(function success(s) { + .then(function success(s) + { NVRDataModel.log("2nd time login hack worked!, nothing to do"); NVRDataModel.getTimeZone(); }, - function error(e) { - $state.go("login", { + function error(e) + { + $state.go("login", + { "wizard": false }); }); @@ -281,71 +319,89 @@ angular.module('zmApp.controllers').controller('zmApp.PortalLoginCtrl', ['$ionic }); - - if ($rootScope.tappedNotification) { - + if ($rootScope.tappedNotification) + { var ld = NVRDataModel.getLogin(); NVRDataModel.log("Came via push tap. onTapScreen=" + ld.onTapScreen); //console.log ("***** NOTIFICATION TAPPED "); $rootScope.tappedNotification = 0; - $ionicHistory.nextViewOptions({ + $ionicHistory.nextViewOptions( + { disableBack: true }); - if (ld.onTapScreen == $translate.instant('kTapMontage')) { + if (ld.onTapScreen == $translate.instant('kTapMontage')) + { NVRDataModel.debug("Going to montage"); - $state.go("montage", {}, { + $state.go("montage", + {}, + { reload: true }); return; - } else if (ld.onTapScreen == $translate.instant('kTapEvents')) { + } + else if (ld.onTapScreen == $translate.instant('kTapEvents')) + { NVRDataModel.debug("Going to events"); - $state.go("events", { + $state.go("events", + { "id": 0, "playEvent": false - }, { + }, + { reload: true }); return; - } else // we go to live + } + else // we go to live { NVRDataModel.debug("Going to live view "); - $state.go("monitors", {}, { + $state.go("monitors", + {}, + { reload: true }); return; } } - }, // coming here means auth error // so go back to login - function(error) { + function(error) + { NVRDataModel.debug("PortalLogin: error authenticating " + JSON.stringify(error)); - if (!$rootScope.userCancelledAuth) { + if (!$rootScope.userCancelledAuth) + { NVRDataModel.displayBanner('error', ['ZoneMinder authentication failed', 'Please check API settings']); - $ionicHistory.nextViewOptions({ + $ionicHistory.nextViewOptions( + { disableAnimate: true, disableBack: true }); - $state.go("login", { + $state.go("login", + { "wizard": false }); return; - } else { + } + else + { // if user cancelled auth I guess we go to login $rootScope.userCancelledAuth = false; - $state.go("login", { + $state.go("login", + { "wizard": false }); return; } }); - } else { + } + else + { $scope.pindata.status = "Invalid PIN"; // wobble the input box on error @@ -353,7 +409,8 @@ angular.module('zmApp.controllers').controller('zmApp.PortalLoginCtrl', ['$ionic element.addClass("animated shake") .one('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', - function() { + function() + { element.removeClass("animated shake"); }); } @@ -367,6 +424,4 @@ angular.module('zmApp.controllers').controller('zmApp.PortalLoginCtrl', ['$ionic var loginData; $ionicSideMenuDelegate.canDragContent(true); - - -}]);
\ No newline at end of file +}]); |
