-
Notifications
You must be signed in to change notification settings - Fork 248
Expand file tree
/
Copy pathUserAPIUser.class.php
More file actions
184 lines (174 loc) · 5.43 KB
/
UserAPIUser.class.php
File metadata and controls
184 lines (174 loc) · 5.43 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
183
184
<?php
class UserAPIUser extends UserAPIBasic {
public function execute($QUERY = array()) {
try {
switch ($QUERY[UQuery::REQUEST]) {
case USectionUser::LIST_USERS:
$this->listUsers($QUERY);
break;
case USectionUser::GET_USER:
$this->getUser($QUERY);
break;
case USectionUser::CREATE_USER:
$this->createUser($QUERY);
break;
case USectionUser::DISABLE_USER:
$this->disableUser($QUERY);
break;
case USectionUser::ENABLE_USER:
$this->enableUser($QUERY);
break;
case USectionUser::DISABLE_LDAP:
$this->disableLDAP($QUERY);
break;
case USectionUser::ENABLE_LDAP:
$this->enableLDAP($QUERY);
break;
case USectionUser::SET_USER_PASSWORD:
$this->setUserPassword($QUERY);
break;
case USectionUser::SET_USER_RIGHT_GROUP:
$this->setRightGroup($QUERY);
break;
default:
$this->sendErrorResponse($QUERY[UQuery::SECTION], "INV", "Invalid section request!");
}
}
catch (HTException $e) {
$this->sendErrorResponse($QUERY[UQueryTask::SECTION], $QUERY[UQueryTask::REQUEST], $e->getMessage());
}
}
/**
* @param array $QUERY
* @throws HTException
*/
private function setRightGroup($QUERY) {
if (!isset($QUERY[UQueryUser::USER_ID]) || !isset($QUERY[UQueryUser::USER_RIGHT_GROUP_ID])) {
throw new HTException("Invalid query!");
}
UserUtils::setRights($QUERY[UQueryUser::USER_ID], $QUERY[UQueryUser::USER_RIGHT_GROUP_ID], $this->user);
$this->sendSuccessResponse($QUERY);
}
/**
* @param array $QUERY
* @throws HTException
*/
private function setUserPassword($QUERY) {
if (!isset($QUERY[UQueryUser::USER_ID]) || !isset($QUERY[UQueryUser::USER_PASSWORD])) {
throw new HTException("Invalid query!");
}
UserUtils::setPassword($QUERY[UQueryUser::USER_ID], $QUERY[UQueryUser::USER_PASSWORD], $this->user);
$this->sendSuccessResponse($QUERY);
}
/**
* @param array $QUERY
* @throws HTException
*/
private function enableUser($QUERY) {
if (!isset($QUERY[UQueryUser::USER_ID])) {
throw new HTException("Invalid query!");
}
UserUtils::enableUser($QUERY[UQueryUser::USER_ID]);
$this->sendSuccessResponse($QUERY);
}
/**
* @param array $QUERY
* @throws HTException
*/
private function disableUser($QUERY) {
if (!isset($QUERY[UQueryUser::USER_ID])) {
throw new HTException("Invalid query!");
}
UserUtils::disableUser($QUERY[UQueryUser::USER_ID], $this->user);
$this->sendSuccessResponse($QUERY);
}
/**
* @param array $QUERY
* @throws HTException
*/
private function enableLDAP($QUERY) {
if (!isset($QUERY[UQueryUser::USER_ID])) {
throw new HTException("Invalid query!");
}
UserUtils::enableLDAP($QUERY[UQueryUser::USER_ID]);
$this->sendSuccessResponse($QUERY);
}
/**
* @param array $QUERY
* @throws HTException
*/
private function disableLDAP($QUERY) {
if (!isset($QUERY[UQueryUser::USER_ID])) {
throw new HTException("Invalid query!");
}
UserUtils::disableLDAP($QUERY[UQueryUser::USER_ID], $this->user);
$this->sendSuccessResponse($QUERY);
}
/**
* @param array $QUERY
* @throws HTException
*/
private function createUser($QUERY) {
$toCheck = [
UQueryUser::USER_USERNAME,
UQueryUser::USER_EMAIL,
UQueryUser::RIGHT_GROUP_ID
];
foreach ($toCheck as $input) {
if (!isset($QUERY[$input])) {
throw new HTException("Invalid query!");
}
}
UserUtils::createUser(
$QUERY[UQueryUser::USER_USERNAME],
$QUERY[UQueryUser::USER_EMAIL],
$QUERY[UQueryUser::RIGHT_GROUP_ID],
$this->user
);
$this->sendSuccessResponse($QUERY);
}
/**
* @param array $QUERY
* @throws HTException
*/
private function getUser($QUERY) {
if (!isset($QUERY[UQueryUser::USER_ID])) {
throw new HTException("Invalid query!");
}
$user = UserUtils::getUser($QUERY[UQueryUser::USER_ID]);
$response = [
UResponseUser::SECTION => $QUERY[UQueryUser::SECTION],
UResponseUser::REQUEST => $QUERY[UQueryUser::REQUEST],
UResponseUser::RESPONSE => UValues::OK,
UResponseUser::USER_ID => (int)$user->getId(),
UResponseUser::USER_USERNAME => $user->getUsername(),
UResponseUser::USER_EMAIL => $user->getEmail(),
UResponseUser::USER_RIGHT_GROUP_ID => (int)$user->getRightGroupId(),
UResponseUser::USER_REGISTERED => (int)$user->getRegisteredSince(),
UResponseUser::USER_LAST_LOGIN => (int)$user->getLastLoginDate(),
UResponseUser::USER_IS_VALID => ($user->getIsValid() == 1) ? true : false,
UResponseUser::USER_SESSION_LIFETIME => (int)$user->getSessionLifetime()
];
$this->sendResponse($response);
}
/**
* @param array $QUERY
*/
private function listUsers($QUERY) {
$users = UserUtils::getUsers();
$list = [];
$response = [
UResponseUser::SECTION => $QUERY[UQueryUser::SECTION],
UResponseUser::REQUEST => $QUERY[UQueryUser::REQUEST],
UResponseUser::RESPONSE => UValues::OK
];
foreach ($users as $user) {
$list[] = [
UResponseUser::USERS_ID => (int)$user->getId(),
UResponseUser::USERS_USERNAME => $user->getUsername()
];
}
$response[UResponseUser::USERS] = $list;
$this->sendResponse($response);
}
}