diff --git a/src/js/index.js b/src/js/index.js index 9fed217b4..48e278ffd 100644 --- a/src/js/index.js +++ b/src/js/index.js @@ -159,9 +159,6 @@ app.config(['$routeProvider', function ($routeProvider) { }).when('/system', { controller: 'SystemController', templateUrl: 'views/system.html?<%= revision %>' - }).when('/tokens', { - controller: 'TokensController', - templateUrl: 'views/tokens.html?<%= revision %>' }).otherwise({ redirectTo: '/'}); }]); diff --git a/src/views/tokens.html b/src/views/tokens.html deleted file mode 100644 index 5a7fcac46..000000000 --- a/src/views/tokens.html +++ /dev/null @@ -1,197 +0,0 @@ - - - - - - - - - - -
-
-

API Tokens

-
- - -
-
-
-
-

These tokens can be used to access the Cloudron API.

- - - - - - - - - - - - - -
NameActions
- {{ token.name || '-' }} - - -
-
-
-
-
- -
- -
-

OAuth Apps

-
- - -
-
-
-
-

- {{client.name}} on {{client.domain}} -

-
-
-
-
-
-
- {{ client.activeTokens.length }} active token(s). -
- Advanced -
-
-

Credentials

-
-

Scope: {{ client.scope }}

-

RedirectURI: {{ client.redirectURI }}

-

Client ID: {{ client.id }}

-

Client Secret: {{ client.clientSecret }}

- -
- -

Tokens -
- - -
-

- -
- -

- {{ token.name || token.id }} -

-
-
-
-
-
-
-
-
-
diff --git a/src/views/tokens.js b/src/views/tokens.js deleted file mode 100644 index 324aab4ba..000000000 --- a/src/views/tokens.js +++ /dev/null @@ -1,197 +0,0 @@ -'use strict'; - -/* global angular:false */ -/* global $:false */ - -angular.module('Application').controller('TokensController', ['$scope', '$location', 'Client', function ($scope, $location, Client) { - Client.onReady(function () { if (!Client.getUserInfo().admin) $location.path('/'); }); - - $scope.user = Client.getUserInfo(); - $scope.config = Client.getConfig(); - - $scope.activeClients = []; - $scope.apiClient = {}; - - $scope.clientAdd = { - busy: false, - error: {}, - name: '', - scope: '', - redirectURI: '', - - show: function () { - $scope.clientAdd.busy = false; - - $scope.clientAdd.error = {}; - $scope.clientAdd.name = ''; - $scope.clientAdd.scope = 'profile'; - $scope.clientAdd.redirectURI = ''; - - $scope.clientAddForm.$setUntouched(); - $scope.clientAddForm.$setPristine(); - - $('#clientAddModal').modal('show'); - }, - - submit: function () { - $scope.clientAdd.busy = true; - $scope.clientAdd.error = {}; - - var CLIENT_REDIRECT_URI_FALLBACK = Client.apiOrigin || location.origin; - - Client.createOAuthClient($scope.clientAdd.name, $scope.clientAdd.scope, $scope.clientAdd.redirectURI || CLIENT_REDIRECT_URI_FALLBACK, function (error) { - $scope.clientAdd.busy = false; - - if (error && error.statusCode === 400) { - if (error.message.indexOf('redirectURI must be a valid uri') === 0) { - $scope.clientAdd.error.redirectURI = error.message; - $scope.clientAddForm.redirectURI.$setPristine(); - $('#clientAddRedirectURI').focus(); - } else if (error.message.indexOf('Username can only contain alphanumerals and dash') === 0) { - $scope.clientAdd.error.name = error.message; - $scope.clientAddForm.name.$setPristine(); - $('#clientAddName').focus(); - } else if (error.message.indexOf('Invalid scope') === 0) { - $scope.clientAdd.error.scope = error.message; - $scope.clientAddForm.scope.$setPristine(); - $('#clientAddScope').focus(); - } else { - console.error(error); - } - return; - } else if (error) return console.error('Unable to create API client.', error.statusCode, error.message); - - refresh(); - - $('#clientAddModal').modal('hide'); - }); - } - }; - - $scope.clientRemove = { - busy: false, - client: {}, - - show: function (client) { - $scope.clientRemove.busy = false; - $scope.clientRemove.client = client; - $('#clientRemoveModal').modal('show'); - }, - - submit: function () { - $scope.clientRemove.busy = true; - - Client.delOAuthClient($scope.clientRemove.client.id, function (error) { - $scope.clientRemove.busy = false; - if (error) return console.error(error); - - $scope.clientRemove.client = {}; - - refresh(); - - $('#clientRemoveModal').modal('hide'); - }); - } - }; - - - $scope.tokenAdd = { - token: {}, - tokenName: '', - busy: false, - error: {}, - client: null, - - reset: function () { - $scope.tokenAdd.busy = false; - $scope.tokenAdd.token = {}; - $scope.tokenAdd.error.tokenName = null; - $scope.tokenAdd.tokenName = ''; - $scope.tokenAdd.client = null; - - $scope.tokenAddForm.$setUntouched(); - $scope.tokenAddForm.$setPristine(); - }, - - show: function (client) { - $scope.tokenAdd.reset(); - $scope.tokenAdd.client = client; - $('#tokenAddModal').modal('show'); - }, - - submit: function () { - $scope.tokenAdd.busy = true; - $scope.tokenAdd.token = {}; - - var expiresAt = Date.now() + 100 * 365 * 24 * 60 * 60 * 1000; // ~100 years from now - - Client.createTokenByClientId($scope.tokenAdd.client.id, '*' /* scope */, expiresAt, $scope.tokenAdd.tokenName, function (error, result) { - if (error) { - if (error.statusCode === 400) { - $scope.tokenAdd.error.tokenName = 'Invalid token name'; - $scope.tokenAddForm.tokenName.$setPristine(); - $('#inputTokenAddName').focus(); - } else { - console.error('Unable to create token.', error); - } - return; - } - - $scope.tokenAdd.busy = false; - $scope.tokenAdd.token = result; - - refreshClientTokens($scope.tokenAdd.client); - }); - } - }; - - $scope.removeToken = function (client, token) { - Client.delToken(client.id, token.id, function (error) { - if (error) console.error(error); - - refreshClientTokens(client); - }); - }; - - $scope.removeAccessTokens = function (client) { - client.busy = true; - - Client.delTokensByClientId(client.id, function (error) { - if (error) console.error(error); - - client.busy = false; - - refreshClientTokens(client); - }); - }; - - function refreshClientTokens(client) { - Client.getTokensByClientId(client.id, function (error, result) { - if (error) console.error(error); - - client.activeTokens = result || []; - }); - } - - function refresh() { - Client.getOAuthClients(function (error, activeClients) { - if (error) return console.error(error); - - 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]; - }); - } - - Client.onReady(refresh); - - // setup all the dialog focus handling - ['clientAddModal', 'tokenAddModal'].forEach(function (id) { - $('#' + id).on('shown.bs.modal', function () { - $(this).find("[autofocus]:first").focus(); - }); - }); - - $('.modal-backdrop').remove(); -}]);