passman/js/app/controllers/settings.js

148 lines
4 KiB
JavaScript
Raw Normal View History

2016-09-25 02:16:57 +08:00
'use strict';
/**
* @ngdoc function
* @name passmanApp.controller:SettingsCtrl
* @description
* # SettingsCtrl
* Controller of the passmanApp
*/
angular.module('passmanApp')
2016-09-29 04:05:09 +08:00
.controller('SettingsCtrl', ['$scope', '$rootScope', 'SettingsService', 'VaultService', 'CredentialService', '$location', '$routeParams', '$http', 'EncryptService',
function ($scope, $rootScope, SettingsService, VaultService, CredentialService, $location, $routeParams, $http, EncryptService) {
2016-09-29 05:23:24 +08:00
$scope.vault_settings = {};
2016-09-29 04:05:09 +08:00
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'));
2016-09-29 05:23:24 +08:00
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,
})
})
2016-09-29 04:05:09 +08:00
}
}
$scope.saveVaultSettings = function () {
var _vault = $scope.active_vault;
_vault.vault_settings = angular.copy($scope.vault_settings);
VaultService.updateVault(_vault).then(function () {
2016-09-29 04:15:03 +08:00
VaultService.setActiveVault(_vault);
2016-09-29 04:05:09 +08:00
});
};
2016-09-25 06:01:23 +08:00
$scope.tabs = [
{
title: 'General settings',
url: 'views/partials/forms/settings/general_settings.html'
},
{
2016-09-29 01:51:36 +08:00
title: 'Password Audit',
2016-09-25 06:01:23 +08:00
url: 'views/partials/forms/settings/tool.html'
2016-09-25 02:47:47 +08:00
2016-09-29 04:05:09 +08:00
},
{
title: 'Password settings',
url: 'views/partials/forms/settings/password_settings.html'
2016-09-25 06:01:23 +08:00
},
2016-09-25 02:47:47 +08:00
{
title: 'Import credentials',
url: 'views/partials/forms/settings/import.html'
},
{
title: 'Export credentials',
url: 'views/partials/forms/settings/export.html'
},
{
title: 'Sharing',
2016-09-29 04:05:09 +08:00
url: 'views/partials/forms/settings/sharing.html'
}
];
2016-09-25 02:47:47 +08:00
2016-09-26 00:21:28 +08:00
$scope.currentTab = $scope.tabs[0];
2016-09-25 02:47:47 +08:00
$scope.onClickTab = function (tab) {
$scope.currentTab = tab;
};
$scope.isActiveTab = function (tab) {
return tab.url == $scope.currentTab.url;
};
var getPassmanVersion = function () {
var url = OC.generateUrl('apps/passman/api/internal/version');
2016-09-25 06:01:23 +08:00
$http.get(url).then(function (result) {
2016-09-25 02:47:47 +08:00
$scope.passman_version = result.data.version;
})
};
getPassmanVersion();
$scope.$watch(function () {
return VaultService.getActiveVault()
}, function (vault) {
2016-09-29 04:05:09 +08:00
if (vault) {
2016-09-25 23:19:05 +08:00
$scope.active_vault = vault;
}
2016-09-25 02:47:47 +08:00
});
if ($scope.active_vault) {
2016-09-29 05:23:24 +08:00
2016-09-25 02:16:57 +08:00
}
2016-09-25 02:47:47 +08:00
$rootScope.$on('logout', function () {
$scope.selectedVault = false;
});
$scope.startScan = function (minStrength) {
2016-09-29 02:28:34 +08:00
VaultService.getVault($scope.active_vault).then(function (vault) {
2016-09-25 02:47:47 +08:00
var results = [];
2016-09-29 02:28:34 +08:00
for (var i = 0; i < vault.credentials.length; i++) {
2016-09-29 05:23:24 +08:00
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
});
}
2016-09-25 02:47:47 +08:00
}
2016-09-29 05:23:24 +08:00
2016-09-25 02:16:57 +08:00
}
2016-09-25 02:47:47 +08:00
//@todo loop custom fields (if any and check secret fields
2016-09-25 02:16:57 +08:00
}
2016-09-25 02:47:47 +08:00
$scope.scan_result = results;
});
};
2016-09-25 02:16:57 +08:00
2016-09-25 02:47:47 +08:00
$scope.cancel = function () {
$location.path('/vault/' + $routeParams.vault_id);
};
2016-09-25 02:16:57 +08:00
2016-09-25 02:47:47 +08:00
}]);
2016-09-25 02:16:57 +08:00