passman/js/app/services/vaultservice.js

90 lines
2.4 KiB
JavaScript
Raw Normal View History

2016-09-11 05:30:17 +08:00
'use strict';
/**
* @ngdoc service
* @name passmanApp.VaultService
* @description
* # VaultService
* Service in the passmanApp.
*/
angular.module('passmanApp')
.service('VaultService', ['$http', function ($http) {
2016-09-11 05:30:17 +08:00
// AngularJS will instantiate a singleton by calling "new" on this function
2016-09-12 01:45:20 +08:00
var _activeVault;
2016-09-11 05:30:17 +08:00
return {
getVaults: function(){
2016-09-12 01:45:20 +08:00
var queryUrl = OC.generateUrl('apps/passman/api/v2/vaults');
2016-09-11 05:30:17 +08:00
return $http.get(queryUrl).then(function (response) {
if(response.data){
return response.data;
} else {
return response;
}
});
},
2016-09-12 01:45:20 +08:00
setActiveVault: function(vault){
_activeVault = vault;
},
getActiveVault: function(vault){
return _activeVault;
},
createVault: function (vaultName) {
2016-09-12 01:45:20 +08:00
var queryUrl = OC.generateUrl('apps/passman/api/v2/vaults');
return $http.post(queryUrl, { vault_name: vaultName }).then(function (response) {
if(response.data){
return response.data;
} else {
return response;
}
});
},
getVault: function (vault) {
2016-09-12 01:45:20 +08:00
var queryUrl = OC.generateUrl('apps/passman/api/v2/vaults/' + vault.vault_id);
return $http.get(queryUrl).then(function (response) {
if(response.data){
2016-09-29 04:05:09 +08:00
if(response.data.vault_settings){
response.data.vault_settings = JSON.parse(window.atob(response.data.vault_settings))
}
return response.data;
} else {
return response;
}
});
},
updateVault: function (vault) {
2016-09-29 03:21:58 +08:00
var _vault = angular.copy(vault);
delete vault.defaultVaultPass;
delete vault.defaultVault;
2016-09-29 04:05:09 +08:00
var queryUrl = OC.generateUrl('apps/passman/api/v2/vaults/' + _vault.vault_id);
return $http.patch(queryUrl, _vault).then(function (response) {
if(response.data){
return response.data;
} else {
return response;
}
});
},
2016-09-26 00:34:33 +08:00
updateSharingKeys: function (vault) {
var queryUrl = OC.generateUrl('apps/passman/api/v2/vaults/' + vault.vault_id +'/sharing-keys');
return $http.post(queryUrl, vault).then(function (response) {
if(response.data){
return response.data;
} else {
return response;
}
});
},
deleteVault: function (vault) {
2016-09-12 01:45:20 +08:00
var queryUrl = OC.generateUrl('apps/passman/api/v2/vaults/' + vault.vault_id);
return $http.delete(queryUrl).then(function (response) {
if(response.data){
return response.data;
} else {
return response;
}
});
2016-09-11 05:30:17 +08:00
}
}
}]);