adding to pin modal to resume
This commit is contained in:
parent
9bb12e91f5
commit
282f549ed0
4 changed files with 310 additions and 12 deletions
224
src/js/controllers/modals/pin.js
Normal file
224
src/js/controllers/modals/pin.js
Normal file
|
|
@ -0,0 +1,224 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.controllers').controller('pinController', function($state, $interval, $stateParams, $ionicHistory, $timeout, $scope, $log, configService, appConfigService, applicationService) {
|
||||
var ATTEMPT_LIMIT = 3;
|
||||
var ATTEMPT_LOCK_OUT_TIME = 5 * 60;
|
||||
var currentPin;
|
||||
|
||||
$scope.$on("$ionicView.beforeEnter", function(event) {
|
||||
currentPin = $scope.confirmPin = '';
|
||||
$scope.action = $stateParams.action;
|
||||
$scope.match = $scope.error = $scope.disableButtons = false;
|
||||
$scope.currentAttempts = 0;
|
||||
$scope.appName = appConfigService.name;
|
||||
});
|
||||
|
||||
$scope.$on("$ionicView.enter", function(event) {
|
||||
configService.whenAvailable(function(config) {
|
||||
if (!config.lock) return;
|
||||
$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 getSavedMethod() {
|
||||
var config = configService.getSync();
|
||||
if (config.lock) return config.lock.method;
|
||||
return 'none';
|
||||
};
|
||||
|
||||
function checkAttempts() {
|
||||
$scope.currentAttempts += 1;
|
||||
$log.debug('Attempts to unlock:', $scope.currentAttempts);
|
||||
if ($scope.currentAttempts === ATTEMPT_LIMIT) {
|
||||
$scope.currentAttempts = 0;
|
||||
var bannedUntil = Math.floor(Date.now() / 1000) + ATTEMPT_LOCK_OUT_TIME;
|
||||
saveFailedAttempt(bannedUntil);
|
||||
}
|
||||
};
|
||||
|
||||
function lockTimeControl(bannedUntil) {
|
||||
setExpirationTime();
|
||||
|
||||
var countDown = $interval(function() {
|
||||
setExpirationTime();
|
||||
}, 1000);
|
||||
|
||||
function setExpirationTime() {
|
||||
var now = Math.floor(Date.now() / 1000);
|
||||
if (now > bannedUntil) {
|
||||
if (countDown) reset();
|
||||
} else {
|
||||
$scope.disableButtons = true;
|
||||
var totalSecs = bannedUntil - 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;
|
||||
currentPin = $scope.confirmPin = '';
|
||||
$interval.cancel(countDown);
|
||||
$timeout(function() {
|
||||
$scope.$apply();
|
||||
});
|
||||
return;
|
||||
};
|
||||
};
|
||||
|
||||
$scope.getFilledClass = function(limit) {
|
||||
return currentPin && currentPin.length >= limit ? 'filled-' + $scope.appName : null;
|
||||
};
|
||||
|
||||
$scope.delete = function() {
|
||||
if ($scope.disableButtons) return;
|
||||
if (currentPin.length > 0) {
|
||||
currentPin = currentPin.substring(0, currentPin.length - 1);
|
||||
$scope.error = false;
|
||||
$scope.updatePin();
|
||||
}
|
||||
};
|
||||
|
||||
$scope.isComplete = function() {
|
||||
if (currentPin.length < 4) return false;
|
||||
else return true;
|
||||
};
|
||||
|
||||
$scope.updatePin = function(value) {
|
||||
if ($scope.disableButtons) return;
|
||||
$scope.error = false;
|
||||
if (value && !$scope.isComplete()) {
|
||||
currentPin = currentPin + value;
|
||||
$timeout(function() {
|
||||
$scope.$apply();
|
||||
});
|
||||
}
|
||||
$scope.save();
|
||||
};
|
||||
|
||||
function isMatch(pin) {
|
||||
var config = configService.getSync();
|
||||
return config.lock.value == pin;
|
||||
};
|
||||
|
||||
$scope.save = function() {
|
||||
if (!$scope.isComplete()) return;
|
||||
var savedMethod = getSavedMethod();
|
||||
|
||||
switch ($scope.action) {
|
||||
case 'setup':
|
||||
applyAndCheckPin();
|
||||
break;
|
||||
case 'disable':
|
||||
if (isMatch(currentPin)) {
|
||||
deletePin();
|
||||
} else {
|
||||
showError();
|
||||
checkAttempts();
|
||||
}
|
||||
break;
|
||||
case 'check':
|
||||
if (isMatch(currentPin)) {
|
||||
console.log("##################################### CHECKING");
|
||||
applicationService.successfullUnlocked = true;
|
||||
$scope.pinModal.hide();
|
||||
return;
|
||||
}
|
||||
showError();
|
||||
checkAttempts();
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
function showError() {
|
||||
$timeout(function() {
|
||||
$scope.confirmPin = currentPin = '';
|
||||
$scope.error = true;
|
||||
}, 200);
|
||||
|
||||
$timeout(function() {
|
||||
$scope.$apply();
|
||||
});
|
||||
};
|
||||
|
||||
function applyAndCheckPin() {
|
||||
if (!$scope.confirmPin) {
|
||||
$timeout(function() {
|
||||
$scope.confirmPin = currentPin;
|
||||
currentPin = '';
|
||||
}, 200);
|
||||
} else {
|
||||
if ($scope.confirmPin == currentPin)
|
||||
savePin($scope.confirmPin);
|
||||
else {
|
||||
$scope.confirmPin = currentPin = '';
|
||||
$scope.error = true;
|
||||
}
|
||||
}
|
||||
$timeout(function() {
|
||||
$scope.$apply();
|
||||
});
|
||||
};
|
||||
|
||||
function deletePin() {
|
||||
var opts = {
|
||||
lock: {
|
||||
method: 'none',
|
||||
value: null,
|
||||
bannedUntil: null,
|
||||
}
|
||||
};
|
||||
|
||||
configService.set(opts, function(err) {
|
||||
if (err) $log.debug(err);
|
||||
$scope.close();
|
||||
});
|
||||
};
|
||||
|
||||
function savePin(value) {
|
||||
var opts = {
|
||||
lock: {
|
||||
method: 'pin',
|
||||
value: value,
|
||||
bannedUntil: null,
|
||||
}
|
||||
};
|
||||
|
||||
configService.set(opts, function(err) {
|
||||
if (err) $log.debug(err);
|
||||
$scope.close();
|
||||
});
|
||||
};
|
||||
|
||||
function saveFailedAttempt(bannedUntil) {
|
||||
var opts = {
|
||||
lock: {
|
||||
bannedUntil: bannedUntil,
|
||||
}
|
||||
};
|
||||
|
||||
configService.set(opts, function(err) {
|
||||
if (err) $log.debug(err);
|
||||
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);
|
||||
};
|
||||
});
|
||||
|
|
@ -1245,6 +1245,7 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
|
|||
|
||||
$ionicPlatform.on('resume', function() {
|
||||
applicationService.successfullUnlocked = false;
|
||||
applicationService.pinModal();
|
||||
// checkAndApplyLock(true);
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ angular.module('copayApp.services').factory('glideraService', function($http, $l
|
|||
* Development: 'testnet'
|
||||
* Production: 'livenet'
|
||||
*/
|
||||
credentials.NETWORK = 'livenet';
|
||||
credentials.NETWORK = 'testnet';
|
||||
//credentials.NETWORK = 'testnet';
|
||||
|
||||
if (credentials.NETWORK == 'testnet') {
|
||||
|
|
@ -127,7 +127,7 @@ angular.module('copayApp.services').factory('glideraService', function($http, $l
|
|||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
var _get = function(endpoint, token) {
|
||||
|
|
@ -365,7 +365,7 @@ angular.module('copayApp.services').factory('glideraService', function($http, $l
|
|||
|
||||
getPermissions(accessToken, credentials.NETWORK, true, function(err, permissions) {
|
||||
if (err) return cb(err);
|
||||
|
||||
|
||||
storageService.getGlideraStatus(credentials.NETWORK, function(err, status) {
|
||||
if (lodash.isString(status)) status = JSON.parse(status);
|
||||
storageService.getGlideraTxs(credentials.NETWORK, function(err, txs) {
|
||||
|
|
@ -386,17 +386,21 @@ angular.module('copayApp.services').factory('glideraService', function($http, $l
|
|||
root.updateStatus = function(data) {
|
||||
storageService.getGlideraToken(credentials.NETWORK, function(err, accessToken) {
|
||||
if (err) return;
|
||||
|
||||
|
||||
getPermissions(accessToken, credentials.NETWORK, false, function(err, permissions) {
|
||||
if (err) return;
|
||||
data.permissions = permissions;
|
||||
|
||||
data.price = {};
|
||||
root.buyPrice(accessToken, {qty: 1}, function(err, buy) {
|
||||
root.buyPrice(accessToken, {
|
||||
qty: 1
|
||||
}, function(err, buy) {
|
||||
if (err) return;
|
||||
data.price['buy'] = buy.price;
|
||||
});
|
||||
root.sellPrice(accessToken, {qty: 1}, function(err, sell) {
|
||||
root.sellPrice(accessToken, {
|
||||
qty: 1
|
||||
}, function(err, sell) {
|
||||
if (err) return;
|
||||
data.price['sell'] = sell.price;
|
||||
});
|
||||
|
|
@ -405,12 +409,12 @@ angular.module('copayApp.services').factory('glideraService', function($http, $l
|
|||
if (err) return;
|
||||
data.status = status;
|
||||
storageService.setGlideraStatus(credentials.NETWORK, JSON.stringify(status), function() {});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
root.getLimits(accessToken, function(err, limits) {
|
||||
data.limits = limits;
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
if (permissions.transaction_history) {
|
||||
root.getTransactions(accessToken, function(err, txs) {
|
||||
if (err) return;
|
||||
|
|
@ -431,8 +435,8 @@ angular.module('copayApp.services').factory('glideraService', function($http, $l
|
|||
data.personalInfo = info;
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
var register = function() {
|
||||
|
|
|
|||
69
www/views/modals/pin.html
Normal file
69
www/views/modals/pin.html
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
<ion-modal-view id="pin" ng-controller="pinController">
|
||||
<div class="content">
|
||||
<div class="block-text row">
|
||||
<div class="message" ng-if="!confirmPin && !error" translate>Please enter your PIN</div>
|
||||
<div class="message" ng-if="confirmPin && !error" translate>Confirm your PIN</div>
|
||||
<div class="message error" ng-if="error">
|
||||
<div ng-if="!expires" translate>Incorrect PIN, try again.</div>
|
||||
<time ng-if="expires" translate>Try again in {{expires}}</time>
|
||||
</div>
|
||||
</div>
|
||||
<div class="app-icon">
|
||||
<i class="icon big-icon-svg">
|
||||
<div class="bg"></div>
|
||||
</i>
|
||||
</div>
|
||||
<div class="block-code">
|
||||
<div class="row">
|
||||
<div class="col circle-{{appName}}" ng-class="getFilledClass(1)"></div>
|
||||
<div class="col circle-{{appName}}" ng-class="getFilledClass(2)"></div>
|
||||
<div class="col circle-{{appName}}" ng-class="getFilledClass(3)"></div>
|
||||
<div class="col circle-{{appName}}" ng-class="getFilledClass(4)"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="block-buttons">
|
||||
<div class="row">
|
||||
<div class="col" ng-click="updatePin('1')">
|
||||
<div class="keyboard">1</div>
|
||||
</div>
|
||||
<div class="col" ng-click="updatePin('2')">
|
||||
<div class="keyboard">2</div>
|
||||
</div>
|
||||
<div class="col" ng-click="updatePin('3')">
|
||||
<div class="keyboard">3</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col" ng-click="updatePin('4')">
|
||||
<div class="keyboard">4</div>
|
||||
</div>
|
||||
<div class="col" ng-click="updatePin('5')">
|
||||
<div class="keyboard">5</div>
|
||||
</div>
|
||||
<div class="col" ng-click="updatePin('6')">
|
||||
<div class="keyboard">6</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col" ng-click="updatePin('7')">
|
||||
<div class="keyboard">7</div>
|
||||
</div>
|
||||
<div class="col" ng-click="updatePin('8')">
|
||||
<div class="keyboard">8</div>
|
||||
</div>
|
||||
<div class="col" ng-click="updatePin('9')">
|
||||
<div class="keyboard">9</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col"></div>
|
||||
<div class="col" ng-click="updatePin('0')">
|
||||
<div class="">0</div>
|
||||
</div>
|
||||
<div class="col" ng-click="delete()">
|
||||
<div class="keyboard icon ion-arrow-left-a"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</ion-modal-view>
|
||||
Loading…
Add table
Add a link
Reference in a new issue