diff options
| author | PliablePixels <pliablepixels@gmail.com> | 2015-09-14 14:36:13 -0400 |
|---|---|---|
| committer | PliablePixels <pliablepixels@gmail.com> | 2015-09-14 14:36:13 -0400 |
| commit | 8d318ef588f10d1eb3a49c663373052f228c5680 (patch) | |
| tree | 409eae1c1e2a5882f5fb2ed652702f93ce6382ee | |
| parent | 6b5c7cf6c3ee67efe3ee7842c1e12c6902f7f31e (diff) | |
Added feature to pin lock app
| -rw-r--r-- | package.json | 2 | ||||
| -rw-r--r-- | plugins/android.json | 32 | ||||
| -rw-r--r-- | plugins/fetch.json | 2 | ||||
| -rw-r--r-- | plugins/ios.json | 26 | ||||
| -rw-r--r-- | www/css/style.css | 5 | ||||
| -rw-r--r-- | www/js/DataModel.js | 96 | ||||
| -rw-r--r-- | www/js/LoginCtrl.js | 55 | ||||
| -rw-r--r-- | www/js/PortalLoginCtrl.js | 41 | ||||
| -rw-r--r-- | www/js/app.js | 37 | ||||
| -rw-r--r-- | www/templates/login.html | 8 |
10 files changed, 240 insertions, 64 deletions
diff --git a/package.json b/package.json index 343f7d64..8c71f8ef 100644 --- a/package.json +++ b/package.json @@ -28,4 +28,4 @@ "ios", "android" ] -} +}
\ No newline at end of file diff --git a/plugins/android.json b/plugins/android.json index fcf98047..14796dcc 100644 --- a/plugins/android.json +++ b/plugins/android.json @@ -13,6 +13,10 @@ "count": 1 }, { + "xml": "<feature name=\"OrientationLock\"><param name=\"android-package\" value=\"com.plugin.phonegap.OrientationLock\" /></feature>", + "count": 1 + }, + { "xml": "<preference name=\"webView\" value=\"org.crosswalk.engine.XWalkWebViewEngine\" />", "count": 1 }, @@ -25,6 +29,10 @@ "count": 1 }, { + "xml": "<feature name=\"SplashScreen\"><param name=\"android-package\" value=\"org.apache.cordova.splashscreen.SplashScreen\" /><param name=\"onload\" value=\"true\" /></feature>", + "count": 1 + }, + { "xml": "<feature name=\"Whitelist\"><param name=\"android-package\" value=\"org.apache.cordova.whitelist.WhitelistPlugin\" /><param name=\"onload\" value=\"true\" /></feature>", "count": 1 }, @@ -45,19 +53,11 @@ "count": 1 }, { - "xml": "<feature name=\"AppVersion\"><param name=\"android-package\" value=\"uk.co.whiteoctober.cordova.AppVersion\" /></feature>", - "count": 1 - }, - { "xml": "<feature name=\"Canvas2ImagePlugin\"><param name=\"android-package\" value=\"org.devgeeks.Canvas2ImagePlugin.Canvas2ImagePlugin\" /></feature>", "count": 1 }, { - "xml": "<feature name=\"OrientationLock\"><param name=\"android-package\" value=\"com.plugin.phonegap.OrientationLock\" /></feature>", - "count": 1 - }, - { - "xml": "<feature name=\"SplashScreen\"><param name=\"android-package\" value=\"org.apache.cordova.splashscreen.SplashScreen\" /><param name=\"onload\" value=\"true\" /></feature>", + "xml": "<feature name=\"AppVersion\"><param name=\"android-package\" value=\"uk.co.whiteoctober.cordova.AppVersion\" /></feature>", "count": 1 } ] @@ -79,6 +79,9 @@ "com.ionic.keyboard": { "PACKAGE_NAME": "com.pliablepixels.zmninja" }, + "com.phonegap.plugins.OrientationLock": { + "PACKAGE_NAME": "com.pliablepixels.zmninja" + }, "cordova-plugin-crosswalk-webview": { "PACKAGE_NAME": "com.pliablepixels.zmninja" }, @@ -88,6 +91,9 @@ "cordova-plugin-inappbrowser": { "PACKAGE_NAME": "com.pliablepixels.zmninja" }, + "cordova-plugin-splashscreen": { + "PACKAGE_NAME": "com.pliablepixels.zmninja" + }, "cordova-plugin-whitelist": { "PACKAGE_NAME": "com.pliablepixels.zmninja" }, @@ -106,16 +112,10 @@ "org.apache.cordova.statusbar": { "PACKAGE_NAME": "com.pliablepixels.zmninja" }, - "uk.co.whiteoctober.cordova.appversion": { - "PACKAGE_NAME": "com.pliablepixels.zmninja" - }, "org.devgeeks.Canvas2ImagePlugin": { "PACKAGE_NAME": "com.pliablepixels.zmninja" }, - "com.phonegap.plugins.OrientationLock": { - "PACKAGE_NAME": "com.pliablepixels.zmninja" - }, - "cordova-plugin-splashscreen": { + "uk.co.whiteoctober.cordova.appversion": { "PACKAGE_NAME": "com.pliablepixels.zmninja" } }, diff --git a/plugins/fetch.json b/plugins/fetch.json index 4701fbf0..c3ce7777 100644 --- a/plugins/fetch.json +++ b/plugins/fetch.json @@ -121,4 +121,4 @@ "is_top_level": true, "variables": {} } -} +}
\ No newline at end of file diff --git a/plugins/ios.json b/plugins/ios.json index 980ff794..b390a6f9 100644 --- a/plugins/ios.json +++ b/plugins/ios.json @@ -21,6 +21,10 @@ "count": 1 }, { + "xml": "<feature name=\"SplashScreen\"><param name=\"ios-package\" value=\"CDVSplashScreen\" /><param name=\"onload\" value=\"true\" /></feature>", + "count": 1 + }, + { "xml": "<feature name=\"EmailComposer\"><param name=\"ios-package\" value=\"APPEmailComposer\" /></feature>", "count": 1 }, @@ -49,15 +53,11 @@ "count": 1 }, { - "xml": "<feature name=\"AppVersion\"><param name=\"ios-package\" value=\"AppVersion\" /></feature>", - "count": 1 - }, - { "xml": "<feature name=\"Canvas2ImagePlugin\"><param name=\"ios-package\" value=\"Canvas2ImagePlugin\" /><param name=\"onload\" value=\"true\" /></feature>", "count": 1 }, { - "xml": "<feature name=\"SplashScreen\"><param name=\"ios-package\" value=\"CDVSplashScreen\" /><param name=\"onload\" value=\"true\" /></feature>", + "xml": "<feature name=\"AppVersion\"><param name=\"ios-package\" value=\"AppVersion\" /></feature>", "count": 1 } ] @@ -80,7 +80,7 @@ "CoreGraphics.framework": [ { "xml": false, - "count": 1 + "count": 2 } ], "MessageUI.framework": [ @@ -97,6 +97,9 @@ "com.ionic.keyboard": { "PACKAGE_NAME": "com.pliablepixels.zmninja" }, + "com.phonegap.plugins.OrientationLock": { + "PACKAGE_NAME": "com.pliablepixels.zmninja" + }, "cordova-plugin-crosswalk-webview": { "PACKAGE_NAME": "com.pliablepixels.zmninja" }, @@ -106,6 +109,9 @@ "cordova-plugin-inappbrowser": { "PACKAGE_NAME": "com.pliablepixels.zmninja" }, + "cordova-plugin-splashscreen": { + "PACKAGE_NAME": "com.pliablepixels.zmninja" + }, "cordova-plugin-whitelist": { "PACKAGE_NAME": "com.pliablepixels.zmninja" }, @@ -124,16 +130,10 @@ "org.apache.cordova.statusbar": { "PACKAGE_NAME": "com.pliablepixels.zmninja" }, - "uk.co.whiteoctober.cordova.appversion": { - "PACKAGE_NAME": "com.pliablepixels.zmninja" - }, "org.devgeeks.Canvas2ImagePlugin": { "PACKAGE_NAME": "com.pliablepixels.zmninja" }, - "com.phonegap.plugins.OrientationLock": { - "PACKAGE_NAME": "com.pliablepixels.zmninja" - }, - "cordova-plugin-splashscreen": { + "uk.co.whiteoctober.cordova.appversion": { "PACKAGE_NAME": "com.pliablepixels.zmninja" } }, diff --git a/www/css/style.css b/www/css/style.css index 14453453..3255c156 100644 --- a/www/css/style.css +++ b/www/css/style.css @@ -394,6 +394,11 @@ input[type=range]::-webkit-slider-thumb { } +/* this is for input = password and dialog = text */ +input[type=number] { + -webkit-text-security: disc; +} + /*.mySliderClass.jslider.sliderCSS div.jslider-pointer {top:-10px;left:15px;width:60px;height:60px;margin-left:-5px;background-color:silver;background-color:#615959;border-radius:50% }*/ 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); diff --git a/www/templates/login.html b/www/templates/login.html index 2b4e2b77..9acde8a8 100644 --- a/www/templates/login.html +++ b/www/templates/login.html @@ -57,6 +57,12 @@ </label> <label> + <ion-toggle ng-model="loginData.usePin" ng-change="pinPrompt();" + ng-checked="{{loginData.usePin}}" + toggle-class="toggle-calm">Password protect</ion-toggle> + </label> + + <label> <ion-toggle ng-model="loginData.useSSL" ng-checked="{{loginData.useSSL}}" toggle-class="toggle-calm">Use SSL</ion-toggle> @@ -71,7 +77,7 @@ </label> </div> <button class="button button-block button-balanced icon ion-locked" - ng-click="save()"> Login + ng-click="save()"> Save </button> </ion-content> |
