diff --git a/src/views/profile.html b/src/views/profile.html index 1fa778343..efe4d906e 100644 --- a/src/views/profile.html +++ b/src/views/profile.html @@ -193,49 +193,6 @@ - - -
@@ -302,37 +259,4 @@
- -
-

API Tokens

-
- - -
-
-
-
-

These tokens can be used to access the Cloudron API.

- - - - - - - - - - - - - -
NameActions
- {{ token.name || '-' }} - - -
-
-
-
-
diff --git a/src/views/profile.js b/src/views/profile.js index a9384f014..d55d1a0ff 100644 --- a/src/views/profile.js +++ b/src/views/profile.js @@ -12,7 +12,6 @@ angular.module('Application').controller('ProfileController', ['$scope', '$locat $scope.webadminClient = {}; $scope.apiClient = {}; $scope.cliClient = {}; - $scope.showApiTokens = !!$location.search().tokens; $scope.twoFactorAuthentication = { busy: false, @@ -298,61 +297,6 @@ angular.module('Application').controller('ProfileController', ['$scope', '$locat } }; - $scope.tokenAdd = { - token: {}, - tokenName: '', - busy: false, - error: {}, - - reset: function () { - $scope.tokenAdd.busy = false; - $scope.tokenAdd.token = {}; - $scope.tokenAdd.error.tokenName = null; - $scope.tokenAdd.tokenName = ''; - - $scope.tokenAddForm.$setUntouched(); - $scope.tokenAddForm.$setPristine(); - }, - - show: function () { - $scope.tokenAdd.reset(); - $('#tokenAddModal').modal('show'); - }, - - submit: function (client) { - $scope.tokenAdd.busy = true; - $scope.tokenAdd.token = {}; - - var expiresAt = Date.now() + 100 * 365 * 24 * 60 * 60 * 1000; // ~100 years from now - - Client.createTokenByClientId(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(client); - }); - } - }; - - $scope.removeToken = function (client, token) { - Client.delToken(client.id, token.id, function (error) { - if (error) console.error(error); - - refreshClientTokens(client); - }); - }; - function revokeTokensByClient(client, callback) { Client.delTokensByClientId(client.id, function (error) { if (error) console.error(error); @@ -399,7 +343,7 @@ angular.module('Application').controller('ProfileController', ['$scope', '$locat }); // setup all the dialog focus handling - ['passwordChangeModal', 'emailChangeModal', 'fallbackEmailChangeModal', 'displayNameChangeModal', 'twoFactorAuthenticationEnableModal', 'twoFactorAuthenticationDisableModal', 'tokenAddModal'].forEach(function (id) { + ['passwordChangeModal', 'emailChangeModal', 'fallbackEmailChangeModal', 'displayNameChangeModal', 'twoFactorAuthenticationEnableModal', 'twoFactorAuthenticationDisableModal'].forEach(function (id) { $('#' + id).on('shown.bs.modal', function () { $(this).find("[autofocus]:first").focus(); }); diff --git a/src/views/tokens.html b/src/views/tokens.html index 7670e84bc..fc0cf7375 100644 --- a/src/views/tokens.html +++ b/src/views/tokens.html @@ -68,90 +68,130 @@
-
-

Access Tokens

-
+
+

API Tokens

+
- -
-
-
-
-

These tokens can be used to access the Cloudron API.

-
-

Active Tokens

-
-

- {{ token.accessToken }} -

-
-
-
-
+ +
+
+
+
+

These tokens can be used to access the Cloudron API.

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

OAuth Apps

-
+
+

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 }}

+ +
+
+
+
+

+ {{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 -
- - -
-

+

Tokens +
+ + +
+

-
+
-

- {{ token.accessToken }} -

-
-
-
-
-
-
-
-
+

+ {{ token.accessToken }} +

+
+
+
+
+
+
+
+
diff --git a/src/views/tokens.js b/src/views/tokens.js index 7b3d89987..439a53b98 100644 --- a/src/views/tokens.js +++ b/src/views/tokens.js @@ -94,31 +94,56 @@ angular.module('Application').controller('TokensController', ['$scope', '$locati } }; - $scope.tokenAdd = { - busy: false, - token: {}, - show: function (client) { + $scope.tokenAdd = { + token: {}, + tokenName: '', + busy: false, + error: {}, + + reset: function () { + $scope.tokenAdd.busy = false; + $scope.tokenAdd.token = {}; + $scope.tokenAdd.error.tokenName = null; + $scope.tokenAdd.tokenName = ''; + + $scope.tokenAddForm.$setUntouched(); + $scope.tokenAddForm.$setPristine(); + }, + + show: function () { + $scope.tokenAdd.reset(); + $('#tokenAddModal').modal('show'); + }, + + submit: function (client) { $scope.tokenAdd.busy = true; $scope.tokenAdd.token = {}; var expiresAt = Date.now() + 100 * 365 * 24 * 60 * 60 * 1000; // ~100 years from now - Client.createTokenByClientId(client.id, '*' /* scope */, expiresAt, '' /* name */, function (error, result) { - if (error) return console.error(error); + Client.createTokenByClientId(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; - $('#tokenAddModal').modal('show'); - refreshClientTokens(client); }); } }; $scope.removeToken = function (client, token) { - Client.delToken(client.id, token.accessToken, function (error) { + Client.delToken(client.id, token.id, function (error) { if (error) console.error(error); refreshClientTokens(client); @@ -159,7 +184,7 @@ angular.module('Application').controller('TokensController', ['$scope', '$locati Client.onReady(refresh); // setup all the dialog focus handling - ['clientAddModal'].forEach(function (id) { + ['clientAddModal', 'tokenAddModal'].forEach(function (id) { $('#' + id).on('shown.bs.modal', function () { $(this).find("[autofocus]:first").focus(); });