Skip to content

Commit

Permalink
#234 - mostly working, needs more testing.
Browse files Browse the repository at this point in the history
  • Loading branch information
pliablepixels committed May 1, 2016
1 parent 8ad8a75 commit 0354373
Show file tree
Hide file tree
Showing 10 changed files with 158 additions and 65 deletions.
2 changes: 1 addition & 1 deletion www/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ <h1 class="title">Options</h1>
System Status
</ion-item>

<ion-item nav-clear menu-close href="#/login">
<ion-item nav-clear menu-close href="#/login/false">
<span style="float:right;margin-top:-18px;background-color:#444444;color:#fff;font-size:11px;opacity:0.7;width:90px;border-radius: 0px 0px 5px 5px;:text-overflow:ellipsis;overflow:hidden;white-space:nowrap;display:inline-block;text-align:center;">&nbsp;{{$root.getProfileName();}}&nbsp;</span>


Expand Down
2 changes: 1 addition & 1 deletion www/js/EventCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ angular.module('zmApp.controllers')
$ionicHistory.nextViewOptions({
disableBack: true
});
$state.go("login");
$state.go("login" ,{"wizard": false});
return;
}

Expand Down
2 changes: 1 addition & 1 deletion www/js/FirstUseCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ $scope.openMenu = function () {
disableAnimate: false,
disableBack: true
});
$state.go ("login");
$state.go("login" ,{"wizard": false});
};


Expand Down
26 changes: 24 additions & 2 deletions www/js/LoginCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/* jslint browser: true*/
/* global cordova,StatusBar,angular,console,alert,URI */

angular.module('zmApp.controllers').controller('zmApp.LoginCtrl', ['$scope', '$rootScope', 'zm', '$ionicModal', 'ZMDataModel', '$ionicSideMenuDelegate', '$ionicPopup', '$http', '$q', '$ionicLoading', 'zmAutoLogin', '$cordovaPinDialog', 'EventServer', '$ionicHistory', '$state', '$ionicActionSheet', 'SecuredPopups', '$localstorage', function ($scope, $rootScope, zm, $ionicModal, ZMDataModel, $ionicSideMenuDelegate, $ionicPopup, $http, $q, $ionicLoading, zmAutoLogin, $cordovaPinDialog, EventServer, $ionicHistory, $state, $ionicActionSheet, SecuredPopups, $localstorage) {
angular.module('zmApp.controllers').controller('zmApp.LoginCtrl', ['$scope', '$rootScope', 'zm', '$ionicModal', 'ZMDataModel', '$ionicSideMenuDelegate', '$ionicPopup', '$http', '$q', '$ionicLoading', 'zmAutoLogin', '$cordovaPinDialog', 'EventServer', '$ionicHistory', '$state', '$ionicActionSheet', 'SecuredPopups', '$localstorage', '$stateParams', function ($scope, $rootScope, zm, $ionicModal, ZMDataModel, $ionicSideMenuDelegate, $ionicPopup, $http, $q, $ionicLoading, zmAutoLogin, $cordovaPinDialog, EventServer, $ionicHistory, $state, $ionicActionSheet, SecuredPopups, $localstorage, $stateParams) {
$scope.openMenu = function () {
$ionicSideMenuDelegate.toggleLeft();
};
Expand Down Expand Up @@ -105,7 +105,7 @@ angular.module('zmApp.controllers').controller('zmApp.LoginCtrl', ['$scope', '$r
var zmServers = ZMDataModel.getServerGroups();
$scope.loginData = zmServers[serverbuttons[index].text];

console.log ("NEW LOOGIN OBJECT IS " + JSON.stringify($scope.loginData));
console.log ("NEW LOGIN OBJECT IS " + JSON.stringify($scope.loginData));


$scope.check.isUseAuth = ($scope.loginData.isUseAuth == '1') ? true : false;
Expand Down Expand Up @@ -203,6 +203,28 @@ angular.module('zmApp.controllers').controller('zmApp.LoginCtrl', ['$scope', '$r

}

ZMDataModel.zmDebug ("Does login need to hear the wizard? " + $stateParams.wizard);

if ($stateParams.wizard == "true")
{
ZMDataModel.zmLog ("Creating new login entry for wizard");
$scope.loginData = angular.copy(ZMDataModel.getDefaultLoginObject());
$scope.loginData.url = $rootScope.wizard.loginURL;
$scope.loginData.apiurl = $rootScope.wizard.apiURL;
$scope.loginData.streamingurl = $rootScope.wizard.streamingURL;
if ($rootScope.wizard.useauth && $rootScope.wizard.usezmauth)
{
$scope.loginData.username = $rootScope.wizard.zmuser;
$scope.loginData.password = $rootScope.wizard.zmpassword;
if ((/^https:\/\//i.test($scope.loginData.url)))
{
$scope.loginData.useSSL = true;
}
}

}


});


Expand Down
2 changes: 1 addition & 1 deletion www/js/MonitorCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ angular.module('zmApp.controllers')
$ionicHistory.nextViewOptions({
disableBack: true
});
$state.go("login");
$state.go("login" ,{"wizard": false});
return;
}

Expand Down
2 changes: 1 addition & 1 deletion www/js/MontageCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ angular.module('zmApp.controllers').controller('zmApp.MontageCtrl', ['$scope', '
$ionicHistory.nextViewOptions({
disableBack: true
});
$state.go("login");
$state.go("login" ,{"wizard": false});
return;
}

Expand Down
6 changes: 3 additions & 3 deletions www/js/PortalLoginCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ angular.module('zmApp.controllers').controller('zmApp.PortalLoginCtrl', ['$ionic
disableAnimate: true,
disableBack: true
});
$state.go('login');
$state.go("login" ,{"wizard": false});
}
else
{
Expand Down Expand Up @@ -221,13 +221,13 @@ angular.module('zmApp.controllers').controller('zmApp.PortalLoginCtrl', ['$ionic
disableAnimate: true,
disableBack: true
});
$state.go('login');
$state.go("login" ,{"wizard": false});
}
else
{
// if user cancelled auth I guess we go to login
$rootScope.userCancelledAuth = false;
$state.go('login');
$state.go("login" ,{"wizard": false});
}
});
}
Expand Down
142 changes: 102 additions & 40 deletions www/js/WizardCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,45 @@ angular.module('zmApp.controllers').controller('zmApp.WizardCtrl', ['$scope', '$
d.reject(false);
return d.promise;
}
});
})
.error (function (error) {
console.log("************ERROR");
$scope.wizard.portalValidText = "Portal login was unsuccessful";
$scope.wizard.portalColor = "#e74c3c";
d.reject(false);
return d.promise;

});

return d.promise;

}


function getFirstMonitor()
{
var d=$q.defer(); $http.get($scope.wizard.apiURL+"/monitors.json")
.then (function (success) {
if (success.data.monitors.length > 0)
{

ZMDataModel.zmDebug("zmWizard - getFirstMonitor returned " + success.data.monitors[0].Monitor.Id); d.resolve(success.data.monitors[0].Monitor.Id);
return d.promise;

}
else
{
d.reject(false);
return d.promise;
}
},
function (error) {
d.reject(false);
return d.promise;
});
return d.promise;
}

//--------------------------------------------------------------------------
// Utility function - iterates through a list of URLs
//--------------------------------------------------------------------------
Expand Down Expand Up @@ -133,27 +165,38 @@ angular.module('zmApp.controllers').controller('zmApp.WizardCtrl', ['$scope', '$

function continueCgi (urls)
{
var tail = "/nph-zms?mode=single&monitor=1";
if ($scope.wizard.useauth && $scope.wizard.usezmauth)
{
tail+= "&user="+$scope.wizard.zmuser+"&pass="+$scope.wizard.zmpassword;
}
findFirstReachableUrl(urls,tail )
.then (function (success) {
ZMDataModel.zmLog ("Valid cgi-bin found with: " + success);
$scope.wizard.streamingURL = success;
$scope.wizard.streamingValidText = "cgi-bin detection succeeded: "+$scope.wizard.streamingURL;
$scope.wizard.streamingColor = "#16a085";
d.resolve(true);
return d.promise;

getFirstMonitor()
.then (function (success){

var tail = "/nph-zms?mode=single&monitor="+success;
if ($scope.wizard.useauth && $scope.wizard.usezmauth)
{
tail+= "&user="+$scope.wizard.zmuser+"&pass="+$scope.wizard.zmpassword;
}
findFirstReachableUrl(urls,tail )
.then (function (success) {
ZMDataModel.zmLog ("Valid cgi-bin found with: " + success);
$scope.wizard.streamingURL = success;
$scope.wizard.streamingValidText = "cgi-bin detection succeeded: "+$scope.wizard.streamingURL;
$scope.wizard.streamingColor = "#16a085";
d.resolve(true);
return d.promise;

},
function (error) {
console.log ("No cgi-bin found: " + error);
$scope.wizard.streamingValidText = "cgi-bin detection failed";
$scope.wizard.streamingColor = "#e74c3c";
d.reject (false);
return (d.promise);
});
},
function (error) {
console.log ("No cgi-bin found: " + error);
$scope.wizard.streamingValidText = "cgi-bin detection failed";
$scope.wizard.streamingColor = "#e74c3c";
d.reject (false);
return (d.promise);
function (error){
$scope.wizard.streamingValidText = "cgi-bin detection failed. No configured monitor found.";
$scope.wizard.streamingColor = "#e74c3c";
d.reject (false);
return (d.promise);

});
}

Expand All @@ -172,24 +215,28 @@ angular.module('zmApp.controllers').controller('zmApp.WizardCtrl', ['$scope', '$
{
var u = $scope.wizard.loginURL;
var d = $q.defer();
var api1 = u ;
var api1 = u+"/api" ;
var c = URI.parse(u);

// lets also try without the path
var api2 = c.scheme+"://";
if (c.userinfo) api2+= c.userinfo+"@";
api2 +=c.host;
if (c.port) api2+= ":"+c.port;
api2+="/api";



// lets try both /zm/api and /api. What else is there?
var apilist = [api1, api2];

findFirstReachableUrl(apilist, '/api/host/getVersion.json')
findFirstReachableUrl(apilist, '/host/getVersion.json')
.then (function (success) {
ZMDataModel.zmLog ("Valid API response found with:" + success);
$scope.wizard.apiURL = success;



$scope.wizard.apiValidText = "API detection succeeded: "+$scope.wizard.apiURL;
$scope.wizard.apiColor = "#16a085";
d.resolve(true);
Expand Down Expand Up @@ -235,16 +282,22 @@ angular.module('zmApp.controllers').controller('zmApp.WizardCtrl', ['$scope', '$
view: "login"
}
})
.finally(function (ans) {
return d.resolve(true);

});

.then (function (success) {console.log ("ZMlogout success"); d.resolve(true); return d.promise;}, function (error) {console.log ("ZMlogout success");d.resolve(true); return d.promise;});


return d.promise;

}


$scope.enterResults = function()
{
$scope.portalValidText = "";
$scope.apiValidateText = "";
$scope.streamingValidateText = "";
$scope.wizard.fqportal = "";
return true;
};
//--------------------------------------------------------------------------
// tries to log into the portal and then discover api and cgi-bin
//--------------------------------------------------------------------------
Expand Down Expand Up @@ -310,7 +363,16 @@ angular.module('zmApp.controllers').controller('zmApp.WizardCtrl', ['$scope', '$
detectapi()
.then (function (success) {
ZMDataModel.zmLog ("zmWizard: API succeeded");
return d.resolve(true);
// CGI detection
detectcgi ()
.then (function (success) {
// return true here because we want to progress
return d.resolve(true);
},
function (error) {
// return true here because we want to progress
return d.resolve(true);
});
},
function (error) {
ZMDataModel.zmLog("zmWizard: api failed");
Expand All @@ -319,24 +381,15 @@ angular.module('zmApp.controllers').controller('zmApp.WizardCtrl', ['$scope', '$
return d.resolve(true);
});

// CGI detection
detectcgi ()
.then (function (success) {
// return true here because we want to progress
return d.resolve(true);
},
function (error) {
// return true here because we want to progress
return d.resolve(true);
});

},

// if login failed, don't progress in the wizard
function (error) {
ZMDataModel.zmLog("zmWizard: login failed");
$scope.wizard.portalValidText = "Portal login was unsuccessful. Please go back and review your settings";
$scope.wizard.portalColor = "#e74c3c";
return d.resolve(false);
return d.resolve(true);

});

Expand Down Expand Up @@ -499,13 +552,22 @@ angular.module('zmApp.controllers').controller('zmApp.WizardCtrl', ['$scope', '$
$scope.wizard.tiptext = "show tip";
};

$scope.gotoLoginState = function()
{
$rootScope.wizard = angular.copy($scope.wizard);
$ionicHistory.nextViewOptions({
disableBack: true
});
$state.go("login", {"wizard":true});
};

//--------------------------------------------------------------------------
// initial
//--------------------------------------------------------------------------
$scope.$on('$ionicView.beforeEnter', function () {
//console.log("**VIEW ** Help Ctrl Entered");

var monId = -1;
$scope.wizard = {
tipshow: false,
tiptext: "show tip",
Expand Down
4 changes: 2 additions & 2 deletions www/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -1106,7 +1106,7 @@ angular.module('zmApp', [
disableBack: true
});
$rootScope.userCancelledAuth = true;
$state.go("login");
$state.go("login" ,{"wizard": false});

};

Expand Down Expand Up @@ -1419,7 +1419,7 @@ angular.module('zmApp', [
data: {
requireLogin: false
},
url: "/login",
url: "/login/:wizard",
templateUrl: "templates/login.html",
controller: 'zmApp.LoginCtrl',

Expand Down
Loading

0 comments on commit 0354373

Please sign in to comment.