diff --git a/www/i18n/locale-fr-FR.json b/www/i18n/locale-fr-FR.json index 30288787de3f0660a2be6aa792886de009071adc..1530d237989065d9c5e1336d92471fff7321b36c 100644 --- a/www/i18n/locale-fr-FR.json +++ b/www/i18n/locale-fr-FR.json @@ -141,7 +141,7 @@ "ALWAYS": "A la fin de la session" }, "REMEMBER_ME": "Se souvenir de moi ?", - "REMEMBER_ME_HELP": "Permet de rester identifié, entre les sessions de navigation<br/>(Seule la clé publique du compte sera conservée localement)", + "REMEMBER_ME_HELP": "Permet de rester identifié d'une session à l'autre, en conservant localement la clé publique.", "PLUGINS_SETTINGS": "Extensions", "BTN_RESET": "Restaurer les valeurs par défaut", "EXPERT_MODE": "Activer le mode expert", diff --git a/www/js/controllers/app-controllers.js b/www/js/controllers/app-controllers.js index e29ca99b25b2b8e0d1fc5cb7768ebd6ecde7a9ce..9dcddf7029d9ff19fcd6d9524e237de41d0b8935 100644 --- a/www/js/controllers/app-controllers.js +++ b/www/js/controllers/app-controllers.js @@ -89,9 +89,6 @@ function AppController($scope, $rootScope, $state, $ionicSideMenuDelegate, $q, $ ) { 'ngInject'; - // Initialize the super class and extend it. - angular.extend(this, $controller('AuthIdleCtrl', {$scope: $scope})); - $scope.search = {}; $scope.login = csWallet.isLogin(); $scope.motion = UIUtils.motion.default; diff --git a/www/js/controllers/login-controllers.js b/www/js/controllers/login-controllers.js index b7517e0541cf7ab2c53e767269665d553796e138..b593a90b445674d312a8ffa722103cc11a022f6d 100644 --- a/www/js/controllers/login-controllers.js +++ b/www/js/controllers/login-controllers.js @@ -3,8 +3,6 @@ angular.module('cesium.login.controllers', ['cesium.services']) .controller('LoginModalCtrl', LoginModalController) - .controller('AuthIdleCtrl', AuthIdleController) - ; function LoginModalController($scope, $timeout, $q, $ionicPopover, CryptoUtils, UIUtils, Modals, csSettings, Device, parameters) { @@ -330,133 +328,3 @@ function LoginModalController($scope, $timeout, $q, $ionicPopover, CryptoUtils, //$scope.form = {$valid:true}; }, 900);*/ } - - -/** - * Manage automatic authentication reset - * @param $scope - * @param $ionicHistory - * @param $state - * @param $q - * @param Idle - * @param UIUtils - * @param $ionicLoading - * @param csWallet - * @param csSettings - * @constructor - */ -function AuthIdleController($scope, $ionicHistory, $state, $q, Idle, UIUtils, $ionicLoading, csWallet, csSettings) { - 'ngInject'; - - var enableAuthIdle = false; - - function checkAuth(isAuth) { - isAuth = angular.isDefined(isAuth) ? isAuth : csWallet.isAuth(); - var enable = csSettings.data.keepAuthIdle > 0 && csSettings.data.keepAuthIdle != 9999 && isAuth; - var changed = (enableAuthIdle != enable); - - // need start/top watching - if (changed) { - // start idle - if (enable) { - console.debug("[idle] Start auth idle (delay: {0}s)".format(csSettings.data.keepAuthIdle)); - Idle.setIdle(csSettings.data.keepAuthIdle); - Idle.watch(); - } - // stop idle, if need - else if (enableAuthIdle){ - console.debug("[app] Stop auth idle"); - Idle.unwatch(); - } - enableAuthIdle = enable; - } - - // if idle time changed: apply it - else if (enable && Idle.getIdle() !== csSettings.data.keepAuthIdle) { - console.debug("[idle] Updating auth idle (delay: {0}s)".format(csSettings.data.keepAuthIdle)); - Idle.setIdle(csSettings.data.keepAuthIdle); - } - } - - csSettings.api.data.on.changed($scope, checkAuth); - - // add listeners on wallet events - csWallet.api.data.on.login($scope, function(walletData, deferred) { - checkAuth(); - return (deferred && deferred.resolve()) || $q.when(); - }); - csWallet.api.data.on.auth($scope, function(walletData, deferred) { - checkAuth(true); - return (deferred && deferred.resolve()) || $q.when(); - }); - csWallet.api.data.on.unauth($scope, function() { - checkAuth(false); - }); - csWallet.api.data.on.logout($scope, function() { - checkAuth(false); - }); - - $scope.$on('IdleStart', function() { - if (!csSettings.data.rememberMe) { - $ionicLoading.hide(); // close previous toast - $ionicLoading.show({ - template: "<div idle-countdown=\"countdown\" ng-init=\"countdown=5\">{{'LOGIN.AUTO_LOGOUT.IDLE_WARNING'|translate:{countdown:countdown} }}</div>" - }); - } - }); - - $scope.$on('IdleEnd', function() { - if (!csSettings.data.rememberMe) { - $ionicLoading.hide(); - } - }); - - $scope.$on('IdleTimeout', function() { - // Keep user login, but remove auth - if (csSettings.data.rememberMe) { - if (!csWallet.isAuth()) return; - - return csWallet.unauth() - .then(function() { - $ionicHistory.clearCache(); - }) - .catch(UIUtils.onError()); - } - - // Do not keep user login, so = logout - else { - return csWallet.logout() - .then(function () { - $ionicHistory.clearCache(); - if ($state.current.data.auth === true) { - $ionicHistory.clearHistory(); - return $scope.showHome(); - } - }) - .then(function () { - $ionicLoading.hide(); - return UIUtils.alert.confirm('LOGIN.AUTO_LOGOUT.MESSAGE', - 'LOGIN.AUTO_LOGOUT.TITLE', { - cancelText: 'COMMON.BTN_CLOSE', - okText: 'COMMON.BTN_LOGIN' - }); - }) - .then(function (relogin) { - if (!relogin) return; - return csWallet.login(options) - .then(function(){ - return $state.go($state.current.name, $state.params, {reload: true}); - }) - .then(UIUtils.loading.hide); - }) - .catch(UIUtils.onError()); - } - }); - - - // Catch windows close event - window.addEventListener("beforeunload", function(e){ - console.log("[auth idle] Getting event beforeunload"); - return "Are you sure ?"; - }, false); -} diff --git a/www/js/services/wallet-services.js b/www/js/services/wallet-services.js index 2fb4ff301ff2570526e07be68598d8de7da21ffa..1a34318a1e5fb87191cf5b43c585c41fa24faa61 100644 --- a/www/js/services/wallet-services.js +++ b/www/js/services/wallet-services.js @@ -3,7 +3,8 @@ angular.module('cesium.wallet.services', ['ngApi', 'ngFileSaver', 'cesium.bma.se 'cesium.settings.services']) -.factory('csWallet', function($q, $rootScope, $timeout, $translate, $filter, Api, localStorage, sessionStorage, Modals, +.factory('csWallet', function($q, $rootScope, $timeout, $translate, $filter, $ionicHistory, + Api, Idle, localStorage, sessionStorage, Modals, CryptoUtils, BMA, csConfig, csSettings, FileSaver, Blob, csWot, csTx, csCurrency) { 'ngInject'; @@ -26,7 +27,7 @@ angular.module('cesium.wallet.services', ['ngApi', 'ngFileSaver', 'cesium.bma.se listeners, started, startPromise, - authPromise, + enableAuthIdle = false, api = new Api(this, 'csWallet-' + id), resetData = function(init) { @@ -109,7 +110,9 @@ angular.module('cesium.wallet.services', ['ngApi', 'ngFileSaver', 'cesium.bma.se if (!needLogin && !needAuth) { return $q.when(data); } + var keepAuth = csSettings.data.keepAuthIdle > 0; + var authData; return Modals.showLogin(options) .then(function(res){ if (!res || !res.pubkey || @@ -118,11 +121,14 @@ angular.module('cesium.wallet.services', ['ngApi', 'ngFileSaver', 'cesium.bma.se throw 'CANCELLED'; } // invalid data + authData = res; data.pubkey = res.pubkey; - data.keypair = res.keypair || { - signSk: null, - signPk: null - }; + if (csSettings.data.keepAuthIdle > 0) { + data.keypair = res.keypair || { + signSk: null, + signPk: null + }; + } // Call extend api if (needLogin) { @@ -138,12 +144,18 @@ angular.module('cesium.wallet.services', ['ngApi', 'ngFileSaver', 'cesium.bma.se // Send auth event (if need) if (needAuth) { api.data.raise.auth(); + + // Check if need to start/stop auth idle + checkAuthIdle(true); } - return data; + + return keepAuth ? data : angular.merge({}, data, authData); }); }, logout = function() { + var wasAuth = isAuth(); + return $q(function(resolve, reject) { resetData(); // will reset keypair @@ -152,6 +164,14 @@ angular.module('cesium.wallet.services', ['ngApi', 'ngFileSaver', 'cesium.bma.se // Send logout event api.data.raise.logout(); + if (wasAuth) { + api.data.raise.unauth(); + } + + checkAuthIdle(false); + + $ionicHistory.clearCache(); + resolve(); }); }, @@ -187,6 +207,10 @@ angular.module('cesium.wallet.services', ['ngApi', 'ngFileSaver', 'cesium.bma.se // Send unauth event api.data.raise.unauth(); + checkAuthIdle(false); + + $ionicHistory.clearCache(); + resolve(); }); }, @@ -1458,16 +1482,46 @@ angular.module('cesium.wallet.services', ['ngApi', 'ngFileSaver', 'cesium.bma.se resolve(); } }); - } - ; + }, + + checkAuthIdle = function(isAuth) { + isAuth = angular.isDefined(isAuth) ? isAuth : isAuth(); + var enable = isAuth && csSettings.data.keepAuthIdle > 0 && csSettings.data.keepAuthIdle != csSettings.constants.KEEP_AUTH_IDLE_SESSION; + var changed = (enableAuthIdle != enable); + + // need start/top watching + if (changed) { + // start idle + if (enable) { + console.debug("[wallet] Start idle (delay: {0}s)".format(csSettings.data.keepAuthIdle)); + Idle.setIdle(csSettings.data.keepAuthIdle); + Idle.watch(); + } + // stop idle, if need + else if (enableAuthIdle){ + console.debug("[wallet] Stop idle"); + Idle.unwatch(); + } + enableAuthIdle = enable; + } + + // if idle time changed: apply it + else if (enable && Idle.getIdle() !== csSettings.data.keepAuthIdle) { + console.debug("[idle] Updating auth idle (delay: {0}s)".format(csSettings.data.keepAuthIdle)); + Idle.setIdle(csSettings.data.keepAuthIdle); + } + }; function addListeners() { listeners = [ // Listen if settings changed csSettings.api.data.on.changed($rootScope, store, this), + csSettings.api.data.on.changed($rootScope, checkAuthIdle, this), // Listen if node changed BMA.api.node.on.restart($rootScope, restart, this) ]; + + $rootScope.$on('IdleStart', unauth); } function removeListeners() { diff --git a/www/plugins/es/js/controllers/message-controllers.js b/www/plugins/es/js/controllers/message-controllers.js index 3099ab673afc6d7b53c57c7897a33e11e7d0ad7f..fb86b85e19e188c1788f2b45c78113641fb0022c 100644 --- a/www/plugins/es/js/controllers/message-controllers.js +++ b/www/plugins/es/js/controllers/message-controllers.js @@ -60,7 +60,7 @@ angular.module('cesium.es.message.controllers', ['cesium.es.services']) ; -function ESMessageListController($scope, $rootScope, $state, $translate, $ionicHistory, $ionicPopover, +function ESMessageListController($scope, $state, $translate, $ionicHistory, $ionicPopover, esModals, UIUtils, esMessage) { 'ngInject'; @@ -96,7 +96,7 @@ function ESMessageListController($scope, $rootScope, $state, $translate, $ionicH options.type = $scope.type; $scope.loading = true; - return esMessage.load($rootScope.walletData.keypair, options) + return esMessage.load(options) .then(function(messages) { $scope.messages = messages; diff --git a/www/plugins/es/js/services/http-services.js b/www/plugins/es/js/services/http-services.js index 22237ebe121b861de5dacd3d5d29d97f631b68ac..bc23127a8754a5aefd91ca63e9067362065a9391 100644 --- a/www/plugins/es/js/services/http-services.js +++ b/www/plugins/es/js/services/http-services.js @@ -211,10 +211,10 @@ angular.module('cesium.es.http.services', ['ngResource', 'ngApi', 'cesium.servic }); } - function postRecord(path) { + function postRecord(path, walletData) { var postRequest = that.post(path); return function(record, params) { - return csWallet.auth() + return (!walletData ? csWallet.auth() : $q.when(walletData)) .then(function(walletData) { if (!record.time) { record.time = that.date.now(); @@ -246,9 +246,9 @@ angular.module('cesium.es.http.services', ['ngResource', 'ngApi', 'cesium.servic }; } - function removeRecord(index, type) { + function removeRecord(index, type, walletData) { return function(id) { - return csWallet.auth() + return (walletData ? csWallet.auth() : $q.when(walletData)) .then(function(walletData) { var obj = { diff --git a/www/plugins/es/js/services/message-services.js b/www/plugins/es/js/services/message-services.js index 51a35cbec4a862d7e125c7919cff978873a17e04..eabf40975f44979442362dcf7548ad93d51467af 100644 --- a/www/plugins/es/js/services/message-services.js +++ b/www/plugins/es/js/services/message-services.js @@ -172,10 +172,8 @@ angular.module('cesium.es.message.services', ['ngResource', 'cesium.platform', } - function searchMessages(options) { - if (!csWallet.isLogin()) { - return $q.when([]); - } + function searchMessages(pubkey, options) { + pubkey = pubkey || csWallet.data.pubkey; options = options || {}; options.type = options.type || 'inbox'; @@ -192,10 +190,10 @@ angular.module('cesium.es.message.services', ['ngResource', 'cesium.platform', }; if (options.type == 'inbox') { - request.query = {bool: {filter: {term: {recipient: csWallet.data.pubkey}}}}; + request.query = {bool: {filter: {term: {recipient: pubkey}}}}; } else { - request.query = {bool: {filter: {term: {issuer: csWallet.data.pubkey}}}}; + request.query = {bool: {filter: {term: {issuer: pubkey}}}}; } return esHttp.post('/message/:type/_search')(request, {type: options.type}) @@ -217,22 +215,22 @@ angular.module('cesium.es.message.services', ['ngResource', 'cesium.platform', }); } - function loadMessages(keypair, options) { - if (!csWallet.isLogin()) { - return $q.when([]); - } - + function loadMessages(options) { options = options || {}; options.type = options.type || 'inbox'; options._source = fields.commons; options.summary = angular.isDefined(options.summary) ? options.summary : true; - // Get encrypted message (with common fields) - return searchMessages(options) + return csWallet.auth() + .then(function(walletData) { + + // Get encrypted message (with common fields) + return searchMessages(walletData.pubkey, options) - // Encrypt content - .then(function(messages) { - return decryptMessages(messages, keypair, options.summary); + // Encrypt content + .then(function(messages) { + return decryptMessages(messages, walletData.keypair, options.summary); + }); }) // Add avatar @@ -355,23 +353,26 @@ angular.module('cesium.es.message.services', ['ngResource', 'cesium.platform', function removeAllMessages(type) { type = type || 'inbox'; - // Get all message id - return searchMessages({type: type, from: 0, size: 1000, _source: false}) - .then(function(res) { - if (!res || !res.length) return; - - // Remove each messages - return $q.all(res.reduce(function(res, msg) { - return res.concat(esHttp.record.remove('message', type)(msg.id)); - }, [])); - }) - .then(function() { - // update message count - if (type == 'inbox') { - csWallet.data.messages = csWallet.data.messages || {}; - csWallet.data.messages.count = 0; - csWallet.data.messages.unreadCount = 0; - } + return csWallet.auth() + .then(function(walletData) { + // Get all message id + return searchMessages(walletData.pubkey, {type: type, from: 0, size: 1000, _source: false}) + .then(function (res) { + if (!res || !res.length) return; + + // Remove each messages + return $q.all(res.reduce(function (res, msg) { + return res.concat(esHttp.record.remove('message', type)(msg.id, walletData)); + }, [])); + }) + .then(function () { + // update message count + if (type == 'inbox') { + csWallet.data.messages = csWallet.data.messages || {}; + csWallet.data.messages.count = 0; + csWallet.data.messages.unreadCount = 0; + } + }); }); } @@ -385,7 +386,12 @@ angular.module('cesium.es.message.services', ['ngResource', 'cesium.platform', } message.read = true; - return CryptoUtils.sign(message.hash, csWallet.data.keypair) + return csWallet.getKeypair() + + // Prepare the read_signature to sent + .then(function(keypair) { + return CryptoUtils.sign(message.hash, keypair); + }) // Send read request .then(function(signature){ @@ -398,35 +404,44 @@ angular.module('cesium.es.message.services', ['ngResource', 'cesium.platform', csWallet.data.messages = csWallet.data.messages || {}; csWallet.data.messages.unreadCount = csWallet.data.messages.unreadCount ? csWallet.data.messages.unreadCount - 1 : 0; } - }) ; + }); } // Mark all messages as read function markAllMessageAsRead() { - // Get all messages hash - return searchMessages({type: 'inbox', from: 0, size: 1000, _source: ['hash', 'read_signature']}) - - .then(function(messages) { - if (!messages || !messages.length) return; - - // Keep only unread message - messages = _.filter(messages, {read:false}); - - // Remove messages - return $q.all(messages.reduce(function(res, message) { - return res.concat( - // Sign hash - CryptoUtils.sign(message.hash, csWallet.data.keypair) - // then send read request - .then(function(signature){ - return raw.postReadById(signature, {id:message.id}); - })); - }, [])); - }) - .then(function() { - // update message count - csWallet.data.messages = csWallet.data.messages || {}; - csWallet.data.messages.unreadCount = 0; + return csWallet.auth() + .then(function(walletData) { + + // Get all messages hash + return searchMessages(walletData.pubkey, { + type: 'inbox', + from: 0, + size: 1000, + _source: ['hash', 'read_signature'] + }) + + .then(function (messages) { + if (!messages || !messages.length) return; + + // Keep only unread message + messages = _.filter(messages, {read: false}); + + // Remove messages + return $q.all(messages.reduce(function (res, message) { + return res.concat( + // Sign hash + CryptoUtils.sign(message.hash, walletData.keypair) + // then send read request + .then(function (signature) { + return raw.postReadById(signature, {id: message.id}); + })); + }, [])); + }) + .then(function () { + // update message count + csWallet.data.messages = csWallet.data.messages || {}; + csWallet.data.messages.unreadCount = 0; + }); }); } diff --git a/www/plugins/graph/js/controllers/blockchain-controllers.js b/www/plugins/graph/js/controllers/blockchain-controllers.js index ab7af7934123e1c2abb9af531055fe2c820fbce2..601fabde7b691f077ba4fb976f888c96292e3ba7 100644 --- a/www/plugins/graph/js/controllers/blockchain-controllers.js +++ b/www/plugins/graph/js/controllers/blockchain-controllers.js @@ -57,7 +57,6 @@ function GpBlockchainTxCountController($scope, $controller, $q, $state, $filter, $scope.load = function(updateTimePct) { var formData = $scope.formData; - console.log(angular.copy($scope.formData)); return $q.all([