Completed
Push — phpunit ( 7f2080...75f541 )
by Marcos
14:28 queued 10:45
created

angular.controller(ꞌPublicSharedCredentialꞌ)   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
(function () {
2
	'use strict';
3
4
	/**
5
	 * @ngdoc function
6
	 * @name passmanApp.controller:MainCtrl
7
	 * @description
8
	 * # MainCtrl
9
	 * Controller of the passmanApp
10
	 */
11
	angular.module('passmanApp')
12
		.controller('PublicSharedCredential', ['$scope', 'ShareService', '$window', 'EncryptService', 'NotificationService', function ($scope, ShareService, $window, EncryptService, NotificationService) {
13
			var _key;
14
			$scope.loading = false;
15
			$scope.loadSharedCredential = function () {
16
				$scope.loading = true;
17
				var data = window.atob($window.location.hash.replace('#', '')).split('<::>');
18
				var guid = data[0];
19
				_key = data[1];
20
				ShareService.getPublicSharedCredential(guid).then(function (sharedCredential) {
21
					$scope.loading = false;
22
					if (sharedCredential.status === 200) {
23
						$scope.shared_credential = ShareService.decryptSharedCredential(sharedCredential.data.credential_data, _key);
24
					} else {
25
						$scope.expired = true;
26
					}
27
28
				});
29
30
			};
31
32
			$scope.downloadFile = function (credential, file) {
33
				ShareService.downloadSharedFile(credential, file).then(function (result) {
34
					if (!result.hasOwnProperty('file_data')) {
35
						NotificationService.showNotification('Error downloading file, you probably don\'t have enough permissions', 5000);
36
						return;
37
					}
38
					var file_data = EncryptService.decryptString(result.file_data, _key);
39
					download(file_data, escapeHTML(file.filename), file.mimetype);
40
				});
41
			};
42
		}]);
43
}());
44