You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
portainer/app/services/userService.js

49 lines
1.3 KiB

angular.module('portainer.services')
.factory('UserService', ['$q', 'Users', function UserServiceFactory($q, Users) {
'use strict';
var service = {};
service.users = function() {
return Users.query({}).$promise;
};
service.user = function(id) {
return Users.get({id: id}).$promise;
};
service.createUser = function(username, password, role) {
return Users.create({}, {username: username, password: password, role: role}).$promise;
};
service.deleteUser = function(id) {
return Users.remove({id: id}).$promise;
};
service.updateUser = function(id, password, role) {
var query = {
password: password,
role: role
};
return Users.update({id: id}, query).$promise;
};
service.updateUserPassword = function(id, currentPassword, newPassword) {
var deferred = $q.defer();
Users.checkPassword({id: id}, {password: currentPassword}).$promise
.then(function success(data) {
if (!data.valid) {
deferred.reject({invalidPassword: true});
}
return service.updateUser(id, newPassword, undefined);
})
.then(function success(data) {
deferred.resolve();
})
.catch(function error(err) {
deferred.reject({msg: 'Unable to update user password', err: err});
});
return deferred.promise;
};
return service;
}]);