From 0e838997566dbe707c40d295f690e24a1e5c7fe5 Mon Sep 17 00:00:00 2001 From: Pliable Pixels Date: Wed, 31 Aug 2016 12:23:41 -0400 Subject: #126 - the "Aaron hack" seems resolve this issue. case of 'When you don't know why, assume its the law of nature and work around it' Former-commit-id: 2d91598fdbad176415e699ded2e70f4c058107e0 --- www/js/PortalLoginCtrl.js | 80 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 77 insertions(+), 3 deletions(-) (limited to 'www/js') diff --git a/www/js/PortalLoginCtrl.js b/www/js/PortalLoginCtrl.js index f579ab8c..da122d0c 100644 --- a/www/js/PortalLoginCtrl.js +++ b/www/js/PortalLoginCtrl.js @@ -120,7 +120,70 @@ angular.module('zmApp.controllers').controller('zmApp.PortalLoginCtrl', ['$ionic }; - + //------------------------------------------------------------------------ + // Aaron Lager hack - can't figure out why he gets a 401 after + // successful login and then it works after resaving + //------------------------------------------------------------------------ + function tryLoggingSecondTimeHack() + { + var d = $q.defer(); + + zmAutoLogin.doLogin("") + .then(function (data) // success + { + ZMDataModel.zmDebug ("2nd auth login worked"); + ZMDataModel.getAPIversion() + .then (function (data) { + ZMDataModel.getKeyConfigParams(1); + ZMDataModel.zmLog("2nd auth:Got API version: " + data); + $rootScope.apiVersion = data; + var ld = ZMDataModel.getLogin(); + if (ZMDataModel.versionCompare(data,zm.minAppVersion)==-1 && data !="0.0.0") + { + + $state.go('lowversion', {"ver":data}); + } + + if (ZMDataModel.versionCompare(data,zm.recommendedAppVersion)==-1 && data !="0.0.0") + { + + $state.go('importantmessage', {"ver":data}); + } + + if (data == "0.0.0") + { + + ZMDataModel.zmLog ("2nd Auth:API getVersion succeeded but returned 0.0.0 " + JSON.stringify(data)); + ZMDataModel.displayBanner('error', ['ZoneMinder authentication failed']); + $state.go("login" ,{"wizard": false}); + + } + // coming here means continue + EventServer.refresh(); + var statetoGo = $rootScope.lastState ? $rootScope.lastState : 'montage'; + //ZMDataModel.zmDebug ("logging state transition"); + ZMDataModel.zmDebug("2nd Auth: Transitioning state to: " + + statetoGo + " with param " +JSON.stringify($rootScope.lastStateParam) ); + $state.go(statetoGo, $rootScope.lastStateParam); + + }, + function (error) { + ZMDataModel.zmDebug ("2nd auth API failed, going to login"); + d.reject("failed 2nd auth"); + return (d.promise); + + }); + + + }, + function (error) { + ZMDataModel.zmDebug ("2nd auth hack failed, going to login"); + d.reject("failed 2nd auth"); + return (d.promise); + }); + + return (d.promise); + } function unlock(idVerified) { /* @@ -180,8 +243,19 @@ angular.module('zmApp.controllers').controller('zmApp.PortalLoginCtrl', ['$ionic }, function (error) { // API Error ZMDataModel.zmLog ("API Error handler: going to login getAPI returned error: " + JSON.stringify(error)); - ZMDataModel.displayBanner('error', ['ZoneMinder authentication failed']); - $state.go("login" ,{"wizard": false}); + //ZMDataModel.displayBanner('error', ['ZoneMinder authentication failed']); + + ZMDataModel.zmDebug ("Doing the Aaron Hack after 1 sec...."); + $timeout ( function () { + tryLoggingSecondTimeHack() + .then (function success(s) { + ZMDataModel.zmLog ("2nd time login hack worked!, nothing to do"); + }, + function error(e) { + $state.go("login" ,{"wizard": false}); + }); + + },1000); }); -- cgit v1.2.3