mirror of
https://github.com/nextcloud/passman.git
synced 2025-10-09 04:56:58 +08:00
Finish up vault settings
This commit is contained in:
parent
3394d78d36
commit
fc99d93f86
4 changed files with 91 additions and 78 deletions
|
@ -10,8 +10,33 @@
|
|||
angular.module('passmanApp')
|
||||
.controller('CredentialEditCtrl', ['$scope', 'VaultService', 'CredentialService', 'SettingsService', '$location', '$routeParams', 'FileService', 'EncryptService', 'TagService', 'NotificationService',
|
||||
function ($scope, VaultService, CredentialService, SettingsService, $location, $routeParams, FileService, EncryptService, TagService, NotificationService) {
|
||||
$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'));
|
||||
VaultService.getVault(_vault).then(function (vault) {
|
||||
vault.vaultKey = SettingsService.getSetting('defaultVaultPass');
|
||||
VaultService.setActiveVault(vault);
|
||||
$scope.active_vault = vault;
|
||||
|
||||
$scope.pwSettings = VaultService.getVaultSetting('pwSettings',
|
||||
{
|
||||
'length': 12,
|
||||
'useUppercase': true,
|
||||
'useLowercase': true,
|
||||
'useDigits': true,
|
||||
'useSpecialChars': true,
|
||||
'minimumDigitCount': 3,
|
||||
'avoidAmbiguousCharacters': false,
|
||||
'requireEveryCharType': true,
|
||||
'generateOnCreate': true,
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
$scope.tabs = [{
|
||||
title: 'General',
|
||||
|
@ -34,21 +59,6 @@ angular.module('passmanApp')
|
|||
url: 'views/partials/forms/edit_credential/otp.html',
|
||||
color: 'purple'
|
||||
}];
|
||||
if($scope.active_vault.vault_settings && $scope.active_vault.vault_settings.pwSettings){
|
||||
$scope.pwSettings = angular.copy($scope.active_vault.vault_settings.pwSettings);
|
||||
} else {
|
||||
$scope.pwSettings = {
|
||||
'length': 12,
|
||||
'useUppercase': true,
|
||||
'useLowercase': true,
|
||||
'useDigits': true,
|
||||
'useSpecialChars': true,
|
||||
'minimumDigitCount': 3,
|
||||
'avoidAmbiguousCharacters': false,
|
||||
'requireEveryCharType': true,
|
||||
'generateOnCreate': true,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
if (!SettingsService.getSetting('defaultVault') || !SettingsService.getSetting('defaultVaultPass')) {
|
||||
|
@ -70,7 +80,7 @@ angular.module('passmanApp')
|
|||
var storedCredential = SettingsService.getSetting('edit_credential');
|
||||
|
||||
if (!storedCredential) {
|
||||
CredentialService.getCredential($routeParams.credential_id).then(function(result){
|
||||
CredentialService.getCredential($routeParams.credential_id).then(function (result) {
|
||||
$scope.storedCredential = CredentialService.decryptCredential(angular.copy(result));
|
||||
});
|
||||
} else {
|
||||
|
@ -176,10 +186,10 @@ angular.module('passmanApp')
|
|||
$scope.renewIntervalValue = 0;
|
||||
$scope.renewIntervalModifier = '0';
|
||||
|
||||
$scope.updateInterval = function(renewIntervalValue, renewIntervalModifier){
|
||||
$scope.updateInterval = function (renewIntervalValue, renewIntervalModifier) {
|
||||
var value = parseInt(renewIntervalValue);
|
||||
var modifier = parseInt(renewIntervalModifier);
|
||||
if( value && modifier) {
|
||||
if (value && modifier) {
|
||||
$scope.storedCredential.renew_interval = value * modifier;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
angular.module('passmanApp')
|
||||
.controller('SettingsCtrl', ['$scope', '$rootScope', 'SettingsService', 'VaultService', 'CredentialService', '$location', '$routeParams', '$http', 'EncryptService',
|
||||
function ($scope, $rootScope, SettingsService, VaultService, CredentialService, $location, $routeParams, $http, EncryptService) {
|
||||
|
||||
$scope.vault_settings = {};
|
||||
if (!SettingsService.getSetting('defaultVault') || !SettingsService.getSetting('defaultVaultPass')) {
|
||||
if (!$scope.active_vault) {
|
||||
$location.path('/')
|
||||
|
@ -18,42 +18,37 @@ angular.module('passmanApp')
|
|||
} else {
|
||||
if (SettingsService.getSetting('defaultVault') && SettingsService.getSetting('defaultVaultPass')) {
|
||||
var _vault = angular.copy(SettingsService.getSetting('defaultVault'));
|
||||
VaultService.setActiveVault(_vault);
|
||||
$scope.active_vault = _vault;
|
||||
|
||||
VaultService.getVault(_vault).then(function (vault) {
|
||||
vault.vaultKey = SettingsService.getSetting('defaultVaultPass');
|
||||
VaultService.setActiveVault(vault);
|
||||
$scope.active_vault = vault;
|
||||
$scope.$parent.selectedVault = true;
|
||||
$scope.vault_settings.pwSettings = VaultService.getVaultSetting('pwSettings',
|
||||
{
|
||||
'length': 12,
|
||||
'useUppercase': true,
|
||||
'useLowercase': true,
|
||||
'useDigits': true,
|
||||
'useSpecialChars': true,
|
||||
'minimumDigitCount': 3,
|
||||
'avoidAmbiguousCharacters': false,
|
||||
'requireEveryCharType': true,
|
||||
'generateOnCreate': true,
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
var _settings = {
|
||||
pwSettings: {
|
||||
'length': 12,
|
||||
'useUppercase': true,
|
||||
'useLowercase': true,
|
||||
'useDigits': true,
|
||||
'useSpecialChars': true,
|
||||
'minimumDigitCount': 3,
|
||||
'avoidAmbiguousCharacters': false,
|
||||
'requireEveryCharType': true,
|
||||
'generateOnCreate': true,
|
||||
}
|
||||
};
|
||||
|
||||
$scope.vault_settings = angular.merge(_settings, $scope.active_vault.vault_settings);
|
||||
console.log($scope.vault_settings);
|
||||
|
||||
|
||||
$scope.saveVaultSettings = function () {
|
||||
var _vault = $scope.active_vault;
|
||||
_vault.vault_settings = angular.copy($scope.vault_settings);
|
||||
_vault.vault_settings = window.btoa(JSON.stringify(_vault.vault_settings));
|
||||
VaultService.updateVault(_vault).then(function () {
|
||||
VaultService.setActiveVault(_vault);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
$scope.tabs = [
|
||||
{
|
||||
title: 'General settings',
|
||||
|
@ -111,42 +106,32 @@ angular.module('passmanApp')
|
|||
}
|
||||
});
|
||||
|
||||
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;
|
||||
|
||||
}
|
||||
}
|
||||
if ($scope.active_vault) {
|
||||
$scope.$parent.selectedVault = true;
|
||||
|
||||
}
|
||||
|
||||
$rootScope.$on('logout', function () {
|
||||
$scope.selectedVault = false;
|
||||
});
|
||||
|
||||
$scope.startScan = function (minStrength) {
|
||||
VaultService.getVault($scope.active_vault).then(function (vault) {
|
||||
var results = [];
|
||||
for (var i = 0; i < vault.credentials.length; i++) {
|
||||
var c = CredentialService.decryptCredential(angular.copy(credentials[i]));
|
||||
if (c.password && c.password.length > 0 && c.hidden == 0) {
|
||||
var zxcvbn_result = zxcvbn(c.password);
|
||||
if (zxcvbn_result.score <= minStrength) {
|
||||
results.push({
|
||||
credential_id: c.credential_id,
|
||||
label: c.label,
|
||||
password: c.password,
|
||||
password_zxcvbn_result: zxcvbn_result
|
||||
});
|
||||
var c = angular.copy(vault.credentials[i]);
|
||||
if (c.password && c.hidden == 0) {
|
||||
c = CredentialService.decryptCredential(c);
|
||||
if(c.password){
|
||||
var zxcvbn_result = zxcvbn(c.password);
|
||||
if (zxcvbn_result.score <= minStrength) {
|
||||
results.push({
|
||||
credential_id: c.credential_id,
|
||||
label: c.label,
|
||||
password: c.password,
|
||||
password_zxcvbn_result: zxcvbn_result
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
//@todo loop custom fields (if any and check secret fields
|
||||
}
|
||||
|
|
|
@ -133,14 +133,18 @@ angular.module('passmanApp')
|
|||
};
|
||||
|
||||
scope.passwordNotNull = false;
|
||||
scope.$watch("settings", function () {
|
||||
if(scope.settings) {
|
||||
if (!scope.password && scope.settings.generateOnCreate) {
|
||||
scope.generatePasswordStart();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
scope.$watch("password", function () {
|
||||
scope.model = scope.password;
|
||||
scope.password_repeat = scope.model;
|
||||
|
||||
if(!scope.password) {
|
||||
console.log('Generating new pw');
|
||||
scope.generatePasswordStart();
|
||||
}
|
||||
});
|
||||
//
|
||||
scope.onSuccess = function(e) {
|
||||
|
|
|
@ -10,8 +10,9 @@
|
|||
angular.module('passmanApp')
|
||||
.service('VaultService', ['$http', function ($http) {
|
||||
// AngularJS will instantiate a singleton by calling "new" on this function
|
||||
var _this = this;
|
||||
var _activeVault;
|
||||
return {
|
||||
var service = {
|
||||
getVaults: function(){
|
||||
var queryUrl = OC.generateUrl('apps/passman/api/v2/vaults');
|
||||
return $http.get(queryUrl).then(function (response) {
|
||||
|
@ -23,7 +24,7 @@ angular.module('passmanApp')
|
|||
});
|
||||
},
|
||||
setActiveVault: function(vault){
|
||||
_activeVault = vault;
|
||||
_activeVault = angular.copy(vault);
|
||||
},
|
||||
getActiveVault: function(vault){
|
||||
return _activeVault;
|
||||
|
@ -32,7 +33,16 @@ angular.module('passmanApp')
|
|||
if(!_activeVault.vault_settings){
|
||||
return default_value
|
||||
} else {
|
||||
return _activeVault.vault_settings[key] | default_value;
|
||||
return (_activeVault.vault_settings[key] !== undefined) ? _activeVault.vault_settings[key] : default_value
|
||||
}
|
||||
|
||||
},
|
||||
setVaultSetting: function(key, value){
|
||||
if(!_activeVault.vault_settings){
|
||||
return false;
|
||||
} else {
|
||||
_activeVault.vault_settings[key] = value;
|
||||
_this.updateVault(_activeVault);
|
||||
}
|
||||
|
||||
},
|
||||
|
@ -52,6 +62,8 @@ angular.module('passmanApp')
|
|||
if(response.data){
|
||||
if(response.data.vault_settings){
|
||||
response.data.vault_settings = JSON.parse(window.atob(response.data.vault_settings))
|
||||
} else {
|
||||
response.data.vault_settings = {};
|
||||
}
|
||||
return response.data;
|
||||
} else {
|
||||
|
@ -63,7 +75,7 @@ angular.module('passmanApp')
|
|||
var _vault = angular.copy(vault);
|
||||
delete vault.defaultVaultPass;
|
||||
delete vault.defaultVault;
|
||||
|
||||
_vault.vault_settings = window.btoa(JSON.stringify(_vault.vault_settings))
|
||||
var queryUrl = OC.generateUrl('apps/passman/api/v2/vaults/' + _vault.vault_id);
|
||||
return $http.patch(queryUrl, _vault).then(function (response) {
|
||||
if(response.data){
|
||||
|
@ -93,5 +105,7 @@ angular.module('passmanApp')
|
|||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
return service;
|
||||
}]);
|
||||
|
|
Loading…
Add table
Reference in a new issue