Get token name as input

This commit is contained in:
Girish Ramakrishnan
2018-08-27 16:04:16 -07:00
parent 764e7e7d1f
commit 9c90a20b4d
4 changed files with 60 additions and 20 deletions
+29 -14
View File
@@ -296,32 +296,47 @@ angular.module('Application').controller('AccountController', ['$scope', 'Client
};
$scope.tokenAdd = {
busy: false,
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 (client) {
$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, function (error, result) {
if (error && error.statusCode === 412) {
var actionScope = $scope.$new(true);
actionScope.action = '/#/settings';
Client.notify('Not allowed', 'You have to enable the external API in the settings.', false, 'error', actionScope);
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;
} else if (error) {
return console.error(error);
}
$scope.tokenAdd.busy = false;
$scope.tokenAdd.token = result;
$('#tokenAddModal').modal('show');
refreshClientTokens(client);
});
}
@@ -360,7 +375,7 @@ angular.module('Application').controller('AccountController', ['$scope', 'Client
client.activeTokens = result || [];
callback();
if (callback) callback();
});
}
@@ -382,7 +397,7 @@ angular.module('Application').controller('AccountController', ['$scope', 'Client
});
// setup all the dialog focus handling
['passwordChangeModal', 'emailChangeModal', 'fallbackEmailChangeModal', 'displayNameChangeModal', 'twoFactorAuthenticationEnableModal', 'twoFactorAuthenticationDisableModal'].forEach(function (id) {
['passwordChangeModal', 'emailChangeModal', 'fallbackEmailChangeModal', 'displayNameChangeModal', 'twoFactorAuthenticationEnableModal', 'twoFactorAuthenticationDisableModal', 'tokenAddModal'].forEach(function (id) {
$('#' + id).on('shown.bs.modal', function () {
$(this).find("[autofocus]:first").focus();
});