List all tokens in profile
This commit is contained in:
+40
-42
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user