summaryrefslogtreecommitdiff
path: root/www/js
diff options
context:
space:
mode:
Diffstat (limited to 'www/js')
-rw-r--r--www/js/DataModel.js96
-rw-r--r--www/js/LoginCtrl.js55
-rw-r--r--www/js/PortalLoginCtrl.js41
-rw-r--r--www/js/app.js37
4 files changed, 197 insertions, 32 deletions
diff --git a/www/js/DataModel.js b/www/js/DataModel.js
index ae4bee12..e42c96a7 100644
--- a/www/js/DataModel.js
+++ b/www/js/DataModel.js
@@ -1,5 +1,6 @@
/* jshint -W041 */
+
/* jslint browser: true*/
/* global cordova,StatusBar,angular,console */
@@ -7,7 +8,12 @@
// that many other controllers use
// It's grown over time. I guess I may have to split this into multiple services in the future
-angular.module('zmApp.controllers').service('ZMDataModel', ['$http', '$q', '$ionicLoading', '$ionicBackdrop', '$fileLogger', 'zm','$rootScope','$ionicContentBanner', '$timeout',function ($http, $q, $ionicLoading, $ionicBackdrop,$fileLogger,zm, $rootScope,$ionicContentBanner, $timeout) {
+angular.module('zmApp.controllers').service('ZMDataModel',
+['$http', '$q', '$ionicLoading', '$ionicBackdrop', '$fileLogger', 'zm','$rootScope','$ionicContentBanner', '$timeout','$cordovaPinDialog', '$ionicPopup',
+ function
+ ($http, $q, $ionicLoading, $ionicBackdrop,$fileLogger,
+ zm, $rootScope,$ionicContentBanner, $timeout, $cordovaPinDialog,
+ $ionicPopup) {
var zmAppVersion="unknown";
var monitorsLoaded = 0;
@@ -28,6 +34,8 @@ angular.module('zmApp.controllers').service('ZMDataModel', ['$http', '$q', '$ion
'isUseAuth':true, // true if user wants ZM auth
'refreshSec':"1", // timer value for frame change in sec
'enableDebug':false, // if enabled with log messages with "debug"
+ 'usePin':false,
+ 'pinCode':'',
};
var configParams = {
'ZM_EVENT_IMAGE_DIGITS':'-1'
@@ -202,6 +210,18 @@ angular.module('zmApp.controllers').service('ZMDataModel', ['$http', '$q', '$ion
}
+ if (window.localStorage.getItem("usePin") != undefined) {
+ var pinValue = window.localStorage.getItem("usePin");
+ loginData.usePin = (pinValue == "1") ? true:false;
+ console.log("usePin " + loginData.usePin);
+
+ }
+
+ if (window.localStorage.getItem("pinCode") != undefined) {
+ loginData.pinCode =
+ window.localStorage.getItem("pinCode");
+
+ }
if (window.localStorage.getItem("keepAwake") != undefined) {
var awakevalue = window.localStorage.getItem("keepAwake");
@@ -292,6 +312,10 @@ angular.module('zmApp.controllers').service('ZMDataModel', ['$http', '$q', '$ion
window.localStorage.setItem("apiurl", loginData.apiurl);
window.localStorage.setItem("streamingurl", loginData.streamingurl);
window.localStorage.setItem("useSSL", loginData.useSSL?"1":"0");
+ window.localStorage.setItem("usePin", loginData.usePin?"1":"0");
+ window.localStorage.setItem("pinCode", loginData.pinCode);
+
+
window.localStorage.setItem("enableDebug", loginData.enableDebug?"1":"0");
window.localStorage.setItem("keepAwake", loginData.keepAwake?"1":"0");
window.localStorage.setItem("maxMontage", loginData.maxMontage);
@@ -358,7 +382,77 @@ angular.module('zmApp.controllers').service('ZMDataModel', ['$http', '$q', '$ion
// Grabs the computed auth key for streaming
// FIXME: Currently a hack - does a screen parse - convert to API based support
//-----------------------------------------------------------------------------
+ validatePin: function()
+ {
+
+ var d=$q.defer();
+ if (loginData.usePin)
+ {
+ zmDebug("Validating PIN...");
+ var pinMatch = false;
+
+ //<input type="number" pattern="[0-9]*">
+ $rootScope.pindata={};
+ var pinPrompt = $ionicPopup.show({
+ template: '<input type="number" pattern="[0-9]*" ng-model="$root.pindata.pin">',
+ title: 'PIN validation',
+ subtitle: 'Please confirm your PIN',
+ scope: $rootScope,
+ buttons: [
+ {
+ text: 'Ok',
+ type:'button-positive',
+ onTap: function(e)
+ {
+ if ($rootScope.pindata.pin != loginData.pinCode)
+ {
+ displayBanner("error",["Invalid PIN. Please try again"]);
+ zmLog("Invalid PIN entered ");
+ e.preventDefault();
+ $rootScope.pindata.pin="";
+ }
+ else
+ {
+ zmLog("PIN was correct");
+ d.resolve(true);
+ }
+
+ }
+ },
+ ]});
+ return (d.promise);
+ /*$cordovaPinDialog.prompt ('Enter PIN', 'PIN Confirm', ["OK"])
+ .then( function (result)
+ {
+ if (result.input1 != loginData.pinCode)
+ {
+ displayBanner("error",["Invalid PIN. Please try again"]);
+ zmLog("Invalid PIN entered, looping...");
+ d.resolve(false);
+ }
+ else
+ {
+ pinMatch = true;
+ zmLog("Valid PIN entered");
+ d.resolve(true);
+ }
+ },
+ function (error)
+ {
+ zmLog("PIN error handler. Should not come here");
+ d.resolve(false);
+ });*/
+
+
+
+ }
+ else
+ {
+ zmDebug("No PIN set, skipping");
+ }
+ },
+
getAuthKey: function ()
{
var d=$q.defer();
diff --git a/www/js/LoginCtrl.js b/www/js/LoginCtrl.js
index b5c409b3..aa61325c 100644
--- a/www/js/LoginCtrl.js
+++ b/www/js/LoginCtrl.js
@@ -2,7 +2,7 @@
/* jslint browser: true*/
/* global cordova,StatusBar,angular,console */
-angular.module('zmApp.controllers').controller('zmApp.LoginCtrl', ['$scope', '$rootScope','zm', '$ionicModal', 'ZMDataModel', '$ionicSideMenuDelegate', '$ionicPopup', '$http', '$q', '$ionicLoading', 'zmAutoLogin', function ($scope, $rootScope,zm, $ionicModal, ZMDataModel, $ionicSideMenuDelegate, $ionicPopup, $http, $q, $ionicLoading, zmAutoLogin) {
+angular.module('zmApp.controllers').controller('zmApp.LoginCtrl', ['$scope', '$rootScope','zm', '$ionicModal', 'ZMDataModel', '$ionicSideMenuDelegate', '$ionicPopup', '$http', '$q', '$ionicLoading', 'zmAutoLogin', '$cordovaPinDialog', function ($scope, $rootScope,zm, $ionicModal, ZMDataModel, $ionicSideMenuDelegate, $ionicPopup, $http, $q, $ionicLoading, zmAutoLogin, $cordovaPinDialog) {
$scope.openMenu = function () {
$ionicSideMenuDelegate.toggleLeft();
};
@@ -13,6 +13,7 @@ angular.module('zmApp.controllers').controller('zmApp.LoginCtrl', ['$scope', '$r
$scope.auth.isUseAuth = ($scope.loginData.isUseAuth == '1') ? true:false;
+
//-------------------------------------------------------------------------
@@ -27,6 +28,58 @@ angular.module('zmApp.controllers').controller('zmApp.LoginCtrl', ['$scope', '$r
ZMDataModel.setAwake(false);
});
+
+ $scope.pinPrompt = function(evt)
+ {
+ ZMDataModel.zmLog ("Password prompt");
+ if ($scope.loginData.usePin)
+ {
+ $scope.loginData.pinCode="";
+ $cordovaPinDialog.prompt('Enter PIN', 'PIN Protect').then (
+ function(result1) {
+
+ // console.log (JSON.stringify(result1));
+ if (result1.input1 && result1.buttonIndex==1)
+ {
+ $cordovaPinDialog.prompt('Reconfirm PIN', 'PIN Protect')
+ .then(function(result2)
+ {
+ if (result1.input1 == result2.input1)
+ {
+ ZMDataModel.zmLog("Pin code match");
+ $scope.loginData.pinCode=result1.input1;
+ }
+ else
+ {
+ ZMDataModel.zmLog("Pin code mismatch");
+ $scope.loginData.usePin = false;
+ ZMDataModel.displayBanner ('error', ['Pin code mismatch']);
+ }
+ },
+ function(error)
+ {
+ console.log ("Error inside");
+ $scope.loginData.usePin = false;
+ });
+ }
+ else
+ {
+ $scope.loginData.usePin = false;
+ }
+ },
+ function (error)
+ {
+ console.log ("Error outside");
+ $scope.loginData.usePin = false;
+ });
+
+
+
+ }
+ else {
+ ZMDataModel.zmDebug("Password disabled");
+ }
+ };
//-------------------------------------------------------------------------------
// Makes input easier
diff --git a/www/js/PortalLoginCtrl.js b/www/js/PortalLoginCtrl.js
index 5504e225..97da4e2c 100644
--- a/www/js/PortalLoginCtrl.js
+++ b/www/js/PortalLoginCtrl.js
@@ -15,26 +15,29 @@ angular.module('zmApp.controllers').controller('zmApp.PortalLoginCtrl', ['$ionic
var loginData = ZMDataModel.getLogin();
if (ZMDataModel.isLoggedIn()) {
- ZMDataModel.zmLog ("User credentials are provided");
- // console.log("VALID CREDENTIALS. Grabbing Monitors");
- ZMDataModel.zmDebug("PortalLogin: Authenticating");
- zmAutoLogin.doLogin("authenticating...")
- .then (function(data) // success
- {
- ZMDataModel.zmDebug("PortalLogin: auth success");
- ZMDataModel.getKeyConfigParams(1);
- $state.go('montage');
- },
- // coming here means auth error
- // so go back to login
- function (error)
- {
- ZMDataModel.zmDebug("PortalLogin: error authenticating " + JSON.stringify(error));
- $state.go('login');
- }
-
+ ZMDataModel.zmLog ("User credentials are provided");
+ ZMDataModel.validatePin()
+ .then( function (data) {
+
- );
+ // console.log("VALID CREDENTIALS. Grabbing Monitors");
+ ZMDataModel.zmDebug("PortalLogin: Authenticating");
+ zmAutoLogin.doLogin("authenticating...")
+ .then (function(data) // success
+ {
+ ZMDataModel.zmDebug("PortalLogin: auth success");
+ ZMDataModel.getKeyConfigParams(1);
+ $state.go('montage');
+ },
+ // coming here means auth error
+ // so go back to login
+ function (error)
+ {
+ ZMDataModel.zmDebug("PortalLogin: error authenticating " +
+ JSON.stringify(error));
+ $state.go('login');
+ });
+ });
}
else
{
diff --git a/www/js/app.js b/www/js/app.js
index b8cc0e8a..214e4f2d 100644
--- a/www/js/app.js
+++ b/www/js/app.js
@@ -1,6 +1,6 @@
/* jshint -W041 */
/* jslint browser: true*/
-/* global cordova,StatusBar,angular,console */
+/* global cordova,StatusBar,angular,console,alert */
var appVersion = "0.0.0";
@@ -285,6 +285,8 @@ angular.module('zmApp', [
//console.log("**** ZM LOGIN SUCCESS INTERCEPT");
});
+
+
//------------------------------------------------------------------
// doLogin() is the function that tries to login to ZM
@@ -483,7 +485,7 @@ angular.module('zmApp', [
$rootScope.toString = "";
$rootScope.loggedIntoZm = 0;
- console.log ("HERE");
+ //console.log ("HERE");
ZMDataModel.init();
// for making sure we canuse $state.go with ng-click
// needed for views that use popovers
@@ -546,7 +548,7 @@ angular.module('zmApp', [
$ionicPlatform.ready(function () {
-
+ console.log("**** DEVICE READY ***");
// generates and error in desktops but works fine
ZMDataModel.zmLog("Device is ready");
console.log("**** DEVICE READY ***");
@@ -563,6 +565,8 @@ angular.module('zmApp', [
});
+
+
//fileLogger is an excellent cross platform library
// that allows you to manage log files without worrying about
@@ -610,14 +614,25 @@ angular.module('zmApp', [
// so as a global hack I'm just reloading the current state if you switch
// from foreground to background and back
document.addEventListener("resume", function () {
- console.log("****The application is resuming from the background");
- ZMDataModel.zmLog("App is resuming from background");
- $rootScope.rand = Math.floor((Math.random() * 100000) + 1);
- //$scope.rand = Math.floor((Math.random() * 100000) + 1);
- console.log("** generated Random of " + $rootScope.rand);
- zmAutoLogin.stop(); //safety
- zmAutoLogin.start();
- zmAutoLogin.doLogin("authenticating ...");
+ ZMDataModel.zmLog("App is resuming from background");
+
+ $ionicSideMenuDelegate.toggleLeft(false);
+ ZMDataModel.validatePin()
+ .then ( function(data)
+ {
+ $rootScope.rand = Math.floor((Math.random() * 100000) + 1);
+ //$scope.rand = Math.floor((Math.random() * 100000) + 1);
+ console.log("** generated Random of " + $rootScope.rand);
+ zmAutoLogin.stop(); //safety
+ zmAutoLogin.start();
+ zmAutoLogin.doLogin("authenticating ...");
+
+ });
+
+
+
+
+
}, false);