2016-09-21 02:03:37 +08:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ngdoc function
|
|
|
|
* @name passmanApp.controller:MainCtrl
|
|
|
|
* @description
|
|
|
|
* # MainCtrl
|
|
|
|
* Controller of the passmanApp
|
|
|
|
*/
|
|
|
|
angular.module('passmanApp')
|
2016-09-23 18:03:37 +08:00
|
|
|
.controller('ShareCtrl', ['$scope', 'VaultService', 'CredentialService', 'SettingsService', '$location', '$routeParams', 'ShareService', function ($scope, VaultService, CredentialService, SettingsService, $location, $routeParams, ShareService) {
|
2016-09-21 02:03:37 +08:00
|
|
|
$scope.active_vault = VaultService.getActiveVault();
|
|
|
|
|
|
|
|
$scope.tabs = [{
|
|
|
|
title: 'Share with users and groups',
|
|
|
|
url: 'views/partials/forms/share_credential/basics.html',
|
|
|
|
}, {
|
|
|
|
title: 'Share link',
|
|
|
|
url: 'views/partials/forms/share_credential/expire_settings.html',
|
|
|
|
color: 'green'
|
|
|
|
}];
|
|
|
|
$scope.currentTab = {
|
|
|
|
title: 'General',
|
|
|
|
url: 'views/partials/forms/share_credential/basics.html'
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.onClickTab = function (tab) {
|
|
|
|
$scope.currentTab = tab;
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.isActiveTab = function (tab) {
|
|
|
|
return tab.url == $scope.currentTab.url;
|
|
|
|
};
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var storedCredential = SettingsService.getSetting('share_credential');
|
|
|
|
if (!storedCredential) {
|
|
|
|
$location.path('/vault/' + $routeParams.vault_id);
|
|
|
|
} else {
|
|
|
|
$scope.storedCredential = CredentialService.decryptCredential(angular.copy(storedCredential));
|
|
|
|
}
|
|
|
|
if ($scope.active_vault) {
|
|
|
|
$scope.$parent.selectedVault = true;
|
|
|
|
}
|
|
|
|
$scope.cancel = function(){
|
|
|
|
SettingsService.setSetting('share_credential', null);
|
|
|
|
$location.path('/vault/' + $scope.storedCredential.vault_id);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$scope.share_settings = {
|
2016-10-01 03:26:55 +08:00
|
|
|
credentialSharedWithUserAndGroup:[
|
2016-10-01 21:18:22 +08:00
|
|
|
{
|
|
|
|
accessLevel:1,
|
|
|
|
displayName:"wolf",
|
|
|
|
userId:"wolf",
|
|
|
|
type:'user'
|
|
|
|
},
|
2016-10-01 03:26:55 +08:00
|
|
|
{
|
|
|
|
accessLevel:1,
|
|
|
|
displayName:"cat",
|
|
|
|
userId:"cat",
|
|
|
|
type:'user'
|
|
|
|
}
|
|
|
|
],
|
|
|
|
cypher_progress:{
|
|
|
|
done:0,
|
|
|
|
total:0
|
|
|
|
}
|
2016-09-21 02:03:37 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
$scope.accessLevels = [
|
|
|
|
{
|
|
|
|
label: 'Can edit',
|
2016-09-27 02:49:30 +08:00
|
|
|
value: '2'
|
2016-09-21 02:03:37 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
label: 'Can view',
|
2016-09-27 02:49:30 +08:00
|
|
|
value: '1'
|
2016-09-21 02:03:37 +08:00
|
|
|
}
|
2016-09-23 18:03:37 +08:00
|
|
|
];
|
2016-09-21 02:03:37 +08:00
|
|
|
|
2016-09-23 18:03:37 +08:00
|
|
|
$scope.inputSharedWith = [];
|
2016-09-27 02:49:30 +08:00
|
|
|
$scope.selectedAccessLevel = '1';
|
2016-09-23 18:03:37 +08:00
|
|
|
|
|
|
|
$scope.searchUsers = function($query){
|
|
|
|
return ShareService.search($query)
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.shareWith = function(shareWith, selectedAccessLevel){
|
|
|
|
$scope.inputSharedWith = [];
|
|
|
|
if(shareWith.length > 0) {
|
|
|
|
for (var i = 0; i < shareWith.length; i++) {
|
2016-10-01 07:20:41 +08:00
|
|
|
var obj = {
|
|
|
|
userId: shareWith[i].uid,
|
|
|
|
displayName: shareWith[i].text,
|
|
|
|
type: shareWith[i].type,
|
|
|
|
accessLevel: selectedAccessLevel
|
|
|
|
};
|
2016-10-01 21:18:22 +08:00
|
|
|
// if (obj.type == 'group') obj.users = shareWith[i].users;
|
2016-09-23 18:03:37 +08:00
|
|
|
$scope.share_settings.credentialSharedWithUserAndGroup.push(
|
2016-10-01 07:20:41 +08:00
|
|
|
obj
|
2016-09-23 18:03:37 +08:00
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
2016-09-29 03:56:54 +08:00
|
|
|
};
|
2016-09-21 02:03:37 +08:00
|
|
|
|
2016-09-27 02:49:30 +08:00
|
|
|
$scope.applyShare = function(){
|
2016-10-01 21:18:22 +08:00
|
|
|
$scope.share_settings.cypher_progress.percent = 0;
|
2016-10-01 03:26:55 +08:00
|
|
|
$scope.share_settings.cypher_progress.done = 0;
|
|
|
|
$scope.share_settings.cypher_progress.total = 0;
|
2016-10-01 21:18:22 +08:00
|
|
|
$scope.share_settings.cypher_progress.times = [];
|
2016-10-02 01:04:05 +08:00
|
|
|
$scope.share_settings.cypher_progress.times_total = [];
|
2016-10-01 03:26:55 +08:00
|
|
|
|
2016-09-27 04:36:05 +08:00
|
|
|
ShareService.generateSharedKey(20).then(function(key){
|
|
|
|
console.log(key);
|
|
|
|
var list = $scope.share_settings.credentialSharedWithUserAndGroup;
|
|
|
|
console.log(list);
|
|
|
|
for (var i = 0; i < list.length; i++){
|
2016-10-01 07:20:41 +08:00
|
|
|
var iterator = i; // Keeps it available inside the promises callback
|
|
|
|
|
2016-09-29 07:12:39 +08:00
|
|
|
if (list[i].type == "user") {
|
|
|
|
ShareService.getVaultsByUser(list[i].userId).then(function (data) {
|
2016-10-01 03:26:55 +08:00
|
|
|
$scope.share_settings.cypher_progress.total += data.length;
|
|
|
|
|
2016-10-01 02:06:31 +08:00
|
|
|
list[iterator].vaults = data;
|
2016-09-29 03:56:54 +08:00
|
|
|
console.log(data);
|
2016-09-29 07:12:39 +08:00
|
|
|
var start = new Date().getTime() / 1000;
|
2016-10-01 01:47:22 +08:00
|
|
|
|
2016-09-29 07:12:39 +08:00
|
|
|
ShareService.cypherRSAStringWithPublicKeyBulkAsync(data, key)
|
|
|
|
.progress(function (data) {
|
2016-10-01 03:26:55 +08:00
|
|
|
$scope.share_settings.cypher_progress.done ++;
|
2016-10-01 21:18:22 +08:00
|
|
|
$scope.share_settings.cypher_progress.percent = $scope.share_settings.cypher_progress.done / $scope.share_settings.cypher_progress.total * 100;
|
2016-10-01 03:26:55 +08:00
|
|
|
$scope.$digest();
|
2016-09-29 07:12:39 +08:00
|
|
|
})
|
|
|
|
.then(function (result) {
|
|
|
|
console.log(result);
|
|
|
|
console.log("Took: " + ((new Date().getTime() / 1000) - start) + "s to cypher the string for user [" + data[0].user_id + "]");
|
2016-10-01 21:18:22 +08:00
|
|
|
$scope.share_settings.cypher_progress.times.push({
|
|
|
|
time: ((new Date().getTime() / 1000) - start),
|
|
|
|
user: data[0].user_id
|
|
|
|
});
|
|
|
|
$scope.$digest();
|
2016-09-29 07:12:39 +08:00
|
|
|
});
|
2016-09-29 03:56:54 +08:00
|
|
|
});
|
2016-09-29 07:12:39 +08:00
|
|
|
}
|
2016-09-27 04:36:05 +08:00
|
|
|
}
|
|
|
|
})
|
2016-09-29 07:12:39 +08:00
|
|
|
};
|
2016-10-02 01:04:05 +08:00
|
|
|
|
|
|
|
$scope.calculate_total_time = function(){
|
|
|
|
$scope.share_settings.cypher_progress.times = $scope.share_settings.cypher_progress.times || [];
|
|
|
|
var total = 0;
|
|
|
|
for (var i = 0; i < $scope.share_settings.cypher_progress.times.length; i++){
|
|
|
|
total += $scope.share_settings.cypher_progress.times[i].time;
|
|
|
|
}
|
|
|
|
console.log(total);
|
|
|
|
return total;
|
|
|
|
}
|
2016-09-21 02:03:37 +08:00
|
|
|
}]);
|