Skip to content

Commit

Permalink
adding security popups for resume
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielbazan7 committed May 9, 2017
1 parent 9b21292 commit 8dfc2de
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 106 deletions.
11 changes: 9 additions & 2 deletions src/js/controllers/lockSetup.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

angular.module('copayApp.controllers').controller('lockSetupController', function($state, $scope, $timeout, $log, configService, gettextCatalog, fingerprintService, profileService, lodash, applicationService) {
angular.module('copayApp.controllers').controller('lockSetupController', function($state, $rootScope, $scope, $timeout, $log, configService, gettextCatalog, fingerprintService, profileService, lodash, applicationService) {

function init() {
$scope.options = [
Expand Down Expand Up @@ -53,7 +53,7 @@ angular.module('copayApp.controllers').controller('lockSetupController', functio
o.disabled = false;
});

// HACK: Disable untill we allow to change between methods directly
// HACK: Disable until we allow to change between methods directly
if (fingerprintService.isAvailable()) {
switch (savedMethod) {
case 'pin':
Expand Down Expand Up @@ -121,6 +121,7 @@ angular.module('copayApp.controllers').controller('lockSetupController', functio
switch (method) {
case 'pin':
applicationService.pinModal('disable');
initMethodSelector();
break;
case 'fingerprint':
fingerprintService.check('unlockingApp', function(err) {
Expand All @@ -135,6 +136,7 @@ angular.module('copayApp.controllers').controller('lockSetupController', functio
switch (method) {
case 'pin':
applicationService.pinModal('setup');
initMethodSelector();
break;
case 'fingerprint':
saveConfig('fingerprint');
Expand All @@ -155,4 +157,9 @@ angular.module('copayApp.controllers').controller('lockSetupController', functio
initMethodSelector();
});
};

$rootScope.$on('pinModalClosed', function() {
initMethodSelector();
});

});
17 changes: 2 additions & 15 deletions src/js/controllers/modals/pin.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ angular.module('copayApp.controllers').controller('pinController', function($sta
var ATTEMPT_LOCK_OUT_TIME = 5 * 60;
var currentPin;
currentPin = $scope.confirmPin = '';
console.log("############################11111");

$scope.match = $scope.error = $scope.disableButtons = false;
$scope.currentAttempts = 0;
$scope.appName = appConfigService.name;

configService.whenAvailable(function(config) {
if (!config.lock) return;
$scope.bannedUntil = config.lock.bannedUntil || null;
Expand Down Expand Up @@ -104,8 +105,6 @@ angular.module('copayApp.controllers').controller('pinController', function($sta
};

$scope.save = function() {
console.log("##################################### CHECKING");
console.log($scope.action);
if (!$scope.isComplete()) return;
var savedMethod = getSavedMethod();

Expand All @@ -123,7 +122,6 @@ angular.module('copayApp.controllers').controller('pinController', function($sta
break;
case 'check':
if (isMatch(currentPin)) {
console.log("##################################### CHECKING");
applicationService.successfullUnlocked = true;
$scope.hideModal();
return;
Expand Down Expand Up @@ -206,15 +204,4 @@ angular.module('copayApp.controllers').controller('pinController', function($sta
lockTimeControl(bannedUntil);
});
};

// $scope.close = function(delay) {
// $timeout(function() {
// var shouldReturn = $ionicHistory.viewHistory().backView && $ionicHistory.viewHistory().backView.stateName != 'starting';
//
// if (shouldReturn)
// $ionicHistory.goBack()
// else
// $state.go('tabs.home');
// }, delay || 1);
// };
});
61 changes: 2 additions & 59 deletions src/js/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -1183,58 +1183,8 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
// Nothing to do
});


// function checkAndApplyLock(onResume) {
// var defaultView = 'tabs.home';
//
// if (!platformInfo.isCordova && !platformInfo.isDevel) {
// goTo(defaultView);
// }
//
// if (onResume) {
// var now = Math.floor(Date.now() / 1000);
// if (now < openURLService.unlockUntil) {
// openURLService.unlockUntil = null;
// $log.debug('Skip startup locking');
// return;
// }
// }
//
// function goTo(nextView) {
// nextView = nextView || defaultView;
// $state.transitionTo(nextView, {
// action: 'check'
// }).then(function() {
// if (nextView == 'lockedView')
// $ionicHistory.clearHistory();
// });
// };
//
// startupService.ready();
//
// configService.whenAvailable(function(config) {
// var lockMethod = config.lock && config.lock.method;
// $log.debug('App Lock:' + (lockMethod || 'no'));
//
// if (lockMethod == 'fingerprint' && fingerprintService.isAvailable()) {
// fingerprintService.check('unlockingApp', function(err) {
// if (err)
// goTo('lockedView');
// else if ($ionicHistory.currentStateName() == 'lockedView' || !onResume)
// goTo('tabs.home');
// });
// } else if (lockMethod == 'pin') {
// goTo('pin');
// } else {
// goTo(defaultView);
// }
// });
// }

$ionicPlatform.on('resume', function() {
applicationService.successfullUnlocked = false;
applicationService.pinModal('check');
// checkAndApplyLock(true);
applicationService.appLockModal('check');
});

$ionicPlatform.on('menubutton', function() {
Expand Down Expand Up @@ -1305,14 +1255,7 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
$log.debug('Route change from:', fromState.name || '-', ' to:', toState.name);
$log.debug(' toParams:' + JSON.stringify(toParams || {}));
$log.debug(' fromParams:' + JSON.stringify(fromParams || {}));
configService.whenAvailable(function(config) {
var lockMethod = config.lock && config.lock.method;
if (!lockMethod || lockMethod == 'none') return;

if (!applicationService.successfullUnlocked && !applicationService.pinIsOpen) {
console.log("################################# OPEN PIN MODAL");
applicationService.pinModal('check');
}
});
if (!applicationService.successfullUnlocked) applicationService.appLockModal('check');
});
});
46 changes: 28 additions & 18 deletions src/js/services/applicationService.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
'use strict';
angular.module('copayApp.services')
.factory('applicationService', function($rootScope, $timeout, $ionicHistory, $ionicModal, platformInfo, $state) {
.factory('applicationService', function($rootScope, $timeout, $ionicHistory, $ionicModal, platformInfo, fingerprintService, openURLService, configService, $state) {
var root = {};

root.successfullUnlocked = false;
root.pinIsOpen = false;
root.pinModalIsOpen = false;

var isChromeApp = platformInfo.isChromeApp;
var isNW = platformInfo.isNW;
Expand Down Expand Up @@ -36,40 +36,50 @@ angular.module('copayApp.services')
}
};

root.fingerprintModal = function() {
fingerprintService.check('unlockingApp', function(err) {
if (err) {
root.fingerprintModal();
return;
}
root.successfullUnlocked = true;
});
};

root.pinModal = function(action) {
if (root.pinModalIsOpen) return;

root.pinIsOpen = true;
root.successfullUnlocked = false;
var scope = $rootScope.$new(true);
console.log(action);
console.log("###########################111");
scope.action = action;
$ionicModal.fromTemplateUrl('views/modals/pin.html', {
scope: scope,
animation: 'slide-in-up',
animation: 'none',
backdropClickToClose: false,
hardwareBackButtonClose: false
}).then(function(modal) {
scope.pinModal = modal;
scope.openModal();
});
scope.openModal = function() {
root.pinModalIsOpen = true;
scope.pinModal.show();
};
scope.hideModal = function() {
scope.$emit('pinModalClosed');
root.pinModalIsOpen = false;
scope.pinModal.hide();
};
// Cleanup the modal when we're done with it!
scope.$on('$destroy', function() {
scope.modal.remove();
});
// Execute action on hide modal
scope.$on('modal.hidden', function() {
// Execute action
});
// Execute action on remove modal
scope.$on('modal.removed', function() {
// Execute action
};

root.appLockModal = function(action) {

configService.whenAvailable(function(config) {
var lockMethod = config.lock && config.lock.method;
if (!lockMethod || lockMethod == 'none') return;

if (lockMethod == 'fingerprint' && fingerprintService.isAvailable()) root.fingerprintModal();
if (lockMethod == 'pin') root.pinModal(action);

});
}
return root;
Expand Down
5 changes: 0 additions & 5 deletions src/js/services/openURL.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
'use strict';

angular.module('copayApp.services').factory('openURLService', function($rootScope, $ionicHistory, $document, $log, $state, platformInfo, lodash, profileService, incomingData, appConfigService) {
var DELAY_UNLOCK_TIME = 2 * 60;
var root = {};

root.unlockUntil = null;

var handleOpenURL = function(args) {
root.unlockUntil = Math.floor(Date.now() / 1000) + DELAY_UNLOCK_TIME;
$log.debug('Set unlock time until: ' + root.unlockUntil);

$log.info('Handling Open URL: ' + JSON.stringify(args));
// Stop it from caching the first view as one to return when the app opens
Expand Down
8 changes: 1 addition & 7 deletions src/sass/views/pin.scss
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
#pin {
background-color: #FAFAFA;
.bar.bar-clear {
background-color: transparent;
border: none;
.back-button .icon:before {
color: #2d3f50;
}
}
.content {
text-align: center;
position: fixed;
width: 100%;
height: 100%;
.app-icon {
Expand Down

0 comments on commit 8dfc2de

Please sign in to comment.