attempts limit - remaining time
This commit is contained in:
parent
5c2b067c87
commit
c29af5f658
4 changed files with 101 additions and 12 deletions
|
|
@ -1,22 +1,93 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
angular.module('copayApp.controllers').controller('pinController', function($state, $stateParams, $ionicHistory, $timeout, $scope, $log, configService, appConfigService) {
|
angular.module('copayApp.controllers').controller('pinController', function($state, $interval, $stateParams, $ionicHistory, $timeout, $scope, $log, configService, appConfigService) {
|
||||||
var PIN = 'pin';
|
var PIN = 'pin';
|
||||||
|
var ATTEPMPTS_LIMIT = 3;
|
||||||
|
|
||||||
$scope.$on("$ionicView.beforeEnter", function(event) {
|
$scope.$on("$ionicView.beforeEnter", function(event) {
|
||||||
$scope.currentPin = $scope.confirmPin = '';
|
$scope.currentPin = $scope.confirmPin = '';
|
||||||
$scope.fromSettings = $stateParams.fromSettings == 'true' ? true : false;
|
$scope.fromSettings = $stateParams.fromSettings == 'true' ? true : false;
|
||||||
$scope.locking = $stateParams.locking == 'true' ? true : false;
|
$scope.locking = $stateParams.locking == 'true' ? true : false;
|
||||||
$scope.match = false;
|
$scope.match = $scope.error = $scope.disableButtons = false;
|
||||||
$scope.error = false;
|
$scope.currentAttempts = 0;
|
||||||
$scope.appName = appConfigService.name;
|
$scope.appName = appConfigService.name;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$scope.$on("$ionicView.enter", function(event) {
|
||||||
|
configService.whenAvailable(function(config) {
|
||||||
|
$scope.bannedUntil = config.lock.bannedUntil || null;
|
||||||
|
if ($scope.bannedUntil) {
|
||||||
|
var now = Math.floor(Date.now() / 1000);
|
||||||
|
if (now < $scope.bannedUntil) {
|
||||||
|
$scope.error = $scope.disableButtons = true;
|
||||||
|
lockTimeControl($scope.bannedUntil);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
function checkAttempts() {
|
||||||
|
$scope.currentAttempts += 1;
|
||||||
|
$log.debug('Attempts to unlock:', $scope.currentAttempts);
|
||||||
|
if ($scope.currentAttempts === 3) {
|
||||||
|
$scope.currentAttempts = 0;
|
||||||
|
var limitTime = Math.floor(Date.now() / 1000) + 5 * 60;
|
||||||
|
var config = configService.getSync();
|
||||||
|
var opts = {
|
||||||
|
lock: {
|
||||||
|
method: PIN,
|
||||||
|
value: config.lock.value,
|
||||||
|
bannedUntil: limitTime,
|
||||||
|
attempts: config.lock.attempts + 1,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
configService.set(opts, function(err) {
|
||||||
|
if (err) $log.debug(err);
|
||||||
|
lockTimeControl(limitTime);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
function lockTimeControl(limitTime) {
|
||||||
|
$scope.limitTimeExpired = false;
|
||||||
|
setExpirationTime();
|
||||||
|
|
||||||
|
var countDown = $interval(function() {
|
||||||
|
setExpirationTime();
|
||||||
|
}, 1000);
|
||||||
|
|
||||||
|
function setExpirationTime() {
|
||||||
|
var now = Math.floor(Date.now() / 1000);
|
||||||
|
if (now > limitTime) {
|
||||||
|
$scope.limitTimeExpired = true;
|
||||||
|
if (countDown) reset();
|
||||||
|
} else {
|
||||||
|
$scope.disableButtons = true;
|
||||||
|
var totalSecs = limitTime - now;
|
||||||
|
var m = Math.floor(totalSecs / 60);
|
||||||
|
var s = totalSecs % 60;
|
||||||
|
$scope.expires = ('0' + m).slice(-2) + ":" + ('0' + s).slice(-2);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
function reset() {
|
||||||
|
$scope.expires = $scope.error = $scope.disableButtons = null;
|
||||||
|
$scope.currentPin = $scope.confirmPin = '';
|
||||||
|
$interval.cancel(countDown);
|
||||||
|
$timeout(function() {
|
||||||
|
$scope.$apply();
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
$scope.getFilledClass = function(limit) {
|
$scope.getFilledClass = function(limit) {
|
||||||
return $scope.currentPin.length >= limit ? 'filled-' + $scope.appName : null;
|
return $scope.currentPin.length >= limit ? 'filled-' + $scope.appName : null;
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.delete = function() {
|
$scope.delete = function() {
|
||||||
|
if ($scope.disableButtons) return;
|
||||||
if ($scope.currentPin.length > 0) {
|
if ($scope.currentPin.length > 0) {
|
||||||
$scope.currentPin = $scope.currentPin.substring(0, $scope.currentPin.length - 1);
|
$scope.currentPin = $scope.currentPin.substring(0, $scope.currentPin.length - 1);
|
||||||
$scope.error = false;
|
$scope.error = false;
|
||||||
|
|
@ -30,6 +101,7 @@ angular.module('copayApp.controllers').controller('pinController', function($sta
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.updatePin = function(value) {
|
$scope.updatePin = function(value) {
|
||||||
|
if ($scope.disableButtons) return;
|
||||||
$scope.error = false;
|
$scope.error = false;
|
||||||
if (value && !$scope.isComplete()) {
|
if (value && !$scope.isComplete()) {
|
||||||
$scope.currentPin = $scope.currentPin + value;
|
$scope.currentPin = $scope.currentPin + value;
|
||||||
|
|
@ -46,11 +118,17 @@ angular.module('copayApp.controllers').controller('pinController', function($sta
|
||||||
$scope.match = config.lock && config.lock.method == PIN && config.lock.value == $scope.currentPin ? true : false;
|
$scope.match = config.lock && config.lock.method == PIN && config.lock.value == $scope.currentPin ? true : false;
|
||||||
if (!$scope.locking) {
|
if (!$scope.locking) {
|
||||||
if ($scope.match) {
|
if ($scope.match) {
|
||||||
$scope.fromSettings ? saveSettings() : $scope.close(150);
|
if ($scope.fromSettings) saveSettings();
|
||||||
$scope.error = false;
|
else {
|
||||||
|
saveSettings(PIN, $scope.currentPin);
|
||||||
|
$scope.error = false;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
$scope.confirmPin = $scope.currentPin = '';
|
$timeout(function() {
|
||||||
$scope.error = true;
|
$scope.confirmPin = $scope.currentPin = '';
|
||||||
|
$scope.error = true;
|
||||||
|
}, 200);
|
||||||
|
checkAttempts();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
processCodes();
|
processCodes();
|
||||||
|
|
@ -59,8 +137,8 @@ angular.module('copayApp.controllers').controller('pinController', function($sta
|
||||||
|
|
||||||
function processCodes() {
|
function processCodes() {
|
||||||
if (!$scope.confirmPin) {
|
if (!$scope.confirmPin) {
|
||||||
$scope.confirmPin = $scope.currentPin;
|
|
||||||
$timeout(function() {
|
$timeout(function() {
|
||||||
|
$scope.confirmPin = $scope.currentPin;
|
||||||
$scope.currentPin = '';
|
$scope.currentPin = '';
|
||||||
}, 200);
|
}, 200);
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -77,10 +155,13 @@ angular.module('copayApp.controllers').controller('pinController', function($sta
|
||||||
};
|
};
|
||||||
|
|
||||||
function saveSettings(method, value) {
|
function saveSettings(method, value) {
|
||||||
|
var config = configService.getSync();
|
||||||
var opts = {
|
var opts = {
|
||||||
lock: {
|
lock: {
|
||||||
method: method || '',
|
method: method || '',
|
||||||
value: value || '',
|
value: value || '',
|
||||||
|
bannedUntil: null,
|
||||||
|
attempts: config.lock.attempts + 1,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -56,6 +56,8 @@ angular.module('copayApp.services').factory('configService', function(storageSer
|
||||||
lock: {
|
lock: {
|
||||||
method: '',
|
method: '',
|
||||||
value: '',
|
value: '',
|
||||||
|
bannedUntil: null,
|
||||||
|
attempts: null,
|
||||||
},
|
},
|
||||||
|
|
||||||
// External services
|
// External services
|
||||||
|
|
|
||||||
|
|
@ -25,9 +25,11 @@
|
||||||
.block-text {
|
.block-text {
|
||||||
align-items: center;
|
align-items: center;
|
||||||
background-color: #F1F1F1;
|
background-color: #F1F1F1;
|
||||||
text-align: center;
|
|
||||||
height: 30%;
|
height: 30%;
|
||||||
border-bottom: 1px solid #c5c5c5;
|
border-bottom: 1px solid #c5c5c5;
|
||||||
|
.message {
|
||||||
|
margin: auto;
|
||||||
|
}
|
||||||
span {
|
span {
|
||||||
width: 60%;
|
width: 60%;
|
||||||
margin: 10% auto;
|
margin: 10% auto;
|
||||||
|
|
@ -88,5 +90,6 @@
|
||||||
}
|
}
|
||||||
.error {
|
.error {
|
||||||
color: #f13333;
|
color: #f13333;
|
||||||
|
max-width: 70%;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,9 +5,12 @@
|
||||||
</ion-nav-bar>
|
</ion-nav-bar>
|
||||||
<div class="content">
|
<div class="content">
|
||||||
<div class="block-text row">
|
<div class="block-text row">
|
||||||
<span translate ng-if="!confirmPin && !error">Please enter your mobile unlock code</span>
|
<div class="message" ng-if="!confirmPin && !error" translate>Please enter your unlock PIN</div>
|
||||||
<span translate ng-if="confirmPin && !error">Confirm your mobile unlock code</span>
|
<div class="message" ng-if="confirmPin && !error" translate>Confirm your unlock PIN</div>
|
||||||
<span translate ng-if="error" class="error">Incorrect code, try again.</span>
|
<div class="message error" ng-if="error">
|
||||||
|
<div ng-if="!expires" translate>Incorrect PIN, try again.</div>
|
||||||
|
<time ng-if="expires" translate>You have incorrectly typed your PIN. Try again in {{expires}}</time>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="app-icon">
|
<div class="app-icon">
|
||||||
<i class="icon big-icon-svg">
|
<i class="icon big-icon-svg">
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue