List all tokens in profile

This commit is contained in:
Johannes Zellner
2020-02-07 17:03:14 +01:00
parent 3efe7eb85d
commit 8ae6bf832a
2 changed files with 68 additions and 47 deletions
+40 -42
View File
@@ -9,11 +9,6 @@ angular.module('Application').controller('ProfileController', ['$scope', '$locat
$scope.config = Client.getConfig();
$scope.apps = Client.getInstalledApps();
$scope.activeClients = [];
$scope.webadminClient = {};
$scope.apiClient = {};
$scope.cliClient = {};
$scope.twoFactorAuthentication = {
busy: false,
error: null,
@@ -493,50 +488,53 @@ angular.module('Application').controller('ProfileController', ['$scope', '$locat
}
};
function revokeTokensByClient(clientId, callback) {
Client.delTokensByClientId(clientId, function (error) {
if (error) console.error(error);
callback();
});
}
$scope.tokens = {
busy: false,
error: {},
allTokens: [],
webadminTokens: [],
cliTokens: [],
apiTokens: [],
$scope.revokeTokens = function () {
// first revoke all non webadmin tokens
var nonWebClientIds = $scope.activeClients.filter(function (c) { return c.id !== 'cid-webadmin'; }).map(function (c) { return c.id; });
asyncForEach(nonWebClientIds, revokeTokensByClient, function () {
// WARNING keep in sync with clients.js in box code
revokeTokensByClient('cid-webadmin', function () {
Client.logout(true /* destroy all OAuth sessions for this user */);
refresh: function () {
$scope.tokens.busy = true;
Client.getTokens(function (error, result) {
if (error) return console.error(error);
$scope.tokens.busy = false;
$scope.tokens.allTokens = result;
$scope.tokens.webadminTokens = result.filter(function (c) { return c.clientId === 'cid-webadmin'; });
$scope.tokens.cliTokens = result.filter(function (c) { return c.clientId === 'cid-cli'; });
$scope.tokens.apiTokens = result.filter(function (c) { return c.clientId === 'cid-sdk'; });
});
});
},
revokeAll: function () {
},
add: {
busy: false,
error: null,
name: '',
show: function () {
},
submit: function () {
}
}
};
function refreshClientTokens(client, callback) {
Client.getTokensByClientId(client.id, function (error, result) {
if (error) console.error(error);
client.activeTokens = result || [];
if (callback) callback();
});
}
Client.onReady(function () {
if (!Client.getUserInfo().admin) return;
Client.getOAuthClients(function (error, activeClients) {
if (error) return console.error(error);
$scope.appPassword.refresh();
asyncForEach(activeClients, refreshClientTokens, function () {
$scope.webadminClient = activeClients.filter(function (c) { return c.id === 'cid-webadmin'; })[0];
$scope.apiClient = activeClients.filter(function (c) { return c.id === 'cid-sdk'; })[0];
$scope.cliClient = activeClients.filter(function (c) { return c.id === 'cid-cli'; })[0];
$scope.activeClients = activeClients;
});
});
$scope.appPassword.refresh();
$scope.tokens.refresh();
});
$('#avatarFileInput').get(0).onchange = function (event) {