2017-03-12 16:24:15 +00:00
|
|
|
angular.module('user', [])
|
2017-08-10 08:35:23 +00:00
|
|
|
.controller('UserController', ['$q', '$scope', '$state', '$stateParams', 'UserService', 'ModalService', 'Notifications', 'SettingsService',
|
|
|
|
function ($q, $scope, $state, $stateParams, UserService, ModalService, Notifications, SettingsService) {
|
2017-03-12 16:24:15 +00:00
|
|
|
|
|
|
|
$scope.state = {
|
2017-05-23 18:56:10 +00:00
|
|
|
updatePasswordError: ''
|
2017-03-12 16:24:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
$scope.formValues = {
|
|
|
|
newPassword: '',
|
2017-03-27 12:44:39 +00:00
|
|
|
confirmPassword: '',
|
2017-05-23 18:56:10 +00:00
|
|
|
Administrator: false
|
2017-03-12 16:24:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
$scope.deleteUser = function() {
|
|
|
|
ModalService.confirmDeletion(
|
2017-04-25 08:20:57 +00:00
|
|
|
'Do you want to remove this user? This user will not be able to login into Portainer anymore.',
|
2017-03-12 16:24:15 +00:00
|
|
|
function onConfirm(confirmed) {
|
|
|
|
if(!confirmed) { return; }
|
|
|
|
deleteUser();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.updatePermissions = function() {
|
|
|
|
$('#loadingViewSpinner').show();
|
2017-03-27 12:44:39 +00:00
|
|
|
var role = $scope.formValues.Administrator ? 1 : 2;
|
|
|
|
UserService.updateUser($scope.user.Id, undefined, role)
|
2017-03-12 16:24:15 +00:00
|
|
|
.then(function success(data) {
|
2017-03-27 12:44:39 +00:00
|
|
|
var newRole = role === 1 ? 'administrator' : 'user';
|
2017-04-12 19:47:22 +00:00
|
|
|
Notifications.success('Permissions successfully updated', $scope.user.Username + ' is now ' + newRole);
|
2017-03-12 16:24:15 +00:00
|
|
|
$state.reload();
|
|
|
|
})
|
|
|
|
.catch(function error(err) {
|
2017-05-23 18:56:10 +00:00
|
|
|
Notifications.error('Failure', err, 'Unable to update user permissions');
|
2017-03-12 16:24:15 +00:00
|
|
|
})
|
|
|
|
.finally(function final() {
|
|
|
|
$('#loadingViewSpinner').hide();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.updatePassword = function() {
|
|
|
|
$('#loadingViewSpinner').show();
|
|
|
|
UserService.updateUser($scope.user.Id, $scope.formValues.newPassword, undefined)
|
|
|
|
.then(function success(data) {
|
2017-04-12 19:47:22 +00:00
|
|
|
Notifications.success('Password successfully updated');
|
2017-03-12 16:24:15 +00:00
|
|
|
$state.reload();
|
|
|
|
})
|
|
|
|
.catch(function error(err) {
|
2017-05-23 18:56:10 +00:00
|
|
|
Notifications.error('Failure', err, 'Unable to update user password');
|
2017-03-12 16:24:15 +00:00
|
|
|
})
|
|
|
|
.finally(function final() {
|
|
|
|
$('#loadingViewSpinner').hide();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
function deleteUser() {
|
|
|
|
$('#loadingViewSpinner').show();
|
|
|
|
UserService.deleteUser($scope.user.Id)
|
|
|
|
.then(function success(data) {
|
2017-04-12 19:47:22 +00:00
|
|
|
Notifications.success('User successfully deleted', $scope.user.Username);
|
2017-03-12 16:24:15 +00:00
|
|
|
$state.go('users');
|
|
|
|
})
|
|
|
|
.catch(function error(err) {
|
2017-05-23 18:56:10 +00:00
|
|
|
Notifications.error('Failure', err, 'Unable to remove user');
|
2017-03-12 16:24:15 +00:00
|
|
|
})
|
|
|
|
.finally(function final() {
|
|
|
|
$('#loadingViewSpinner').hide();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-05-23 18:56:10 +00:00
|
|
|
function initView() {
|
2017-03-12 16:24:15 +00:00
|
|
|
$('#loadingViewSpinner').show();
|
2017-05-23 18:56:10 +00:00
|
|
|
$q.all({
|
2017-08-10 08:35:23 +00:00
|
|
|
user: UserService.user($stateParams.id),
|
|
|
|
settings: SettingsService.publicSettings()
|
2017-05-23 18:56:10 +00:00
|
|
|
})
|
2017-03-12 16:24:15 +00:00
|
|
|
.then(function success(data) {
|
2017-05-23 18:56:10 +00:00
|
|
|
var user = data.user;
|
2017-03-27 12:44:39 +00:00
|
|
|
$scope.user = user;
|
2017-05-23 18:56:10 +00:00
|
|
|
$scope.formValues.Administrator = user.Role === 1 ? true : false;
|
2017-08-10 08:35:23 +00:00
|
|
|
$scope.AuthenticationMethod = data.settings.AuthenticationMethod;
|
2017-03-12 16:24:15 +00:00
|
|
|
})
|
|
|
|
.catch(function error(err) {
|
2017-05-23 18:56:10 +00:00
|
|
|
Notifications.error('Failure', err, 'Unable to retrieve user information');
|
2017-03-12 16:24:15 +00:00
|
|
|
})
|
|
|
|
.finally(function final() {
|
|
|
|
$('#loadingViewSpinner').hide();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-05-23 18:56:10 +00:00
|
|
|
initView();
|
2017-03-12 16:24:15 +00:00
|
|
|
}]);
|