passman/js/app/controllers/credential.js

52 lines
1.6 KiB
JavaScript
Raw Normal View History

2016-09-12 02:47:29 +08:00
'use strict';
/**
* @ngdoc function
* @name passmanApp.controller:MainCtrl
* @description
* # MainCtrl
* Controller of the passmanApp
*/
angular.module('passmanApp')
2016-09-12 04:57:55 +08:00
.controller('CredentialCtrl', ['$scope', 'VaultService', 'SettingsService', '$location', 'CredentialService', '$rootScope', function ($scope, VaultService, SettingsService, $location, CredentialService, $rootScope) {
2016-09-12 02:47:29 +08:00
$scope.active_vault = VaultService.getActiveVault();
if(! SettingsService.getSetting('defaultVault') || ! SettingsService.getSetting('defaultVaultPass')){
if(!$scope.active_vault){
$location.path('/')
}
} else {
if(SettingsService.getSetting('defaultVault') && SettingsService.getSetting('defaultVaultPass')){
var _vault = angular.copy(SettingsService.getSetting('defaultVault'))
_vault.vaultKey = angular.copy(SettingsService.getSetting('defaultVaultPass'));
VaultService.setActiveVault(_vault);
$scope.active_vault = _vault;
}
}
2016-09-12 04:57:55 +08:00
$rootScope.$on('logout', function(){
console.log('Logout received, clean up');
$scope.credentials = [];
$scope.$parent.selectedVault = false;
$scope.active_vault = null;
});
2016-09-12 02:47:29 +08:00
var fetchCredentials = function(){
VaultService.getVault($scope.active_vault).then(function(credentials) {
var _credentials = [];
for(var i = 0; i < credentials.length; i++){
var credential = CredentialService.decryptCredential(angular.copy(credentials[i]));
_credentials.push(credential);
}
$scope.credentials = _credentials;
2016-09-12 05:40:06 +08:00
//@Todo: Set last accessed
2016-09-12 02:47:29 +08:00
});
};
if($scope.active_vault){
$scope.$parent.selectedVault = true;
fetchCredentials();
}
}]);