Merge pull request #5896 from JDonadio/bug/config-lock
Fix lock options by default
This commit is contained in:
commit
79653c5945
8 changed files with 96 additions and 72 deletions
|
|
@ -1,21 +1,16 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
angular.module('copayApp.controllers').controller('lockController', function($state, $scope, $timeout, $log, configService, popupService, gettextCatalog, appConfigService, fingerprintService, profileService, lodash) {
|
angular.module('copayApp.controllers').controller('lockSetupController', function($state, $scope, $timeout, $log, configService, popupService, gettextCatalog, appConfigService, fingerprintService, profileService, lodash) {
|
||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
var config = configService.getSync();
|
|
||||||
$scope.locking = config.lock.method != 'pin';
|
|
||||||
|
|
||||||
$scope.options = [
|
$scope.options = [
|
||||||
{
|
{
|
||||||
method: 'none',
|
method: null,
|
||||||
label: gettextCatalog.getString('Disabled'),
|
label: gettextCatalog.getString('Disabled'),
|
||||||
value: config.lock.method == '',
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
method: 'pin',
|
method: 'pin',
|
||||||
label: gettextCatalog.getString('Enable PIN'),
|
label: gettextCatalog.getString('Lock by PIN'),
|
||||||
value: config.lock.method == 'pin',
|
|
||||||
needsBackup: null,
|
needsBackup: null,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
@ -23,13 +18,17 @@ angular.module('copayApp.controllers').controller('lockController', function($st
|
||||||
if (fingerprintService.isAvailable()) {
|
if (fingerprintService.isAvailable()) {
|
||||||
$scope.options.push({
|
$scope.options.push({
|
||||||
method: 'fingerprint',
|
method: 'fingerprint',
|
||||||
label: gettextCatalog.getString('Enable Fingerprint'),
|
label: gettextCatalog.getString('Lock by Fingerprint'),
|
||||||
value: config.lock.method == 'fingerprint',
|
|
||||||
needsBackup: null,
|
needsBackup: null,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
$scope.currentOption = lodash.find($scope.options, 'value');
|
var config = configService.getSync();
|
||||||
|
var method = config.lock && config.lock.method;
|
||||||
|
if (!method) $scope.currentOption = $scope.options[0];
|
||||||
|
else $scope.currentOption = lodash.find($scope.options, {
|
||||||
|
'method': method
|
||||||
|
});
|
||||||
processWallets();
|
processWallets();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -70,21 +69,24 @@ angular.module('copayApp.controllers').controller('lockController', function($st
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.select = function(method) {
|
$scope.select = function(selectedMethod) {
|
||||||
if (method == 'none')
|
var config = configService.getSync();
|
||||||
|
var savedMethod = config.lock && config.lock.method;
|
||||||
|
|
||||||
|
if (!selectedMethod)
|
||||||
saveConfig();
|
saveConfig();
|
||||||
else if (method == 'fingerprint') {
|
else if (selectedMethod == 'fingerprint') {
|
||||||
var config = configService.getSync();
|
if (savedMethod == 'pin') {
|
||||||
if (config.lock.method == 'pin') {
|
|
||||||
askForDisablePin(function(disablePin) {
|
askForDisablePin(function(disablePin) {
|
||||||
if (disablePin) saveConfig('fingerprint');
|
if (disablePin) saveConfig('fingerprint');
|
||||||
else init();
|
else init();
|
||||||
});
|
});
|
||||||
} else saveConfig('fingerprint');
|
} else saveConfig('fingerprint');
|
||||||
} else if (method == 'pin') {
|
} else if (selectedMethod == 'pin') {
|
||||||
$state.transitionTo('tabs.lock.pin', {
|
if (savedMethod == 'pin') return;
|
||||||
|
$state.transitionTo('tabs.pin', {
|
||||||
fromSettings: true,
|
fromSettings: true,
|
||||||
locking: $scope.locking
|
locking: savedMethod == 'pin' ? false : true
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
$timeout(function() {
|
$timeout(function() {
|
||||||
|
|
@ -93,7 +95,7 @@ angular.module('copayApp.controllers').controller('lockController', function($st
|
||||||
};
|
};
|
||||||
|
|
||||||
function askForDisablePin(cb) {
|
function askForDisablePin(cb) {
|
||||||
var message = gettextCatalog.getString('{{appName}} is protected by Pin. Are you sure you want to disable it?', {
|
var message = gettextCatalog.getString('{{appName}} startup is locked by PIN. Are you sure you want to disable it?', {
|
||||||
appName: appConfigService.nameCase
|
appName: appConfigService.nameCase
|
||||||
});
|
});
|
||||||
var okText = gettextCatalog.getString('Continue');
|
var okText = gettextCatalog.getString('Continue');
|
||||||
|
|
@ -107,8 +109,8 @@ angular.module('copayApp.controllers').controller('lockController', function($st
|
||||||
function saveConfig(method) {
|
function saveConfig(method) {
|
||||||
var opts = {
|
var opts = {
|
||||||
lock: {
|
lock: {
|
||||||
method: method || '',
|
method: method || null,
|
||||||
value: '',
|
value: null,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -15,6 +15,7 @@ angular.module('copayApp.controllers').controller('pinController', function($sta
|
||||||
|
|
||||||
$scope.$on("$ionicView.enter", function(event) {
|
$scope.$on("$ionicView.enter", function(event) {
|
||||||
configService.whenAvailable(function(config) {
|
configService.whenAvailable(function(config) {
|
||||||
|
if (!config.lock) return;
|
||||||
$scope.bannedUntil = config.lock.bannedUntil || null;
|
$scope.bannedUntil = config.lock.bannedUntil || null;
|
||||||
if ($scope.bannedUntil) {
|
if ($scope.bannedUntil) {
|
||||||
var now = Math.floor(Date.now() / 1000);
|
var now = Math.floor(Date.now() / 1000);
|
||||||
|
|
@ -156,12 +157,13 @@ angular.module('copayApp.controllers').controller('pinController', function($sta
|
||||||
|
|
||||||
function saveSettings(method, value) {
|
function saveSettings(method, value) {
|
||||||
var config = configService.getSync();
|
var config = configService.getSync();
|
||||||
|
var attempts = config.lock && config.lock.attempts ? config.lock.attempts : 0;
|
||||||
var opts = {
|
var opts = {
|
||||||
lock: {
|
lock: {
|
||||||
method: method || '',
|
method: method || null,
|
||||||
value: value || '',
|
value: value || null,
|
||||||
bannedUntil: null,
|
bannedUntil: null,
|
||||||
attempts: config.lock.attempts + 1,
|
attempts: attempts + 1,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -173,7 +175,12 @@ angular.module('copayApp.controllers').controller('pinController', function($sta
|
||||||
|
|
||||||
$scope.close = function(delay) {
|
$scope.close = function(delay) {
|
||||||
$timeout(function() {
|
$timeout(function() {
|
||||||
$ionicHistory.viewHistory().backView ? $ionicHistory.goBack() : $state.go('tabs.home');
|
var shouldReturn = $ionicHistory.viewHistory().backView && $ionicHistory.viewHistory().backView.stateName != 'starting';
|
||||||
|
|
||||||
|
if (shouldReturn)
|
||||||
|
$ionicHistory.goBack()
|
||||||
|
else
|
||||||
|
$state.go('tabs.home');
|
||||||
}, delay || 1);
|
}, delay || 1);
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -54,8 +54,8 @@ angular.module('copayApp.controllers').controller('tabSettingsController', funct
|
||||||
$scope.isDevel = platformInfo.isDevel;
|
$scope.isDevel = platformInfo.isDevel;
|
||||||
$scope.appName = appConfigService.nameCase;
|
$scope.appName = appConfigService.nameCase;
|
||||||
configService.whenAvailable(function(config) {
|
configService.whenAvailable(function(config) {
|
||||||
$scope.locked = config.lock && config.lock.method != '' ? true : false;
|
$scope.locked = config.lock && config.lock.method;
|
||||||
$scope.method = config.lock && config.lock.method != '' ? config.lock.method.charAt(0).toUpperCase() + config.lock.method.slice(1) : gettextCatalog.getString('Disabled');
|
$scope.method = $scope.locked ? config.lock.method.charAt(0).toUpperCase() + config.lock.method.slice(1) : gettextCatalog.getString('Disabled');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -463,16 +463,16 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.state('tabs.lock', {
|
.state('tabs.lockSetup', {
|
||||||
url: '/lock',
|
url: '/lockSetup',
|
||||||
views: {
|
views: {
|
||||||
'tab-settings@tabs': {
|
'tab-settings@tabs': {
|
||||||
controller: 'lockController',
|
controller: 'lockSetupController',
|
||||||
templateUrl: 'views/lock.html',
|
templateUrl: 'views/lockSetup.html',
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.state('tabs.lock.pin', {
|
.state('tabs.pin', {
|
||||||
url: '/pin/:fromSettings/:locking',
|
url: '/pin/:fromSettings/:locking',
|
||||||
views: {
|
views: {
|
||||||
'tab-settings@tabs': {
|
'tab-settings@tabs': {
|
||||||
|
|
@ -1195,25 +1195,53 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
|
||||||
// Nothing to do
|
// Nothing to do
|
||||||
});
|
});
|
||||||
|
|
||||||
$ionicPlatform.on('resume', function() {
|
|
||||||
configService.whenAvailable(function(config) {
|
|
||||||
var nextView;
|
|
||||||
var lock = config.lock;
|
|
||||||
if (lock && lock.method == 'fingerprint' && fingerprintService.isAvailable()) {
|
|
||||||
fingerprintService.check('unlockingApp', function(err) {
|
|
||||||
if (err) goTo('lockedView');
|
|
||||||
else if ($ionicHistory.currentStateName() == 'lockedView') goTo('tabs.home');
|
|
||||||
});
|
|
||||||
} else if (lock && lock.method == 'pin') {
|
|
||||||
goTo('pin');
|
|
||||||
}
|
|
||||||
|
|
||||||
function goTo(nextView) {
|
function checkAndApplyLock(onResume) {
|
||||||
$state.transitionTo(nextView).then(function() {
|
var defaultView = 'tabs.home';
|
||||||
if (nextView == 'lockedView') $ionicHistory.clearHistory();
|
|
||||||
|
if (!platformInfo.isCordova && !platformInfo.isDevel) {
|
||||||
|
goTo(defaultView);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (onResume) {
|
||||||
|
var now = Math.floor(Date.now() / 1000);
|
||||||
|
if (now < openURLService.unlockUntil) {
|
||||||
|
$log.debug('Skip startup locking');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function goTo(nextView) {
|
||||||
|
nextView = nextView || defaultView;
|
||||||
|
$state.transitionTo(nextView).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');
|
||||||
|
if ($ionicHistory.currentStateName() == 'lockedView' || !onResume)
|
||||||
|
goTo('tabs.home');
|
||||||
});
|
});
|
||||||
};
|
} else if (lockMethod == 'pin') {
|
||||||
|
goTo('pin');
|
||||||
|
} else {
|
||||||
|
goTo(defaultView);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
$ionicPlatform.on('resume', function() {
|
||||||
|
checkAndApplyLock(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
$ionicPlatform.on('menubutton', function() {
|
$ionicPlatform.on('menubutton', function() {
|
||||||
|
|
@ -1256,33 +1284,14 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
|
||||||
disableAnimate: true,
|
disableAnimate: true,
|
||||||
historyRoot: true
|
historyRoot: true
|
||||||
});
|
});
|
||||||
if (platformInfo.isCordova || platformInfo.isDevel) {
|
|
||||||
startupService.ready();
|
|
||||||
configService.whenAvailable(function(config) {
|
|
||||||
var lock = config.lock;
|
|
||||||
if (fingerprintService.isAvailable() && lock && lock.method == 'fingerprint') {
|
|
||||||
fingerprintService.check('unlockingApp', function(err) {
|
|
||||||
if (err) goTo('lockedView');
|
|
||||||
else goTo('tabs.home');
|
|
||||||
});
|
|
||||||
} else if (lock && lock.method == 'pin') {
|
|
||||||
goTo('pin');
|
|
||||||
} else
|
|
||||||
goTo('tabs.home');
|
|
||||||
});
|
|
||||||
} else goTo('tabs.home');
|
|
||||||
|
|
||||||
function goTo(nextView) {
|
checkAndApplyLock();
|
||||||
$state.transitionTo(nextView).then(function() {
|
|
||||||
$ionicHistory.clearHistory();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
// After everything have been loaded, initialize handler URL
|
// After everything have been loaded, initialize handler URL
|
||||||
$timeout(function() {
|
$timeout(function() {
|
||||||
openURLService.init();
|
openURLService.init();
|
||||||
}, 1000);
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -54,8 +54,8 @@ angular.module('copayApp.services').factory('configService', function(storageSer
|
||||||
},
|
},
|
||||||
|
|
||||||
lock: {
|
lock: {
|
||||||
method: '',
|
method: null,
|
||||||
value: '',
|
value: null,
|
||||||
bannedUntil: null,
|
bannedUntil: null,
|
||||||
attempts: null,
|
attempts: null,
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,15 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
angular.module('copayApp.services').factory('openURLService', function($rootScope, $ionicHistory, $document, $log, $state, platformInfo, lodash, profileService, incomingData, appConfigService) {
|
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 = {};
|
var root = {};
|
||||||
|
|
||||||
|
root.unlockUntil = null;
|
||||||
|
|
||||||
var handleOpenURL = function(args) {
|
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));
|
$log.info('Handling Open URL: ' + JSON.stringify(args));
|
||||||
// Stop it from caching the first view as one to return when the app opens
|
// Stop it from caching the first view as one to return when the app opens
|
||||||
$ionicHistory.nextViewOptions({
|
$ionicHistory.nextViewOptions({
|
||||||
|
|
@ -103,5 +109,5 @@ angular.module('copayApp.services').factory('openURLService', function($rootScop
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
return root;
|
return root;
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
<ion-view class="settings">
|
<ion-view class="settings">
|
||||||
<ion-nav-bar class="bar-royal">
|
<ion-nav-bar class="bar-royal">
|
||||||
<ion-nav-title>{{'Lock App' | translate}}</ion-nav-title>
|
<ion-nav-title>{{'Startup Lock' | translate}}</ion-nav-title>
|
||||||
<ion-nav-back-button>
|
<ion-nav-back-button>
|
||||||
</ion-nav-back-button>
|
</ion-nav-back-button>
|
||||||
</ion-nav-bar>
|
</ion-nav-bar>
|
||||||
|
|
@ -89,7 +89,7 @@
|
||||||
<i class="icon bp-arrow-right"></i>
|
<i class="icon bp-arrow-right"></i>
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
<a class="item has-setting-value item-icon-left item-icon-right" ui-sref="tabs.lock" ng-if="isCordova || isDevel">
|
<a class="item has-setting-value item-icon-left item-icon-right" ui-sref="tabs.lockSetup" ng-if="isCordova || isDevel">
|
||||||
<i class="icon ion-ios-locked-outline" ng-if="locked"></i>
|
<i class="icon ion-ios-locked-outline" ng-if="locked"></i>
|
||||||
<i class="icon ion-ios-unlocked-outline" ng-if="!locked"></i>
|
<i class="icon ion-ios-unlocked-outline" ng-if="!locked"></i>
|
||||||
<span class="setting-title">{{'Lock App' | translate}}</span>
|
<span class="setting-title">{{'Lock App' | translate}}</span>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue