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