150 lines
4.5 KiB
JavaScript
150 lines
4.5 KiB
JavaScript
'use strict';
|
|
|
|
/* global angular */
|
|
/* global $ */
|
|
|
|
angular.module('Application').controller('OidcController', ['$scope', '$location', 'Client', function ($scope, $location, Client) {
|
|
Client.onReady(function () { if (!Client.getUserInfo().isAtLeastAdmin) $location.path('/'); });
|
|
|
|
$scope.user = Client.getUserInfo();
|
|
$scope.config = Client.getConfig();
|
|
$scope.clients = [];
|
|
|
|
$scope.refreshClients = function () {
|
|
Client.getOidcClients(function (error, result) {
|
|
if (error) return console.error('Failed to load oidc clients', error);
|
|
|
|
$scope.clients = result;
|
|
});
|
|
};
|
|
|
|
$scope.clientAdd = {
|
|
busy: false,
|
|
error: {},
|
|
id: '',
|
|
name: '',
|
|
secret: '',
|
|
loginRedirectUri: '',
|
|
logoutRedirectUri: '',
|
|
|
|
show: function () {
|
|
$scope.clientAdd.id = '';
|
|
$scope.clientAdd.secret = '';
|
|
$scope.clientAdd.name = '';
|
|
$scope.clientAdd.loginRedirectUri = '';
|
|
$scope.clientAdd.logoutRedirectUri = '';
|
|
$scope.clientAdd.busy = false;
|
|
$scope.clientAdd.error = null;
|
|
$scope.clientAddForm.$setPristine();
|
|
|
|
$('#clientAddModal').modal('show');
|
|
},
|
|
|
|
submit: function () {
|
|
$scope.clientAdd.busy = true;
|
|
$scope.clientAdd.error = {};
|
|
|
|
Client.addOidcClient($scope.clientAdd.id, $scope.clientAdd.name, $scope.clientAdd.secret, $scope.clientAdd.loginRedirectUri, $scope.clientAdd.logoutRedirectUri, function (error) {
|
|
if (error) {
|
|
if (error.statusCode === 409) {
|
|
$scope.clientAdd.error.id = 'Client ID already exists';
|
|
$('#clientId').focus();
|
|
} else {
|
|
console.error('Unable to add openid client.', error);
|
|
}
|
|
|
|
$scope.clientAdd.busy = false;
|
|
|
|
return;
|
|
}
|
|
|
|
$scope.refreshClients();
|
|
$scope.clientAdd.busy = false;
|
|
|
|
$('#clientAddModal').modal('hide');
|
|
});
|
|
}
|
|
};
|
|
|
|
$scope.clientEdit = {
|
|
busy: false,
|
|
error: {},
|
|
id: '',
|
|
name: '',
|
|
secret: '',
|
|
loginRedirectUri: '',
|
|
logoutRedirectUri: '',
|
|
|
|
show: function (client) {
|
|
$scope.clientEdit.id = client.id;
|
|
$scope.clientEdit.name = client.name;
|
|
$scope.clientEdit.secret = client.secret;
|
|
$scope.clientEdit.loginRedirectUri = client.loginRedirectUri;
|
|
$scope.clientEdit.logoutRedirectUri = client.logoutRedirectUri;
|
|
$scope.clientEdit.busy = false;
|
|
$scope.clientEdit.error = null;
|
|
$scope.clientEditForm.$setPristine();
|
|
|
|
$('#clientEditModal').modal('show');
|
|
},
|
|
|
|
submit: function () {
|
|
$scope.clientEdit.busy = true;
|
|
$scope.clientEdit.error = {};
|
|
|
|
Client.updateOidcClient($scope.clientEdit.id, $scope.clientEdit.name, $scope.clientEdit.secret, $scope.clientEdit.loginRedirectUri, $scope.clientEdit.logoutRedirectUri, function (error) {
|
|
if (error) {
|
|
console.error('Unable to edit openid client.', error);
|
|
|
|
$scope.clientEdit.busy = false;
|
|
|
|
return;
|
|
}
|
|
|
|
$scope.refreshClients();
|
|
$scope.clientEdit.busy = false;
|
|
|
|
$('#clientEditModal').modal('hide');
|
|
});
|
|
}
|
|
};
|
|
|
|
$scope.deleteClient = {
|
|
busy: false,
|
|
error: {},
|
|
id: '',
|
|
|
|
show: function (client) {
|
|
$scope.deleteClient.busy = false;
|
|
$scope.deleteClient.id = client.id;
|
|
|
|
$('#clientDeleteModal').modal('show');
|
|
},
|
|
|
|
submit: function () {
|
|
Client.delOidcClient($scope.deleteClient.id, function (error) {
|
|
$scope.deleteClient.busy = false;
|
|
|
|
if (error) return console.error('Failed to delete openid client', error);
|
|
|
|
$scope.refreshClients();
|
|
|
|
$('#clientDeleteModal').modal('hide');
|
|
});
|
|
}
|
|
};
|
|
|
|
Client.onReady(function () {
|
|
$scope.refreshClients();
|
|
});
|
|
|
|
// setup all the dialog focus handling
|
|
['clientAddModal', 'clientEditmodal'].forEach(function (id) {
|
|
$('#' + id).on('shown.bs.modal', function () {
|
|
$(this).find('[autofocus]:first').focus();
|
|
});
|
|
});
|
|
|
|
$('.modal-backdrop').remove();
|
|
}]);
|