diff options
| -rw-r--r-- | www/js/PortalLoginCtrl.js | 146 |
1 files changed, 85 insertions, 61 deletions
diff --git a/www/js/PortalLoginCtrl.js b/www/js/PortalLoginCtrl.js index cb498844..97ff214b 100644 --- a/www/js/PortalLoginCtrl.js +++ b/www/js/PortalLoginCtrl.js @@ -5,67 +5,14 @@ /* global vis,cordova,StatusBar,angular,console,moment */ angular.module('zmApp.controllers').controller('zmApp.PortalLoginCtrl', ['$ionicPlatform', '$scope', 'zm', 'ZMDataModel', '$ionicSideMenuDelegate', '$rootScope', '$http', '$q', '$state', '$ionicLoading', '$ionicPopover', '$ionicScrollDelegate', '$ionicModal', '$timeout', 'zmAutoLogin', '$ionicHistory', '$cordovaTouchID', function ($ionicPlatform, $scope, zm, ZMDataModel, $ionicSideMenuDelegate, $rootScope, $http, $q, $state, $ionicLoading, $ionicPopover, $ionicScrollDelegate, $ionicModal, $timeout, zmAutoLogin, $ionicHistory, $cordovaTouchID) { - - //------------------------------------------------------------------------------- - // remove status is pin is empty - //------------------------------------------------------------------------------- - - $scope.pinChange = function () { - if ($scope.pindata.pin == null) { - $scope.pindata.status = ""; - } - }; - - //------------------------------------------------------------------------------- - // unlock app if PIN is correct - //------------------------------------------------------------------------------- - $scope.unlock = function () { - unlock(); - }; - - function unlock() - { - ZMDataModel.zmDebug("Trying to unlock PIN"); - if ($scope.pindata.pin == loginData.pinCode) { - ZMDataModel.zmDebug("PIN code entered is correct"); - $rootScope.rand = Math.floor((Math.random() * 100000) + 1); - zmAutoLogin.stop(); //safety - zmAutoLogin.start(); - zmAutoLogin.doLogin("authenticating...") - .then(function (data) // success - { - ZMDataModel.zmDebug("PortalLogin: auth success"); - ZMDataModel.getKeyConfigParams(1); - ZMDataModel.zmDebug("Transitioning state to: " + $rootScope.lastState? $rootScope.lastState:'montage'); - $state.go($rootScope.lastState? $rootScope.lastState:'montage', $rootScope.lastStateParam); - }, - // coming here means auth error - // so go back to login - function (error) { - ZMDataModel.zmDebug("PortalLogin: error authenticating " + - JSON.stringify(error)); - $state.go('login'); - }); - } else { - $scope.pindata.status = "Invalid PIN"; - - // wobble the input box on error - var element = angular.element(document.getElementById("pin-box")); - - element.addClass("animated shake") - .one('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', - function () { - element.removeClass("animated shake"); - }); - } - } - - //------------------------------------------------------------------------------- - // Controller Main - //------------------------------------------------------------------------------- - - $ionicHistory.nextViewOptions({ + $scope.$on('$ionicView.enter', + function(){ + + ZMDataModel.zmDebug("Inside Portal login Enter handler"); + + + $ionicHistory.nextViewOptions({ disableBack: true }); @@ -75,7 +22,7 @@ angular.module('zmApp.controllers').controller('zmApp.PortalLoginCtrl', ['$ionic ZMDataModel.zmDebug("Sliding menu close"); } - var loginData = ZMDataModel.getLogin(); + $scope.pinPrompt = false; // if true, then PIN is displayed else skip if (ZMDataModel.isLoggedIn()) { @@ -107,6 +54,13 @@ angular.module('zmApp.controllers').controller('zmApp.PortalLoginCtrl', ['$ionic else // no PIN Code so skip { + // don't get stuck in this state + // will happen if you switch to background in portal state + if ($rootScope.lastState == "zm-portal-login") + { + ZMDataModel.zmDebug("Last state was portal-login, so forcing montage"); + $rootScope.lastState = "montage"; + } ZMDataModel.zmDebug("PIN code not set"); $rootScope.rand = Math.floor((Math.random() * 100000) + 1); zmAutoLogin.stop(); //safety @@ -134,6 +88,76 @@ angular.module('zmApp.controllers').controller('zmApp.PortalLoginCtrl', ['$ionic $state.go('login'); } + + }); + + //------------------------------------------------------------------------------- + // remove status is pin is empty + //------------------------------------------------------------------------------- + + $scope.pinChange = function () { + if ($scope.pindata.pin == null) { + $scope.pindata.status = ""; + } + }; + + //------------------------------------------------------------------------------- + // unlock app if PIN is correct + //------------------------------------------------------------------------------- + $scope.unlock = function () { + unlock(); + }; + + function unlock() + { + ZMDataModel.zmDebug("Trying to unlock PIN"); + if ($scope.pindata.pin == loginData.pinCode) { + ZMDataModel.zmDebug("PIN code entered is correct"); + $rootScope.rand = Math.floor((Math.random() * 100000) + 1); + zmAutoLogin.stop(); //safety + zmAutoLogin.start(); + zmAutoLogin.doLogin("authenticating...") + .then(function (data) // success + { + // don't get stuck in this state + // will happen if you switch to background in portal state + if ($rootScope.lastState == "zm-portal-login") { + ZMDataModel.zmDebug("Last state was portal-login, so forcing montage"); + $rootScope.lastState = "montage"; + } + ZMDataModel.zmDebug("PortalLogin: auth success"); + ZMDataModel.getKeyConfigParams(1); + ZMDataModel.zmDebug("Transitioning state to: " + $rootScope.lastState? $rootScope.lastState:'montage'); + $state.go($rootScope.lastState? $rootScope.lastState:'montage', $rootScope.lastStateParam); + }, + // coming here means auth error + // so go back to login + function (error) { + ZMDataModel.zmDebug("PortalLogin: error authenticating " + + JSON.stringify(error)); + $state.go('login'); + }); + } else { + $scope.pindata.status = "Invalid PIN"; + + // wobble the input box on error + var element = angular.element(document.getElementById("pin-box")); + + element.addClass("animated shake") + .one('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', + function () { + element.removeClass("animated shake"); + }); + } + } + + //------------------------------------------------------------------------------- + // Controller Main + //------------------------------------------------------------------------------- + console.log ("************* ENTERING PORTAL MAIN "); + var loginData = ZMDataModel.getLogin(); + + }]);
\ No newline at end of file |
