summaryrefslogtreecommitdiff
path: root/www/js/LoginCtrl.js
diff options
context:
space:
mode:
authorArjun Roychowdhury <pliablepixels@gmail.com>2015-09-29 14:48:08 -0400
committerArjun Roychowdhury <pliablepixels@gmail.com>2015-09-29 14:48:08 -0400
commitbd2e8b0aec872b74fe0ec52feec14d3bf3900986 (patch)
treea6878b7a4f322b6f26b59afa2cfe7c878a9f3ab7 /www/js/LoginCtrl.js
parent054bd7beffd8cc304f48f1b1369c118a28bbbf73 (diff)
code formatting
Diffstat (limited to 'www/js/LoginCtrl.js')
-rw-r--r--www/js/LoginCtrl.js272
1 files changed, 131 insertions, 141 deletions
diff --git a/www/js/LoginCtrl.js b/www/js/LoginCtrl.js
index f37f2b56..2322391f 100644
--- a/www/js/LoginCtrl.js
+++ b/www/js/LoginCtrl.js
@@ -2,21 +2,23 @@
/* 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', '$cordovaPinDialog', function ($scope, $rootScope,zm, $ionicModal, ZMDataModel, $ionicSideMenuDelegate, $ionicPopup, $http, $q, $ionicLoading, zmAutoLogin, $cordovaPinDialog) {
+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();
};
$scope.loginData = ZMDataModel.getLogin();
-
- $scope.auth={isUseAuth:""};
- $scope.auth.isUseAuth = ($scope.loginData.isUseAuth == '1') ? true:false;
-
-
+ $scope.auth = {
+ isUseAuth: ""
+ };
+ $scope.auth.isUseAuth = ($scope.loginData.isUseAuth == '1') ? true : false;
+
+
- //-------------------------------------------------------------------------
+
+ //-------------------------------------------------------------------------
// Lets make sure we set screen dim properly as we enter
// The problem is we enter other states before we leave previous states
// from a callback perspective in ionic, so we really can't predictably
@@ -28,90 +30,81 @@ 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");
- }
+
+ //--------------------------------------------------------------------------
+ // When PIN is enabled, this is called to specify a PIN
+ // FIXME: Get rid of cordovaPinDialog. It's really not needed
+ //--------------------------------------------------------------------------
+ $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
//-------------------------------------------------------------------------------
- $scope.portalKeypress = function(evt)
- {
+ $scope.portalKeypress = function (evt) {
- // if ($scope.loginData.streamingurl.indexOf($scope.loginData.url) !=0)
- $scope.loginData.streamingurl = $scope.loginData.url;
+ // if ($scope.loginData.streamingurl.indexOf($scope.loginData.url) !=0)
+ $scope.loginData.streamingurl = $scope.loginData.url;
- // Changed Sep 16 2015: Seems cgi-bin will now have /zm/cgi-bin by
- // default in packages instead of /cgi-bin
- //if ($scope.loginData.streamingurl.slice(-3).toLowerCase() == '/zm') {
- //$scope.loginData.streamingurl = $scope.loginData.streamingurl.slice(0, -3);
+ // Changed Sep 16 2015: Seems cgi-bin will now have /zm/cgi-bin by
+ // default in packages instead of /cgi-bin
+ //if ($scope.loginData.streamingurl.slice(-3).toLowerCase() == '/zm') {
+ //$scope.loginData.streamingurl = $scope.loginData.streamingurl.slice(0, -3);
//}
- // if ($scope.loginData.apiurl.indexOf($scope.loginData.url) !=0)
- $scope.loginData.apiurl = $scope.loginData.url+"/api";
+ // if ($scope.loginData.apiurl.indexOf($scope.loginData.url) !=0)
+ $scope.loginData.apiurl = $scope.loginData.url + "/api";
};
-//-------------------------------------------------------------------------------
-// Adds http to url if not present
-// http://stackoverflow.com/questions/11300906/check-if-a-string-starts-with-http-using-javascript
-//-------------------------------------------------------------------------------
-function addhttp(url) {
-
- if ((!/^(f|ht)tps?:\/\//i.test(url)) && (url !="") ) {
- url = "http://" + url;
- }
- return url;
-}
+ //-------------------------------------------------------------------------------
+ // Adds http to url if not present
+ // http://stackoverflow.com/questions/11300906/check-if-a-string-starts-with-http-using-javascript
+ //-------------------------------------------------------------------------------
+ function addhttp(url) {
+
+ if ((!/^(f|ht)tps?:\/\//i.test(url)) && (url != "")) {
+ url = "http://" + url;
+ }
+ return url;
+ }
//-----------------------------------------------------------------------------
// Perform the login action when the user submits the login form
@@ -137,8 +130,8 @@ function addhttp(url) {
$scope.loginData.apiurl = $scope.loginData.apiurl.trim();
$scope.loginData.username = $scope.loginData.username.trim();
$scope.loginData.streamingurl = $scope.loginData.streamingurl.trim();
-
- $scope.loginData.isUseAuth = ($scope.auth.isUseAuth) ? "1": "0";
+
+ $scope.loginData.isUseAuth = ($scope.auth.isUseAuth) ? "1" : "0";
if ($scope.loginData.url.slice(-1) == '/') {
$scope.loginData.url = $scope.loginData.url.slice(0, -1);
@@ -164,87 +157,84 @@ function addhttp(url) {
// check for protocol and if not put it in
$scope.loginData.url = addhttp($scope.loginData.url);
- $scope.loginData.apiurl = addhttp($scope.loginData.apiurl);
- $scope.loginData.streamingurl = addhttp($scope.loginData.streamingurl);
+ $scope.loginData.apiurl = addhttp($scope.loginData.apiurl);
+ $scope.loginData.streamingurl = addhttp($scope.loginData.streamingurl);
- if ($scope.loginData.useSSL)
- {
+ if ($scope.loginData.useSSL) {
// replace all http with https
- $scope.loginData.url = $scope.loginData.url.replace("http:","https:");
- $scope.loginData.apiurl = $scope.loginData.apiurl.replace("http:","https:");
- $scope.loginData.streamingurl = $scope.loginData.streamingurl.replace("http:","https:");
+ $scope.loginData.url = $scope.loginData.url.replace("http:", "https:");
+ $scope.loginData.apiurl = $scope.loginData.apiurl.replace("http:", "https:");
+ $scope.loginData.streamingurl = $scope.loginData.streamingurl.replace("http:", "https:");
- }
- else
- {
+ } else {
// replace all https with http
- $scope.loginData.url = $scope.loginData.url.replace("https:","http:");
- $scope.loginData.apiurl = $scope.loginData.apiurl.replace("https:","http:");
- $scope.loginData.streamingurl = $scope.loginData.streamingurl.replace("https:","http:");
+ $scope.loginData.url = $scope.loginData.url.replace("https:", "http:");
+ $scope.loginData.apiurl = $scope.loginData.apiurl.replace("https:", "http:");
+ $scope.loginData.streamingurl = $scope.loginData.streamingurl.replace("https:", "http:");
}
var apiurl = $scope.loginData.apiurl + '/host/getVersion.json';
var portalurl = $scope.loginData.url + '/index.php';
-
-
-
+
+
+
// Check if isUseAuth is set make sure u/p have a dummy value
- if ($scope.isUseAuth)
- {
- if (!$scope.loginData.username) $scope.loginData.username="x";
- if (!$scope.loginData.password) $scope.loginData.password="x";
+ if ($scope.isUseAuth) {
+ if (!$scope.loginData.username) $scope.loginData.username = "x";
+ if (!$scope.loginData.password) $scope.loginData.password = "x";
ZMDataModel.zmLog("Authentication is disabled, setting dummy user & pass");
}
-
+
ZMDataModel.setLogin($scope.loginData);
-
+
// now grab and report PATH_ZMS
ZMDataModel.getPathZms()
- .then (function(data) {
- var ld = ZMDataModel.getLogin();
- ZMDataModel.zmLog ("PATH_ZMS:"+data+" ,Path ZmNinja will use:"+ld.streamingurl+"/cgi-bin/nph-zms");
- ZMDataModel.zmLog ("If live streams are not working, make sure you check these values");
-
-
-
- });
-
-
+ .then(function (data) {
+ var ld = ZMDataModel.getLogin();
+ ZMDataModel.zmLog("PATH_ZMS:" + data + " ,Path ZmNinja will use:" + ld.streamingurl + "/cgi-bin/nph-zms");
+ ZMDataModel.zmLog("If live streams are not working, make sure you check these values");
+
+
+
+ });
+
+
zmAutoLogin.doLogin("authenticating...")
- // 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)
- {
-
+ // 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);
+
+ ZMDataModel.zmLog("Validating APIs at " + apiurl);
$http.get(apiurl)
- .success (function (data) {
-
- $ionicPopup.alert({
- title: 'Login validated',
- template: 'Please explore the menu and enjoy zmNinja!'
- }).then(function(res) { $ionicSideMenuDelegate.toggleLeft();});
-
- })
- .error (function (error) {
- ZMDataModel.displayBanner ('error',['ZoneMinder API check failed', 'Please check API settings']);
- ZMDataModel.zmLog ("API login error " + JSON.stringify(error));
- $ionicPopup.alert({
- title: 'Login validated but API failed',
- template: 'Please check your API settings'
+ .success(function (data) {
+
+ $ionicPopup.alert({
+ title: 'Login validated',
+ template: 'Please explore the menu and enjoy zmNinja!'
+ }).then(function (res) {
+ $ionicSideMenuDelegate.toggleLeft();
});
- });
-
-
+
+ })
+ .error(function (error) {
+ ZMDataModel.displayBanner('error', ['ZoneMinder API check failed', 'Please check API settings']);
+ ZMDataModel.zmLog("API login error " + JSON.stringify(error));
+ $ionicPopup.alert({
+ title: 'Login validated but API failed',
+ template: 'Please check your API settings'
+ });
+ });
+
+
});
};
-}]);
+}]); \ No newline at end of file