Skip to content

Commit

Permalink
#234 - more functionality - portal check done
Browse files Browse the repository at this point in the history
  • Loading branch information
pliablepixels committed May 1, 2016
1 parent 9331c61 commit b6acebb
Show file tree
Hide file tree
Showing 3 changed files with 217 additions and 15 deletions.
2 changes: 1 addition & 1 deletion www/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ <h1 class="title">Options</h1>

<ion-item nav-clear menu-close href="#/wizard">
<span class=" item-icon-left">
<i class="icon ion-help"></i>
<i class="icon ion-wand"></i>
</span> wizard
</ion-item>

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

angular.module('zmApp.controllers').controller('zmApp.WizardCtrl', ['$scope', '$rootScope', '$ionicModal', 'ZMDataModel','$ionicSideMenuDelegate', '$ionicHistory', '$state', '$ionicPopup', 'SecuredPopups',function ($scope, $rootScope, $ionicModal, ZMDataModel,$ionicSideMenuDelegate, $ionicHistory, $state, $ionicPopup, SecuredPopups) {
angular.module('zmApp.controllers').controller('zmApp.WizardCtrl', ['$scope', '$rootScope', '$ionicModal', 'ZMDataModel','$ionicSideMenuDelegate', '$ionicHistory', '$state', '$ionicPopup', 'SecuredPopups', '$http','$q','zm',function ($scope, $rootScope, $ionicModal, ZMDataModel,$ionicSideMenuDelegate, $ionicHistory, $state, $ionicPopup, SecuredPopups, $http, $q,zm) {
$scope.openMenu = function () {
$ionicSideMenuDelegate.toggleLeft();
};


function login (u,zmu,zmp)
{
var d = $q.defer();

$http({
method: 'POST',
//withCredentials: true,
url: u,
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Accept': 'application/json',
},
transformRequest: function (obj) {
var str = [];
for (var p in obj)
str.push(encodeURIComponent(p) + "=" +
encodeURIComponent(obj[p]));
var params = str.join("&");
return params;
},

data: {
username: zmu,
password: zmp,
action: "login",
view: "console"
}
})
.success (function (data, status,headers){
console.log ("LOOKING FOR " + zm.loginScreenString);
//console.log ("DATA RECEIVED " + JSON.stringify(data));
if (data.indexOf(zm.loginScreenString) == -1)
{
d.resolve(true);
return d.promise;
}
else
{
console.log ("************ERROR");
d.reject(false);
return d.promise;
}
});

return d.promise;

}

function logout(u)
{
var d = $q.defer();

$http({
method: 'POST',
url: u,
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Accept': 'application/json',
},
transformRequest: function (obj) {
var str = [];
for (var p in obj)
str.push(encodeURIComponent(p) + "=" +
encodeURIComponent(obj[p]));
var params = str.join("&");
return params;
},

data: {
action: "logout",
view: "login"
}
})
.finally (function (ans) {
return d.resolve(true);

});


return d.promise;

}

$scope.exitValidate = function()
{
$rootScope.authSession = 'undefined';
$rootScope.zmCookie = '';

$scope.portalValidText = "";
$scope.apiValidateText = "";
$scope.streamingValidateText = "";
$scope.wizard.fqportal = "";

var d = $q.defer();

var c = URI.parse ($scope.wizard.portalurl);

var b ="";
if ($scope.wizard.useauth && $scope.wizard.usebasicauth)
{
b = $scope.wizard.basicuser+":"+$scope.wizard.basicpassword+"@";
console.log ("B="+b);
}
var u = c.scheme+"://"+b+c.host;
if (c.port) u+= ":"+c.port;
if (c.path) u+= c.path;


if (u.slice(-1) == '/') {
u = u.slice(0, -1);

}

$scope.fqportal = u;

u = u+'/index.php';
ZMDataModel.zmLog ("Wizard: login url is " + u);

// now lets login

var zmu = "x";
var zmp = "x";
if ($scope.wizard.usezmauth)
{
zmu = $scope.wizard.zmuser;
zmp = $scope.wizard.zmpassword;
}

// logout first for the adventurers amongst us who must
// use it even after logging in
ZMDataModel.zmLog ("zmWizard: logging out");
logout(u)
.then ( function (ans)
{
// login now
ZMDataModel.zmLog ("zmWizard: logging in with "+u+" "+zmu+":"+zmp);
login(u,zmu,zmp)
.then ( function (success){
ZMDataModel.zmLog ("zmWizard: login succeeded");
$scope.wizard.portalValidText = "Portal login was successful";
$scope.wizard.portalColor = "#16a085";
return d.resolve(true);
},
function (error) {
ZMDataModel.zmLog ("zmWizard: login failed");
$scope.wizard.portalValidText = "Portal login was unsuccessful";
$scope.wizard.portalColor = "#e74c3c";
return d.resolve(false);

});


});//finally
return d.promise;
};


//--------------------------------------------------------------------------
// tags a protocol
//--------------------------------------------------------------------------
function addhttp(url) {
function checkscheme(url) {

if ((!/^(f|ht)tps?:\/\//i.test(url)) && (url != "")) {
url = "http://" + url;
return false;
}
return url;
else
return true;
}



//--------------------------------------------------------------------------
// exit validator for auth wizard
//--------------------------------------------------------------------------
Expand Down Expand Up @@ -92,8 +249,19 @@ $scope.openMenu = function () {
return false;
}

if ( !checkscheme($scope.wizard.portalurl))
{
$rootScope.zmPopup = SecuredPopups.show('show',{
title: 'Whoops!',
template: 'Please specify http:// or https:// in the url',
buttons: [{text: 'Ok'}]

});
return false;
}

$scope.wizard.portalurl = $scope.wizard.portalurl.toLowerCase().trim();
$scope.wizard.portalurl = addhttp($scope.wizard.portalurl);

ZMDataModel.zmLog ("Wizard: stripped url:"+$scope.wizard.portalurl);

var c = URI.parse ($scope.wizard.portalurl);
Expand Down Expand Up @@ -121,7 +289,7 @@ $scope.openMenu = function () {

$scope.wizard.portalurl = c.scheme+"://";
if (c.host) $scope.wizard.portalurl += c.host;
if (c.port) $scope.wizard.portalurl += ":"+c.host;
if (c.port) $scope.wizard.portalurl += ":"+c.port;
if (c.path) $scope.wizard.portalurl += c.path;
ZMDataModel.zmLog ("Wizard: normalized url:"+$scope.wizard.portalurl);
return true;
Expand Down Expand Up @@ -170,7 +338,20 @@ $scope.openMenu = function () {
basicuser : "",
basicpassword : "",
zmuser : "",
zmpassword : ""
zmpassword : "",
///////////////////////
loginURL: "",
apiURL: "",
streamingURL: "",
fqportal:"",
portalValidText:"",
portalColor:"",
apiValidText:"",
apiColor:"",
streamingValidText:"",
streamingColor:"",


};

});
Expand Down
35 changes: 28 additions & 7 deletions www/templates/wizard.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<!-- portal url -->
<wz-step wz-title="1" canexit="exitPortal">
<h4>Welcome to zmWizard</h4>
<h4><i class="icon ion-wizard"></i> Welcome to zmWizard</h4>
<p>Configuring ZoneMinder can be a pain. Lets see if zmWizard can help. In the next few screens, I will ask you some simple questions and do my best to guess the settings for you.</p>

<h4>What is your Zoneminder portal url?</h4>
Expand All @@ -28,7 +28,9 @@ <h4>What is your Zoneminder portal url?</h4>
<img src="img/portalurl.png" width="30%">
</div>

<br/><input type="button" wz-next value="Next" />
<br/>
<button class="button icon icon-right ion-chevron-right" wz-next>Next</button>


</wz-step>

Expand Down Expand Up @@ -70,20 +72,39 @@ <h4>Portal Authentication</h4>
</div>

<br/>
<input type="button" wz-previous value="Prev" />
<input type="button" wz-next value="Next" />
<button class="button icon icon-left ion-chevron-left" wz-previous>Prev</button>
<button class="button icon icon-right ion-chevron-right" wz-next>Next</button>

</wz-step>

<!-- validate url with auth -->
<wz-step wz-title="3">
<wz-step wz-title="3" canexit="exitValidate">
<h4>Lets try and validate your inputs</h4>
<p>I am now going to try and log into the portal using:
<p>I am now going to try and log into the ZM portal
<br/>
<span style="color:{{wizard.portalColor}};">{{wizard.portalValidText}}</span>
<span style="color:{{wizard.apiColor}};">{{wizard.apiValidateText}}</span>
<span style="color:{{wizard.streamingColor}};">{{wizard.streamingValidateText}}</span>

</p>
<button class="button icon icon-left ion-chevron-left" wz-previous>Prev</button>
<button class="button icon icon-right ion-chevron-right" wz-next>Next</button>
</wz-step>

<wz-step wz-title="4" >
<h4>Sone</h4>
<p>I am now going to try and log into the ZM portal
<br/>Portal: {{wizard.portalurl}}
{{wizard.portalValidText}}
{{wizard.apiValidateText}}
{{wizard.streamingValidateText}}

</p>
<input type="button" wz-next value="Finish now" />
<button class="button icon icon-left ion-chevron-left" wz-previous>Prev</button>
<button class="button icon icon-right ion-chevron-right" wz-next>Validate</button>
</wz-step>


</wizard>
</ion-content>

Expand Down

0 comments on commit b6acebb

Please sign in to comment.