Merge pull request #976 from cmgustavo/feature/01-timeout

Automatically logout wallet after 15 minutes of inactivity
This commit is contained in:
Yemel Jardi 2014-08-01 10:56:23 -03:00
commit ba504f147d
6 changed files with 24 additions and 3 deletions

View file

@ -27,6 +27,7 @@ var copayApp = window.copayApp = angular.module('copayApp', [
'angularMoment',
'mm.foundation',
'monospaced.qrcode',
'ngIdle',
'copayApp.filters',
'copayApp.services',
'copayApp.controllers',
@ -40,6 +41,7 @@ copayApp.config(function($sceDelegateProvider) {
]);
});
angular.module('copayApp.filters', []);
angular.module('copayApp.services', []);
angular.module('copayApp.controllers', []);

View file

@ -82,4 +82,15 @@ angular.module('copayApp.controllers').controller('SidebarController',
// Init socket handlers (with no wallet yet)
controllerUtils.setSocketHandlers();
if ($rootScope.wallet) {
$scope.$on('$idleStart', function(a) {
notification.warning('Session will be closed', 'Your session is about to expire due to inactivity');
});
$scope.$on('$idleTimeout', function() {
$scope.signout();
notification.warning('Session closed', 'Session closed because a long time of inactivity');
});
}
});

View file

@ -65,17 +65,22 @@ angular
//Setting HTML5 Location Mode
angular
.module('copayApp')
.config(function($locationProvider) {
.config(function($locationProvider, $idleProvider) {
$locationProvider
.html5Mode(false)
.hashPrefix('!');
// IDLE timeout
$idleProvider.idleDuration(15 * 60); // in seconds
$idleProvider.warningDuration(10); // in seconds
})
.run(function($rootScope, $location) {
.run(function($rootScope, $location, $idle) {
$idle.watch();
$rootScope.$on('$routeChangeStart', function(event, next, current) {
if (!util.supports.data) {
$location.path('unsupported');
} else {
if ((!$rootScope.wallet || !$rootScope.wallet.id) && next.validate) {
$idle.unwatch();
$location.path('/');
}
if ($rootScope.wallet && !$rootScope.wallet.isReady()) {