refactor
This commit is contained in:
parent
163a45a5a0
commit
8be28e85da
7 changed files with 45 additions and 43 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 && config.lock.method == 'pin' ? false : true;
|
|
||||||
|
|
||||||
$scope.options = [
|
$scope.options = [
|
||||||
{
|
{
|
||||||
method: '',
|
method: null,
|
||||||
label: gettextCatalog.getString('Disabled'),
|
label: gettextCatalog.getString('Disabled'),
|
||||||
selected: config.lock && config.lock.method == '' ? true : false,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
method: 'pin',
|
method: 'pin',
|
||||||
label: gettextCatalog.getString('Enable PIN'),
|
label: gettextCatalog.getString('Lock by PIN'),
|
||||||
selected: config.lock && config.lock.method == 'pin' ? true : false,
|
|
||||||
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'),
|
||||||
selected: config.lock && config.lock.method == 'fingerprint' ? true : false,
|
|
||||||
needsBackup: null,
|
needsBackup: null,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
$scope.currentOption = lodash.find($scope.options, 'selected') || $scope.options[0];
|
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 == '')
|
|
||||||
saveConfig();
|
|
||||||
else if (method == 'fingerprint') {
|
|
||||||
var config = configService.getSync();
|
var config = configService.getSync();
|
||||||
if (config.lock.method == 'pin') {
|
var savedMethod = config.lock && config.lock.method;
|
||||||
|
|
||||||
|
if (!selectedMethod)
|
||||||
|
saveConfig();
|
||||||
|
else if (selectedMethod == 'fingerprint') {
|
||||||
|
if (savedMethod == '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,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -160,8 +160,8 @@ angular.module('copayApp.controllers').controller('pinController', function($sta
|
||||||
var attempts = config.lock && config.lock.attempts ? config.lock.attempts : 0;
|
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: attempts + 1,
|
attempts: attempts + 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');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1206,19 +1206,23 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
function checkAndApplyLock(defaultView) {
|
function checkAndApplyLock(onResume) {
|
||||||
|
var defaultView = 'tabs.home';
|
||||||
|
|
||||||
if (!platformInfo.isCordova && !platformInfo.isDevel) {
|
if (!platformInfo.isCordova && !platformInfo.isDevel) {
|
||||||
goTo('tabs.home');
|
goTo(defaultView);
|
||||||
}
|
}
|
||||||
|
|
||||||
function goTo(nextView) {
|
function goTo(nextView) {
|
||||||
|
nextView = nextView || defaultView;
|
||||||
$state.transitionTo(nextView).then(function() {
|
$state.transitionTo(nextView).then(function() {
|
||||||
if (nextView == 'lockedView')
|
if (nextView == 'lockedView')
|
||||||
$ionicHistory.clearHistory();
|
$ionicHistory.clearHistory();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
startupService.ready();
|
||||||
|
|
||||||
configService.whenAvailable(function(config) {
|
configService.whenAvailable(function(config) {
|
||||||
var lockMethod = config.lock && config.lock.method;
|
var lockMethod = config.lock && config.lock.method;
|
||||||
$log.debug('App Lock:' + (lockMethod || 'no'));
|
$log.debug('App Lock:' + (lockMethod || 'no'));
|
||||||
|
|
@ -1227,20 +1231,19 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
|
||||||
fingerprintService.check('unlockingApp', function(err) {
|
fingerprintService.check('unlockingApp', function(err) {
|
||||||
if (err)
|
if (err)
|
||||||
goTo('lockedView');
|
goTo('lockedView');
|
||||||
|
if ($ionicHistory.currentStateName() == 'lockedView' || !onResume)
|
||||||
if ($ionicHistory.currentStateName() == 'lockedView')
|
|
||||||
goTo('tabs.home');
|
goTo('tabs.home');
|
||||||
});
|
});
|
||||||
} else if (lockMethod == 'pin') {
|
} else if (lockMethod == 'pin') {
|
||||||
goTo('pin');
|
goTo('pin');
|
||||||
} else if (defaultView) {
|
} else {
|
||||||
goTo(defaultView);
|
goTo(defaultView);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
$ionicPlatform.on('resume', function() {
|
$ionicPlatform.on('resume', function() {
|
||||||
checkAndApplyLock();
|
checkAndApplyLock(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
$ionicPlatform.on('menubutton', function() {
|
$ionicPlatform.on('menubutton', function() {
|
||||||
|
|
@ -1284,10 +1287,7 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
|
||||||
historyRoot: true
|
historyRoot: true
|
||||||
});
|
});
|
||||||
|
|
||||||
if (platformInfo.isCordova)
|
checkAndApplyLock();
|
||||||
startupService.ready();
|
|
||||||
|
|
||||||
checkAndApplyLock('tabs.home');
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
// After everything have been loaded, initialize handler URL
|
// After everything have been loaded, initialize handler URL
|
||||||
|
|
|
||||||
|
|
@ -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,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