|
1
|
|
|
/** |
|
2
|
|
|
* Nextcloud - passman |
|
3
|
|
|
* |
|
4
|
|
|
* @copyright Copyright (c) 2016, Sander Brand ([email protected]) |
|
5
|
|
|
* @copyright Copyright (c) 2016, Marcos Zuriaga Miguel ([email protected]) |
|
6
|
|
|
* @license GNU AGPL version 3 or any later version |
|
7
|
|
|
* |
|
8
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
9
|
|
|
* it under the terms of the GNU Affero General Public License as |
|
10
|
|
|
* published by the Free Software Foundation, either version 3 of the |
|
11
|
|
|
* License, or (at your option) any later version. |
|
12
|
|
|
* |
|
13
|
|
|
* This program is distributed in the hope that it will be useful, |
|
14
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16
|
|
|
* GNU Affero General Public License for more details. |
|
17
|
|
|
* |
|
18
|
|
|
* You should have received a copy of the GNU Affero General Public License |
|
19
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
20
|
|
|
* |
|
21
|
|
|
*/ |
|
22
|
|
|
|
|
23
|
|
|
(function () { |
|
24
|
|
|
'use strict'; |
|
25
|
|
|
/** |
|
26
|
|
|
* @ngdoc directive |
|
27
|
|
|
* @name passmanApp.directive:passwordGen |
|
28
|
|
|
* @description |
|
29
|
|
|
* # passwordGen |
|
30
|
|
|
*/ |
|
31
|
|
|
angular.module('passmanApp') |
|
32
|
|
|
.directive('credentialTemplate', ['EncryptService', '$translate', 'FileService', 'ShareService', 'NotificationService', 'CredentialService', |
|
33
|
|
|
function (EncryptService, $translate, FileService, ShareService, NotificationService, CredentialService) { |
|
34
|
|
|
return { |
|
35
|
|
|
templateUrl: 'views/partials/credential_template.html', |
|
36
|
|
|
replace: true, |
|
37
|
|
|
restrict: 'A', |
|
38
|
|
|
scope: { |
|
39
|
|
|
credential: '=credentialTemplate' |
|
40
|
|
|
}, |
|
41
|
|
|
|
|
42
|
|
|
link: function (scope, element, attrs) { |
|
43
|
|
|
scope.downloadFile = function (credential, file) { |
|
44
|
|
|
var callback = function (result) { |
|
45
|
|
|
var key = CredentialService.getSharedKeyFromCredential(credential); |
|
46
|
|
|
if (!result.hasOwnProperty('file_data')) { |
|
47
|
|
|
NotificationService.showNotification($translate.instant('error.loading.file.perm'), 5000); |
|
48
|
|
|
return; |
|
49
|
|
|
|
|
50
|
|
|
} |
|
51
|
|
|
var file_data = EncryptService.decryptString(result.file_data, key); |
|
52
|
|
|
download(file_data, escapeHTML(file.filename), file.mimetype); |
|
53
|
|
|
|
|
54
|
|
|
}; |
|
55
|
|
|
|
|
56
|
|
|
if (!credential.hasOwnProperty('acl')) { |
|
57
|
|
|
FileService.getFile(file).then(callback); |
|
58
|
|
|
} else { |
|
59
|
|
|
ShareService.downloadSharedFile(credential, file).then(callback); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
}; |
|
63
|
|
|
|
|
64
|
|
|
scope.showLabel = (attrs.hasOwnProperty('showLabel')); |
|
65
|
|
|
} |
|
66
|
|
|
}; |
|
67
|
|
|
}]); |
|
68
|
|
|
}()); |