Completed
Pull Request — master (#214)
by Sander
04:14
created

angular.controller(ꞌMainCtrlꞌ)   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 1
rs 10
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
	/**
27
	 * @ngdoc function
28
	 * @name passmanApp.controller:MainCtrl
29
	 * @description
30
	 * # MainCtrl
31
	 * Controller of the passmanApp
32
	 */
33
	angular.module('passmanApp')
34
		.controller('MainCtrl', ['$scope', '$rootScope', '$location', 'SettingsService', '$window', '$interval', '$filter', function ($scope, $rootScope, $location, SettingsService, $window, $interval, $filter) {
35
			$scope.selectedVault = false;
36
37
			$scope.http_warning_hidden = true;
38
			if ($location.$$protocol === 'http' && $location.$$host !== 'localhost' && $location.$host !== '127.0.0.1') {
39
				$scope.using_http = true;
40
				$scope.http_warning_hidden = false;
41
42
			}
43
44
			$rootScope.$on('settings_loaded', function(){
45
				if (SettingsService.isEnabled('disable_contextmenu')) {
46
					document.addEventListener('contextmenu', function (event) {
47
						event.preventDefault();
48
					});
49
				}
50
				if (SettingsService.isEnabled('https_check')) {
51
					$scope.http_warning_hidden = true;
52
				}
53
54
				if(SettingsService.isEnabled('disable_debugger')){
55
					(function a() {
56
						try {
57
							(function b(i) {
58
								if (('' + (i / i)).length !== 1 || i % 20 === 0) {
59
									(function() {}).constructor('debugger')();
60
								} else {
61
									// This debugger statement is allowed to block javascript console
62
									/*jshint -W087 */
63
									debugger;
64
								}
65
								b(++i);
66
							})(0);
67
						} catch (e) {
68
							setTimeout(a, 5000);
69
						}
70
					})();
71
				}
72
			});
73
74
			$rootScope.setHttpWarning = function (state) {
75
				$scope.http_warning_hidden = state;
76
			};
77
78
			$rootScope.$on('app_menu', function (evt, shown) {
79
				$scope.app_sidebar = shown;
80
			});
81
82
			$rootScope.$on('logout', function () {
83
				$scope.selectedVault = false;
84
			});
85
86
			var tickSessionTimer = function(){
87
				if($scope.session_time_left){
88
					$scope.session_time_left--;
89
					var session_time_left_formatted = $filter('toHHMMSS')($scope.session_time_left);
90
					$scope.translationData = {
91
						session_time: session_time_left_formatted
92
					};
93
					$rootScope.$broadcast('logout_timer_tick_tack', $scope.session_time_left);
94
					if($scope.session_time_left === 0){
95
						$window.location.reload();
96
					}
97
				}
98
			};
99
100
			$scope.session_time_left = false;
101
			$scope.$on('logout_timer_set', function(evt, timer){
102
				$scope.session_time_left = timer;
103
				$scope.translationData = {
104
					session_time: timer
105
				};
106
				$interval(tickSessionTimer, 1000);
107
			});
108
109
		}]);
110
111
}());