fix lock by attempts reached

This commit is contained in:
JDonadio 2017-04-22 12:54:25 -03:00
commit cc3b2d6147

View file

@ -38,13 +38,12 @@ angular.module('copayApp.controllers').controller('pinController', function($sta
$log.debug('Attempts to unlock:', $scope.currentAttempts); $log.debug('Attempts to unlock:', $scope.currentAttempts);
if ($scope.currentAttempts === ATTEMPT_LIMIT) { if ($scope.currentAttempts === ATTEMPT_LIMIT) {
$scope.currentAttempts = 0; $scope.currentAttempts = 0;
var limitTime = Math.floor(Date.now() / 1000) + ATTEMPT_LOCK_OUT_TIME; var bannedUntil = Math.floor(Date.now() / 1000) + ATTEMPT_LOCK_OUT_TIME;
saveFailedAttempt(limitTime); saveFailedAttempt(bannedUntil);
} }
}; };
function lockTimeControl(limitTime) { function lockTimeControl(bannedUntil) {
$scope.limitTimeExpired = false;
setExpirationTime(); setExpirationTime();
var countDown = $interval(function() { var countDown = $interval(function() {
@ -53,12 +52,11 @@ angular.module('copayApp.controllers').controller('pinController', function($sta
function setExpirationTime() { function setExpirationTime() {
var now = Math.floor(Date.now() / 1000); var now = Math.floor(Date.now() / 1000);
if (now > limitTime) { if (now > bannedUntil) {
$scope.limitTimeExpired = true;
if (countDown) reset(); if (countDown) reset();
} else { } else {
$scope.disableButtons = true; $scope.disableButtons = true;
var totalSecs = limitTime - now; var totalSecs = bannedUntil - now;
var m = Math.floor(totalSecs / 60); var m = Math.floor(totalSecs / 60);
var s = totalSecs % 60; var s = totalSecs % 60;
$scope.expires = ('0' + m).slice(-2) + ":" + ('0' + s).slice(-2); $scope.expires = ('0' + m).slice(-2) + ":" + ('0' + s).slice(-2);
@ -130,6 +128,7 @@ angular.module('copayApp.controllers').controller('pinController', function($sta
case 'check': case 'check':
if (isMatch(currentPin)) return $scope.close(); if (isMatch(currentPin)) return $scope.close();
showError(); showError();
checkAttempts();
break; break;
} }
}; };
@ -203,7 +202,7 @@ angular.module('copayApp.controllers').controller('pinController', function($sta
configService.set(opts, function(err) { configService.set(opts, function(err) {
if (err) $log.debug(err); if (err) $log.debug(err);
lockTimeControl(limitTime); lockTimeControl(bannedUntil);
}); });
}; };