-
-
Notifications
You must be signed in to change notification settings - Fork 81
/
Copy pathheader-controller.js
86 lines (74 loc) · 3.14 KB
/
header-controller.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
angular
.module('nzbhydraApp')
.controller('HeaderController', HeaderController);
function HeaderController($scope, $state, growl, HydraAuthService, bootstrapped) {
$scope.showLoginout = false;
$scope.oldUserName = null;
$scope.bootstrapped = bootstrapped;
function update(event) {
$scope.userInfos = HydraAuthService.getUserInfos();
if (!$scope.userInfos.authConfigured) {
$scope.showSearch = true;
$scope.showAdmin = true;
$scope.showStats = true;
$scope.showLoginout = false;
} else {
if ($scope.userInfos.username) {
$scope.showSearch = true;
$scope.showAdmin = $scope.userInfos.maySeeAdmin || !$scope.userInfos.adminRestricted;
$scope.showStats = $scope.userInfos.maySeeStats || !$scope.userInfos.statsRestricted;
$scope.showLoginout = true;
$scope.username = $scope.userInfos.username;
$scope.loginlogoutText = "Logout " + $scope.username;
$scope.oldUserName = $scope.username;
} else {
$scope.showAdmin = !$scope.userInfos.adminRestricted;
$scope.showStats = !$scope.userInfos.statsRestricted;
$scope.showSearch = !$scope.userInfos.searchRestricted;
$scope.loginlogoutText = "Login";
$scope.showLoginout = ($scope.userInfos.adminRestricted || $scope.userInfos.statsRestricted || $scope.userInfos.searchRestricted) && event !== "loggedOut" && !$state.is("root.login");
$scope.username = "";
}
}
}
update();
$scope.$on("user:loggedIn", function (event, data) {
update("loggedIn");
});
$scope.$on("user:loggedOut", function (event, data) {
update("loggedOut");
});
$scope.loginout = function () {
if (HydraAuthService.isLoggedIn()) {
HydraAuthService.logout().then(function () {
if ($scope.userInfos.authType === "BASIC") {
growl.info("Logged out. Close your browser to make sure session is closed.");
}
else if ($scope.userInfos.authType === "FORM") {
growl.info("Logged out");
}
update();
//$state.go("root.search", null, {reload: true});
});
} else {
if ($scope.userInfos.authType === "BASIC") {
var params = {};
if ($scope.oldUserName) {
params = {
old_username: $scope.oldUserName
}
}
HydraAuthService.askForPassword(params).then(function () {
growl.info("Login successful!");
$scope.oldUserName = null;
update("loggedIn");
$state.go("root.search");
})
} else if ($scope.userInfos.authType === "FORM") {
$state.go("root.login");
} else {
growl.info("You shouldn't need to login but here you go!");
}
}
};
}