This repository was archived by the owner on Sep 17, 2019. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathModuleABApp.js
More file actions
182 lines (173 loc) · 4.78 KB
/
Copy pathModuleABApp.js
File metadata and controls
182 lines (173 loc) · 4.78 KB
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
'use strict';
angular.module('ModuleAB', [
'ngRoute',
'ui.bootstrap',
'angular-loading-bar',
'ngAnimate',
'ModuleAB.appsets',
'ModuleAB.records',
'ModuleAB.policies',
'ModuleAB.hosts',
'ModuleAB.paths',
'ModuleAB.backupsets',
'ModuleAB.oss',
'ModuleAB.oas',
'ModuleAB.users',
'ModuleAB.clientjobs',
'ModuleAB.faillogs',
])
.config(['$routeProvider', function($routeProvider) {
$routeProvider.otherwise({
redirectTo: '/hosts'
});
}])
.config(['cfpLoadingBarProvider', function(cfpLoadingBarProvider) {
cfpLoadingBarProvider.includeSpinner = false;
}])
.controller("topNavBar", ['$scope', '$http', '$uibModal', '$rootScope',
'$window',
function($scope, $http, $uibModal, $rootScope, $window) {
$rootScope.dismiss = function() {
$rootScope.fadein = '';
};
$rootScope.dismiss();
$http({
method: "GET",
url: "/api/v1/auth/check"
}).then(function(response) {
$scope.session = response.data;
$rootScope.loaded = true;
}, function(response) {
$window.location.href = "/login";
});
$scope.logout = function() {
$http({
method: "GET",
url: "/api/v1/auth/logout"
}).then(function(response) {
$window.location.href = "/login";
}, function(response) {
switch (response.status) {
case 401:
$window.location.href = "/login";
break;
}
});
};
$scope.about = function() {
$uibModal.open({
templateUrl: "aboutModal.html",
controller: "aboutModal"
});
};
$scope.profile = function() {
$uibModal.open({
templateUrl: "userProfileModal.html",
controller: "userProfileModal",
resolve: {
session: function() {
return $scope.session;
}
}
});
};
}
])
.controller('aboutModal', function($scope, $http, $uibModalInstance) {
$http({
method: "GET",
url: "/api/v1/version"
}).then(function(response) {
$scope.version = response.data;
});
$scope.cancel = function() {
$uibModalInstance.dismiss('cancel');
};
})
.controller('userProfileModal', function($scope, $http, $uibModalInstance,
$window, session) {
$http({
method: "GET",
url: "/api/v1/users/" + session.name
}).then(function(response) {
$scope.user = response.data[0];
$scope.password2 = $scope.user.password;
}, function(response) {
$rootScope.alertType = 'alert-warning';
$rootScope.fadein = 'fadein-opacity';
switch (response.status) {
case 401:
$window.location.href = "/login";
break;
case 403:
$rootScope.failMessage = "没有权限";
break;
case 404:
$rootScope.failMessage = "无此用户";
break;
case 500:
$rootScope.failMessage = "服务器错误,见控制台输出";
console.log(response.data);
break;
default:
$rootScope.failMessage = "通讯故障";
break;
}
});
$scope.doJob = function() {
if ($scope.user.loginname == '') {
$scope.modalInfoFadein = "fadein-opacity";
$scope.modalInfoMsg = "登录名不能为空";
return;
}
if ($scope.user.name == '') {
$scope.modalInfoFadein = "fadein-opacity";
$scope.modalInfoMsg = "显示名不能为空";
return;
}
if (!$scope.user.password.match(/.{8,32}/)) {
$scope.modalInfoFadein = "fadein-opacity";
$scope.modalInfoMsg = "密码长度为8-32位!";
return;
}
if ($scope.user.password != $scope.password2) {
$scope.modalInfoFadein = "fadein-opacity";
$scope.modalInfoMsg = "两次输入的密码不一致!";
return;
}
$http({
method: "PUT",
url: "/api/v1/users/" + $scope.user.loginname,
data: $scope.user
}).then(function(response) {
$uibModalInstance.close(response.status);
}, function(response) {
$scope.modalInfoFadein = "fadein-opacity";
switch (response.status) {
case 400:
$scope.modalInfoMsg = "数据错误";
break;
case 401:
$scope.modalInfoMsg = "未登录";
window.location.href = "/login";
break;
case 403:
$scope.modalInfoMsg = "访问被拒绝";
break;
case 404:
$scope.modalInfoMsg = "无此用户";
break;
case 500:
$scope.modalInfoMsg = "服务器错误,见控制台输出";
console.log(response.data);
break;
default:
$scope.modalInfoMsg = "通讯故障";
break;
}
});
};
$scope.cancel = function() {
$uibModalInstance.dismiss('cancel');
};
});