diff --git a/webadmin/src/views/account.html b/webadmin/src/views/account.html index 49dca80fd..0506db54b 100644 --- a/webadmin/src/views/account.html +++ b/webadmin/src/views/account.html @@ -140,5 +140,28 @@ +
+ +
+
+

Sessions

+
+
+ +
+
+
+
+

You are logged {{ activeTokenCount }} times into applications, including this session.

+
+

Active Applications:

+

{{ client.name }} ({{client.activeTokens.length}} times)

+
+ +
+
+
+
+

diff --git a/webadmin/src/views/account.js b/webadmin/src/views/account.js index 805327502..c5d2c8d28 100644 --- a/webadmin/src/views/account.js +++ b/webadmin/src/views/account.js @@ -4,6 +4,10 @@ angular.module('Application').controller('AccountController', ['$scope', 'Client $scope.user = Client.getUserInfo(); $scope.config = Client.getConfig(); + $scope.activeTokens = 0; + $scope.activeClients = []; + $scope.webadminClient = {}; + $scope.passwordchange = { busy: false, error: {}, @@ -160,6 +164,58 @@ angular.module('Application').controller('AccountController', ['$scope', 'Client }); }; + // poor man's async + function asyncForEach(items, handler, callback) { + var cur = 0; + + (function iterator() { + handler(items[cur], function () { + if (cur >= items.length-1) return callback(); + ++cur; + + iterator(); + }); + })(); + } + + function revokeTokenByClient(client, callback) { + Client.delTokensByClientId(client.id, function (error) { + if (error) console.error(error); + callback(); + }); + } + + $scope.revokeTokens = function () { + asyncForEach($scope.activeClients, revokeTokenByClient, function () { + console.log('done'); + }); + }; + + function refreshClientTokens(client, callback) { + Client.getTokensByClientId(client.id, function (error, result) { + if (error) console.error(error); + + client.activeTokens = result || []; + + callback(); + }); + } + + Client.onReady(function () { + Client.getOAuthClients(function (error, activeClients) { + if (error) return console.error(error); + + asyncForEach(activeClients, refreshClientTokens, function () { + activeClients = activeClients.filter(function (c) { return c.activeTokens.length > 0; }); + + $scope.activeTokenCount = activeClients.reduce(function (prev, cur) { return prev + cur.activeTokens.length; }, 0); + + $scope.activeClients = activeClients.filter(function (c) { return c.id !== 'cid-sdk' && c.id !== 'cid-webadmin'; }); + $scope.webadminClient = activeClients.filter(function (c) { return c.id === 'cid-webadmin'; })[0]; + }); + }); + }); + // setup all the dialog focus handling ['passwordChangeModal', 'emailChangeModal', 'displayNameChangeModal'].forEach(function (id) { $('#' + id).on('shown.bs.modal', function () { diff --git a/webadmin/src/views/tokens.js b/webadmin/src/views/tokens.js index 596cc4e96..9d6d9f3ee 100644 --- a/webadmin/src/views/tokens.js +++ b/webadmin/src/views/tokens.js @@ -144,9 +144,7 @@ angular.module('Application').controller('TokensController', ['$scope', 'Client' Client.getOAuthClients(function (error, activeClients) { if (error) return console.error(error); - $scope.activeClients = activeClients; - - $scope.activeClients.forEach(refreshClientTokens); + activeClients.forEach(refreshClientTokens); $scope.activeClients = activeClients.filter(function (c) { return c.id !== 'cid-sdk'; }); $scope.apiClient = activeClients.filter(function (c) { return c.id === 'cid-sdk'; })[0];