@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | $this->close(); |
123 | 123 | $this->newDoc = false; |
124 | 124 | |
125 | - if (!$find = $this->findUser($id)) { |
|
125 | + if ( ! $find = $this->findUser($id)) { |
|
126 | 126 | $this->id = null; |
127 | 127 | } else { |
128 | 128 | $this->set('editedon', time()); |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | */ |
155 | 155 | public function set($key, $value) |
156 | 156 | { |
157 | - if (is_scalar($value) && is_scalar($key) && !empty($key)) { |
|
157 | + if (is_scalar($value) && is_scalar($key) && ! empty($key)) { |
|
158 | 158 | switch ($key) { |
159 | 159 | case 'password': |
160 | 160 | $this->givenPassword = $value; |
@@ -207,20 +207,20 @@ discard block |
||
207 | 207 | return false; |
208 | 208 | } |
209 | 209 | |
210 | - if (!$this->checkUnique('manager_users', 'username')) { |
|
210 | + if ( ! $this->checkUnique('manager_users', 'username')) { |
|
211 | 211 | $this->log['UniqueUsername'] = 'username not unique <pre>' . print_r($this->get('username'), |
212 | 212 | true) . '</pre>'; |
213 | 213 | |
214 | 214 | return false; |
215 | 215 | } |
216 | 216 | |
217 | - if (!$this->checkUnique('user_attributes', 'email', 'internalKey')) { |
|
217 | + if ( ! $this->checkUnique('user_attributes', 'email', 'internalKey')) { |
|
218 | 218 | $this->log['UniqueEmail'] = 'Email not unique <pre>' . print_r($this->get('email'), true) . '</pre>'; |
219 | 219 | |
220 | 220 | return false; |
221 | 221 | } |
222 | 222 | |
223 | - if(!$this->get('role')) { |
|
223 | + if ( ! $this->get('role')) { |
|
224 | 224 | $this->log['UniqueEmail'] = 'Wrong manager role <pre>' . print_r($this->get('role'), true) . '</pre>'; |
225 | 225 | } |
226 | 226 | |
@@ -228,13 +228,13 @@ discard block |
||
228 | 228 | $fld = $this->toArray(); |
229 | 229 | foreach ($this->default_field['user'] as $key => $value) { |
230 | 230 | $tmp = $this->get($key); |
231 | - if ($this->newDoc && (!is_int($tmp) && $tmp == '')) { |
|
231 | + if ($this->newDoc && ( ! is_int($tmp) && $tmp == '')) { |
|
232 | 232 | $this->field[$key] = $value; |
233 | 233 | } |
234 | 234 | $this->Uset($key, 'user'); |
235 | 235 | unset($fld[$key]); |
236 | 236 | } |
237 | - if (!empty($this->set['user'])) { |
|
237 | + if ( ! empty($this->set['user'])) { |
|
238 | 238 | if ($this->newDoc) { |
239 | 239 | $SQL = "INSERT into {$this->makeTable('manager_users')} SET " . implode(', ', $this->set['user']); |
240 | 240 | } else { |
@@ -250,13 +250,13 @@ discard block |
||
250 | 250 | |
251 | 251 | foreach ($this->default_field['attribute'] as $key => $value) { |
252 | 252 | $tmp = $this->get($key); |
253 | - if ($this->newDoc && (!is_int($tmp) && $tmp == '')) { |
|
253 | + if ($this->newDoc && ( ! is_int($tmp) && $tmp == '')) { |
|
254 | 254 | $this->field[$key] = $value; |
255 | 255 | } |
256 | 256 | $this->Uset($key, 'attribute'); |
257 | 257 | unset($fld[$key]); |
258 | 258 | } |
259 | - if (!empty($this->set['attribute'])) { |
|
259 | + if ( ! empty($this->set['attribute'])) { |
|
260 | 260 | if ($this->newDoc) { |
261 | 261 | $this->set('internalKey', $this->id)->Uset('internalKey', 'attribute'); |
262 | 262 | $SQL = "INSERT into {$this->makeTable('user_attributes')} SET " . implode(', ', |
@@ -269,7 +269,7 @@ discard block |
||
269 | 269 | } |
270 | 270 | unset($fld['id']); |
271 | 271 | foreach ($fld as $key => $value) { |
272 | - if ($value == '' || !$this->isChanged($key)) { |
|
272 | + if ($value == '' || ! $this->isChanged($key)) { |
|
273 | 273 | continue; |
274 | 274 | } |
275 | 275 | $result = $this->query("SELECT `setting_value` FROM {$this->makeTable('user_settings')} WHERE `user` = '{$this->id}' AND `setting_name` = '{$key}'"); |
@@ -280,7 +280,7 @@ discard block |
||
280 | 280 | } |
281 | 281 | } |
282 | 282 | // TODO |
283 | - if (!$this->newDoc && $this->givenPassword) { |
|
283 | + if ( ! $this->newDoc && $this->givenPassword) { |
|
284 | 284 | $this->invokeEvent('OnManagerChangePassword', array( |
285 | 285 | 'userObj' => $this, |
286 | 286 | 'userid' => $this->id, |
@@ -386,7 +386,7 @@ discard block |
||
386 | 386 | $b = $tmp->get('blocked'); |
387 | 387 | $bu = $tmp->get('blockeduntil'); |
388 | 388 | $ba = $tmp->get('blockedafter'); |
389 | - $flag = (($b && !$bu && !$ba) || ($bu && $now < $bu) || ($ba && $now > $ba)); |
|
389 | + $flag = (($b && ! $bu && ! $ba) || ($bu && $now < $bu) || ($ba && $now > $ba)); |
|
390 | 390 | unset($tmp); |
391 | 391 | |
392 | 392 | return $flag; |
@@ -408,7 +408,7 @@ discard block |
||
408 | 408 | |
409 | 409 | $flag = $pluginFlag = false; |
410 | 410 | if ( |
411 | - (null !== $tmp->getID()) && (!$blocker || ($blocker && !$tmp->checkBlock($id))) |
|
411 | + (null !== $tmp->getID()) && ( ! $blocker || ($blocker && ! $tmp->checkBlock($id))) |
|
412 | 412 | ) { |
413 | 413 | $_password = $tmp->get('password'); |
414 | 414 | $eventResult = $this->getInvokeEventResult('OnManagerAuthentication', array( |
@@ -425,7 +425,7 @@ discard block |
||
425 | 425 | } else { |
426 | 426 | $pluginFlag = (bool)$eventResult; |
427 | 427 | } |
428 | - if (!$pluginFlag) { |
|
428 | + if ( ! $pluginFlag) { |
|
429 | 429 | $hashType = $this->getPasswordHashType($_password); |
430 | 430 | switch ($hashType) { |
431 | 431 | case 'phpass': |
@@ -462,7 +462,7 @@ discard block |
||
462 | 462 | */ |
463 | 463 | public function logOut($cookieName = 'modx_remember_manager', $fire_events = null) |
464 | 464 | { |
465 | - if (!$uid = $this->modx->getLoginUserID('mgr')) { |
|
465 | + if ( ! $uid = $this->modx->getLoginUserID('mgr')) { |
|
466 | 466 | return; |
467 | 467 | } |
468 | 468 | $params = array( |
@@ -556,7 +556,7 @@ discard block |
||
556 | 556 | */ |
557 | 557 | public function setAutoLoginCookie($cookieName, $remember = true) |
558 | 558 | { |
559 | - if (!empty($cookieName) && $this->getID()) { |
|
559 | + if ( ! empty($cookieName) && $this->getID()) { |
|
560 | 560 | $secure = $this->isSecure(); |
561 | 561 | $remember = is_bool($remember) ? (60 * 60 * 24 * 365 * 5) : (int)$remember; |
562 | 562 | $cookieValue = $this->get('username'); |
@@ -620,7 +620,7 @@ discard block |
||
620 | 620 | */ |
621 | 621 | public function setUserGroups($userID = 0, $groupIds = array()) |
622 | 622 | { |
623 | - if (!is_array($groupIds)) { |
|
623 | + if ( ! is_array($groupIds)) { |
|
624 | 624 | return $this; |
625 | 625 | } |
626 | 626 | if ($this->newDoc && $userID == 0) { |
@@ -631,7 +631,7 @@ discard block |
||
631 | 631 | foreach ($groupIds as $gid) { |
632 | 632 | $this->query("REPLACE INTO {$this->makeTable('member_groups')} (`user_group`, `member`) VALUES ('{$gid}', '{$uid}')"); |
633 | 633 | } |
634 | - if (!$this->newDoc) { |
|
634 | + if ( ! $this->newDoc) { |
|
635 | 635 | $groupIds = empty($groupIds) ? '0' : implode(',', $groupIds); |
636 | 636 | $this->query("DELETE FROM {$this->makeTable('member_groups')} WHERE `member`={$uid} AND `user_group` NOT IN ({$groupIds})"); |
637 | 637 | } |
@@ -4,8 +4,8 @@ discard block |
||
4 | 4 | /** |
5 | 5 | * Class modUsers |
6 | 6 | */ |
7 | -class modManagers extends MODxAPI |
|
8 | -{ |
|
7 | +class modManagers extends MODxAPI |
|
8 | +{ |
|
9 | 9 | /** |
10 | 10 | * @var array |
11 | 11 | */ |
@@ -59,8 +59,8 @@ discard block |
||
59 | 59 | * @param bool $debug |
60 | 60 | * @throws Exception |
61 | 61 | */ |
62 | - public function __construct(DocumentParser $modx, $debug = false) |
|
63 | - { |
|
62 | + public function __construct(DocumentParser $modx, $debug = false) |
|
63 | + { |
|
64 | 64 | parent::__construct($modx, $debug); |
65 | 65 | $this->modx->loadExtension('phpass'); |
66 | 66 | } |
@@ -70,8 +70,8 @@ discard block |
||
70 | 70 | * @param $key |
71 | 71 | * @return bool |
72 | 72 | */ |
73 | - public function issetField($key) |
|
74 | - { |
|
73 | + public function issetField($key) |
|
74 | + { |
|
75 | 75 | return (array_key_exists($key, $this->default_field['user']) || array_key_exists($key, |
76 | 76 | $this->default_field['attribute']) || in_array($key, $this->default_field['hidden'])); |
77 | 77 | } |
@@ -80,9 +80,9 @@ discard block |
||
80 | 80 | * @param string $data |
81 | 81 | * @return string|false |
82 | 82 | */ |
83 | - protected function findUser($data) |
|
84 | - { |
|
85 | - switch (true) { |
|
83 | + protected function findUser($data) |
|
84 | + { |
|
85 | + switch (true) { |
|
86 | 86 | case (is_int($data) || ((int)$data > 0 && (string)intval($data) === $data)): |
87 | 87 | $find = 'attribute.internalKey'; |
88 | 88 | break; |
@@ -103,8 +103,8 @@ discard block |
||
103 | 103 | * @param array $data |
104 | 104 | * @return $this |
105 | 105 | */ |
106 | - public function create($data = array()) |
|
107 | - { |
|
106 | + public function create($data = array()) |
|
107 | + { |
|
108 | 108 | parent::create($data); |
109 | 109 | $this->set('createdon', time()); |
110 | 110 | |
@@ -115,16 +115,16 @@ discard block |
||
115 | 115 | * @param $id |
116 | 116 | * @return $this |
117 | 117 | */ |
118 | - public function edit($id) |
|
119 | - { |
|
118 | + public function edit($id) |
|
119 | + { |
|
120 | 120 | $id = is_scalar($id) ? trim($id) : ''; |
121 | - if ($this->getID() != $id) { |
|
121 | + if ($this->getID() != $id) { |
|
122 | 122 | $this->close(); |
123 | 123 | $this->newDoc = false; |
124 | 124 | |
125 | - if (!$find = $this->findUser($id)) { |
|
125 | + if (!$find = $this->findUser($id)) { |
|
126 | 126 | $this->id = null; |
127 | - } else { |
|
127 | + } else { |
|
128 | 128 | $this->set('editedon', time()); |
129 | 129 | $result = $this->query(" |
130 | 130 | SELECT * from {$this->makeTable('user_attributes')} as attribute |
@@ -152,10 +152,10 @@ discard block |
||
152 | 152 | * @param $value |
153 | 153 | * @return $this |
154 | 154 | */ |
155 | - public function set($key, $value) |
|
156 | - { |
|
157 | - if (is_scalar($value) && is_scalar($key) && !empty($key)) { |
|
158 | - switch ($key) { |
|
155 | + public function set($key, $value) |
|
156 | + { |
|
157 | + if (is_scalar($value) && is_scalar($key) && !empty($key)) { |
|
158 | + switch ($key) { |
|
159 | 159 | case 'password': |
160 | 160 | $this->givenPassword = $value; |
161 | 161 | $value = $this->getPassword($value); |
@@ -179,8 +179,8 @@ discard block |
||
179 | 179 | * @param $pass |
180 | 180 | * @return string |
181 | 181 | */ |
182 | - public function getPassword($pass) |
|
183 | - { |
|
182 | + public function getPassword($pass) |
|
183 | + { |
|
184 | 184 | return $this->modx->phpass->HashPassword($pass); |
185 | 185 | } |
186 | 186 | |
@@ -188,8 +188,8 @@ discard block |
||
188 | 188 | * @param string $name |
189 | 189 | * @return bool |
190 | 190 | */ |
191 | - public function hasPermission($name) |
|
192 | - { |
|
191 | + public function hasPermission($name) |
|
192 | + { |
|
193 | 193 | return (is_string($name) && $name && isset($this->mgrPermissions[$name])); |
194 | 194 | } |
195 | 195 | |
@@ -198,89 +198,89 @@ discard block |
||
198 | 198 | * @param bool $clearCache |
199 | 199 | * @return bool|int|null|void |
200 | 200 | */ |
201 | - public function save($fire_events = false, $clearCache = false) |
|
202 | - { |
|
203 | - if ($this->get('email') == '' || $this->get('username') == '' || $this->get('password') == '') { |
|
201 | + public function save($fire_events = false, $clearCache = false) |
|
202 | + { |
|
203 | + if ($this->get('email') == '' || $this->get('username') == '' || $this->get('password') == '') { |
|
204 | 204 | $this->log['EmptyPKField'] = 'Email, username or password is empty <pre>' . print_r($this->toArray(), |
205 | 205 | true) . '</pre>'; |
206 | 206 | |
207 | 207 | return false; |
208 | 208 | } |
209 | 209 | |
210 | - if (!$this->checkUnique('manager_users', 'username')) { |
|
210 | + if (!$this->checkUnique('manager_users', 'username')) { |
|
211 | 211 | $this->log['UniqueUsername'] = 'username not unique <pre>' . print_r($this->get('username'), |
212 | 212 | true) . '</pre>'; |
213 | 213 | |
214 | 214 | return false; |
215 | 215 | } |
216 | 216 | |
217 | - if (!$this->checkUnique('user_attributes', 'email', 'internalKey')) { |
|
217 | + if (!$this->checkUnique('user_attributes', 'email', 'internalKey')) { |
|
218 | 218 | $this->log['UniqueEmail'] = 'Email not unique <pre>' . print_r($this->get('email'), true) . '</pre>'; |
219 | 219 | |
220 | 220 | return false; |
221 | 221 | } |
222 | 222 | |
223 | - if(!$this->get('role')) { |
|
223 | + if(!$this->get('role')) { |
|
224 | 224 | $this->log['UniqueEmail'] = 'Wrong manager role <pre>' . print_r($this->get('role'), true) . '</pre>'; |
225 | 225 | } |
226 | 226 | |
227 | 227 | $this->set('sessionid', ''); |
228 | 228 | $fld = $this->toArray(); |
229 | - foreach ($this->default_field['user'] as $key => $value) { |
|
229 | + foreach ($this->default_field['user'] as $key => $value) { |
|
230 | 230 | $tmp = $this->get($key); |
231 | - if ($this->newDoc && (!is_int($tmp) && $tmp == '')) { |
|
231 | + if ($this->newDoc && (!is_int($tmp) && $tmp == '')) { |
|
232 | 232 | $this->field[$key] = $value; |
233 | 233 | } |
234 | 234 | $this->Uset($key, 'user'); |
235 | 235 | unset($fld[$key]); |
236 | 236 | } |
237 | - if (!empty($this->set['user'])) { |
|
238 | - if ($this->newDoc) { |
|
237 | + if (!empty($this->set['user'])) { |
|
238 | + if ($this->newDoc) { |
|
239 | 239 | $SQL = "INSERT into {$this->makeTable('manager_users')} SET " . implode(', ', $this->set['user']); |
240 | - } else { |
|
240 | + } else { |
|
241 | 241 | $SQL = "UPDATE {$this->makeTable('manager_users')} SET " . implode(', ', |
242 | 242 | $this->set['user']) . " WHERE id = " . $this->id; |
243 | 243 | } |
244 | 244 | $this->query($SQL); |
245 | 245 | } |
246 | 246 | |
247 | - if ($this->newDoc) { |
|
247 | + if ($this->newDoc) { |
|
248 | 248 | $this->id = $this->modx->db->getInsertId(); |
249 | 249 | } |
250 | 250 | |
251 | - foreach ($this->default_field['attribute'] as $key => $value) { |
|
251 | + foreach ($this->default_field['attribute'] as $key => $value) { |
|
252 | 252 | $tmp = $this->get($key); |
253 | - if ($this->newDoc && (!is_int($tmp) && $tmp == '')) { |
|
253 | + if ($this->newDoc && (!is_int($tmp) && $tmp == '')) { |
|
254 | 254 | $this->field[$key] = $value; |
255 | 255 | } |
256 | 256 | $this->Uset($key, 'attribute'); |
257 | 257 | unset($fld[$key]); |
258 | 258 | } |
259 | - if (!empty($this->set['attribute'])) { |
|
260 | - if ($this->newDoc) { |
|
259 | + if (!empty($this->set['attribute'])) { |
|
260 | + if ($this->newDoc) { |
|
261 | 261 | $this->set('internalKey', $this->id)->Uset('internalKey', 'attribute'); |
262 | 262 | $SQL = "INSERT into {$this->makeTable('user_attributes')} SET " . implode(', ', |
263 | 263 | $this->set['attribute']); |
264 | - } else { |
|
264 | + } else { |
|
265 | 265 | $SQL = "UPDATE {$this->makeTable('user_attributes')} SET " . implode(', ', |
266 | 266 | $this->set['attribute']) . " WHERE internalKey = " . $this->getID(); |
267 | 267 | } |
268 | 268 | $this->query($SQL); |
269 | 269 | } |
270 | 270 | unset($fld['id']); |
271 | - foreach ($fld as $key => $value) { |
|
272 | - if ($value == '' || !$this->isChanged($key)) { |
|
271 | + foreach ($fld as $key => $value) { |
|
272 | + if ($value == '' || !$this->isChanged($key)) { |
|
273 | 273 | continue; |
274 | 274 | } |
275 | 275 | $result = $this->query("SELECT `setting_value` FROM {$this->makeTable('user_settings')} WHERE `user` = '{$this->id}' AND `setting_name` = '{$key}'"); |
276 | - if ($this->modx->db->getRecordCount($result) > 0) { |
|
276 | + if ($this->modx->db->getRecordCount($result) > 0) { |
|
277 | 277 | $this->query("UPDATE {$this->makeTable('user_settings')} SET `setting_value` = '{$value}' WHERE `user` = '{$this->id}' AND `setting_name` = '{$key}';"); |
278 | - } else { |
|
278 | + } else { |
|
279 | 279 | $this->query("INSERT into {$this->makeTable('user_settings')} SET `user` = {$this->id},`setting_name` = '{$key}',`setting_value` = '{$value}';"); |
280 | 280 | } |
281 | 281 | } |
282 | 282 | // TODO |
283 | - if (!$this->newDoc && $this->givenPassword) { |
|
283 | + if (!$this->newDoc && $this->givenPassword) { |
|
284 | 284 | $this->invokeEvent('OnManagerChangePassword', array( |
285 | 285 | 'userObj' => $this, |
286 | 286 | 'userid' => $this->id, |
@@ -290,7 +290,7 @@ discard block |
||
290 | 290 | ), $fire_events); |
291 | 291 | } |
292 | 292 | |
293 | - if ($this->groupIds) { |
|
293 | + if ($this->groupIds) { |
|
294 | 294 | $this->setUserGroups($this->id, $this->groupIds); |
295 | 295 | } |
296 | 296 | // TODO |
@@ -306,7 +306,7 @@ discard block |
||
306 | 306 | "userroleid" => $this->get('role') |
307 | 307 | ), $fire_events); |
308 | 308 | |
309 | - if ($clearCache) { |
|
309 | + if ($clearCache) { |
|
310 | 310 | $this->clearCache($fire_events); |
311 | 311 | } |
312 | 312 | |
@@ -318,9 +318,9 @@ discard block |
||
318 | 318 | * @param bool $fire_events |
319 | 319 | * @return bool|null|void |
320 | 320 | */ |
321 | - public function delete($ids, $fire_events = false) |
|
322 | - { |
|
323 | - if ($this->edit($ids)) { |
|
321 | + public function delete($ids, $fire_events = false) |
|
322 | + { |
|
323 | + if ($this->edit($ids)) { |
|
324 | 324 | $flag = $this->query(" |
325 | 325 | DELETE user,attribute FROM {$this->makeTable('user_attributes')} as attribute |
326 | 326 | LEFT JOIN {$this->makeTable('manager_users')} as user ON user.id=attribute.internalKey |
@@ -334,7 +334,7 @@ discard block |
||
334 | 334 | 'username' => $this->get('username'), |
335 | 335 | 'timestamp' => time() |
336 | 336 | ), $fire_events); |
337 | - } else { |
|
337 | + } else { |
|
338 | 338 | $flag = false; |
339 | 339 | } |
340 | 340 | $this->close(); |
@@ -349,13 +349,13 @@ discard block |
||
349 | 349 | * @param bool $fire_events |
350 | 350 | * @return bool |
351 | 351 | */ |
352 | - public function authUser($id = 0, $fulltime = true, $cookieName = 'modx_remember_manager', $fire_events = false) |
|
353 | - { |
|
352 | + public function authUser($id = 0, $fulltime = true, $cookieName = 'modx_remember_manager', $fire_events = false) |
|
353 | + { |
|
354 | 354 | $flag = false; |
355 | - if (null === $this->getID() && $id) { |
|
355 | + if (null === $this->getID() && $id) { |
|
356 | 356 | $this->edit($id); |
357 | 357 | } |
358 | - if (null !== $this->getID()) { |
|
358 | + if (null !== $this->getID()) { |
|
359 | 359 | $flag = true; |
360 | 360 | $this->save(false); |
361 | 361 | $this->SessionHandler('start', $cookieName, $fulltime); |
@@ -375,10 +375,10 @@ discard block |
||
375 | 375 | * @param int $id |
376 | 376 | * @return bool |
377 | 377 | */ |
378 | - public function checkBlock($id = 0) |
|
379 | - { |
|
378 | + public function checkBlock($id = 0) |
|
379 | + { |
|
380 | 380 | $tmp = clone $this; |
381 | - if ($id && $tmp->getID() != $id) { |
|
381 | + if ($id && $tmp->getID() != $id) { |
|
382 | 382 | $tmp->edit($id); |
383 | 383 | } |
384 | 384 | $now = time(); |
@@ -399,17 +399,17 @@ discard block |
||
399 | 399 | * @param bool $fire_events |
400 | 400 | * @return bool |
401 | 401 | */ |
402 | - public function testAuth($id, $password, $blocker, $fire_events = false) |
|
403 | - { |
|
402 | + public function testAuth($id, $password, $blocker, $fire_events = false) |
|
403 | + { |
|
404 | 404 | $tmp = clone $this; |
405 | - if ($id && $tmp->getID() != $id) { |
|
405 | + if ($id && $tmp->getID() != $id) { |
|
406 | 406 | $tmp->edit($id); |
407 | 407 | } |
408 | 408 | |
409 | 409 | $flag = $pluginFlag = false; |
410 | 410 | if ( |
411 | 411 | (null !== $tmp->getID()) && (!$blocker || ($blocker && !$tmp->checkBlock($id))) |
412 | - ) { |
|
412 | + ) { |
|
413 | 413 | $_password = $tmp->get('password'); |
414 | 414 | $eventResult = $this->getInvokeEventResult('OnManagerAuthentication', array( |
415 | 415 | 'userObj' => $this, |
@@ -418,16 +418,16 @@ discard block |
||
418 | 418 | 'userpassword' => $password, |
419 | 419 | 'savedpassword' => $_password |
420 | 420 | ), $fire_events); |
421 | - if (is_array($eventResult)) { |
|
422 | - foreach ($eventResult as $result) { |
|
421 | + if (is_array($eventResult)) { |
|
422 | + foreach ($eventResult as $result) { |
|
423 | 423 | $pluginFlag = (bool)$result; |
424 | 424 | } |
425 | - } else { |
|
425 | + } else { |
|
426 | 426 | $pluginFlag = (bool)$eventResult; |
427 | 427 | } |
428 | - if (!$pluginFlag) { |
|
428 | + if (!$pluginFlag) { |
|
429 | 429 | $hashType = $this->getPasswordHashType($_password); |
430 | - switch ($hashType) { |
|
430 | + switch ($hashType) { |
|
431 | 431 | case 'phpass': |
432 | 432 | $flag = $this->modx->phpass->CheckPassword($password, $_password); |
433 | 433 | break; |
@@ -437,15 +437,15 @@ discard block |
||
437 | 437 | case 'v1': |
438 | 438 | $algorithm = \APIhelpers::getkey($this->modx->config, 'pwd_hash_algo', 'UNCRYPT'); |
439 | 439 | $userAlgorithm = $this->getPasswordHashAlgorithm($_password); |
440 | - if ($algorithm !== $userAlgorithm) { |
|
440 | + if ($algorithm !== $userAlgorithm) { |
|
441 | 441 | $algorithm = $userAlgorithm; |
442 | 442 | } |
443 | 443 | $flag = $_password == $this->makeHash($password, $tmp->getID(), $algorithm); |
444 | 444 | break; |
445 | 445 | } |
446 | - if ($flag && $hashType == 'md5' || $hashType == 'v1') { |
|
446 | + if ($flag && $hashType == 'md5' || $hashType == 'v1') { |
|
447 | 447 | $tmp->set('password', $password)->save(); |
448 | - if ($id == $this->getID()) { |
|
448 | + if ($id == $this->getID()) { |
|
449 | 449 | $this->field['password'] = $tmp->get('password'); |
450 | 450 | } |
451 | 451 | } |
@@ -460,9 +460,9 @@ discard block |
||
460 | 460 | * @param string $cookieName |
461 | 461 | * @param null $fire_events |
462 | 462 | */ |
463 | - public function logOut($cookieName = 'modx_remember_manager', $fire_events = null) |
|
464 | - { |
|
465 | - if (!$uid = $this->modx->getLoginUserID('mgr')) { |
|
463 | + public function logOut($cookieName = 'modx_remember_manager', $fire_events = null) |
|
464 | + { |
|
465 | + if (!$uid = $this->modx->getLoginUserID('mgr')) { |
|
466 | 466 | return; |
467 | 467 | } |
468 | 468 | $params = array( |
@@ -489,11 +489,11 @@ discard block |
||
489 | 489 | * |
490 | 490 | * remeber может быть числом в секундах |
491 | 491 | */ |
492 | - protected function SessionHandler($directive, $cookieName, $remember = true) |
|
493 | - { |
|
494 | - switch ($directive) { |
|
492 | + protected function SessionHandler($directive, $cookieName, $remember = true) |
|
493 | + { |
|
494 | + switch ($directive) { |
|
495 | 495 | case 'start': |
496 | - if ($this->getID()) { |
|
496 | + if ($this->getID()) { |
|
497 | 497 | $_SESSION['usertype'] = 'manager'; |
498 | 498 | $_SESSION['mgrShortname'] = $this->get('username'); |
499 | 499 | $_SESSION['mgrFullname'] = $this->get('fullname'); |
@@ -506,13 +506,13 @@ discard block |
||
506 | 506 | $_SESSION['mgrRole'] = $this->get('role'); |
507 | 507 | $_SESSION['mgrPermissions'] = $this->mgrPermissions; |
508 | 508 | $_SESSION['mgrDocgroups'] = $this->getDocumentGroups(); |
509 | - if ($remember) { |
|
509 | + if ($remember) { |
|
510 | 510 | $this->setAutoLoginCookie($cookieName, $remember); |
511 | 511 | } |
512 | 512 | } |
513 | 513 | break; |
514 | 514 | case 'destroy': |
515 | - if (isset($_SESSION['mgrValidated'])) { |
|
515 | + if (isset($_SESSION['mgrValidated'])) { |
|
516 | 516 | unset($_SESSION['usertype']); |
517 | 517 | unset($_SESSION['mgrShortname']); |
518 | 518 | unset($_SESSION['mgrFullname']); |
@@ -526,8 +526,8 @@ discard block |
||
526 | 526 | unset($_SESSION['mgrPermissions']); |
527 | 527 | |
528 | 528 | setcookie($cookieName, '', time() - 60, MODX_BASE_URL); |
529 | - } else { |
|
530 | - if (isset($_COOKIE[session_name()])) { |
|
529 | + } else { |
|
530 | + if (isset($_COOKIE[session_name()])) { |
|
531 | 531 | setcookie(session_name(), '', time() - 60, MODX_BASE_URL); |
532 | 532 | } |
533 | 533 | setcookie($cookieName, '', time() - 60, MODX_BASE_URL); |
@@ -542,8 +542,8 @@ discard block |
||
542 | 542 | /** |
543 | 543 | * @return bool |
544 | 544 | */ |
545 | - public function isSecure() |
|
546 | - { |
|
545 | + public function isSecure() |
|
546 | + { |
|
547 | 547 | $out = $this->modxConfig('server_protocol') == 'http' ? false : true; |
548 | 548 | |
549 | 549 | return $out; |
@@ -554,9 +554,9 @@ discard block |
||
554 | 554 | * @param bool $remember |
555 | 555 | * @return $this |
556 | 556 | */ |
557 | - public function setAutoLoginCookie($cookieName, $remember = true) |
|
558 | - { |
|
559 | - if (!empty($cookieName) && $this->getID()) { |
|
557 | + public function setAutoLoginCookie($cookieName, $remember = true) |
|
558 | + { |
|
559 | + if (!empty($cookieName) && $this->getID()) { |
|
560 | 560 | $secure = $this->isSecure(); |
561 | 561 | $remember = is_bool($remember) ? (60 * 60 * 24 * 365 * 5) : (int)$remember; |
562 | 562 | $cookieValue = $this->get('username'); |
@@ -571,11 +571,11 @@ discard block |
||
571 | 571 | * @param int $userID |
572 | 572 | * @return array |
573 | 573 | */ |
574 | - public function getDocumentGroups($userID = 0) |
|
575 | - { |
|
574 | + public function getDocumentGroups($userID = 0) |
|
575 | + { |
|
576 | 576 | $out = array(); |
577 | 577 | $user = $this->switchObject($userID); |
578 | - if (null !== $user->getID()) { |
|
578 | + if (null !== $user->getID()) { |
|
579 | 579 | $member_groups = $this->modx->getFullTableName('member_groups'); |
580 | 580 | $membergroup_access = $this->modx->getFullTableName('membergroup_access'); |
581 | 581 | |
@@ -593,18 +593,18 @@ discard block |
||
593 | 593 | * @param int $userID |
594 | 594 | * @return array |
595 | 595 | */ |
596 | - public function getUserGroups($userID = 0) |
|
597 | - { |
|
596 | + public function getUserGroups($userID = 0) |
|
597 | + { |
|
598 | 598 | $out = array(); |
599 | 599 | $user = $this->switchObject($userID); |
600 | - if (null !== $user->getID()) { |
|
600 | + if (null !== $user->getID()) { |
|
601 | 601 | $member_groups = $this->makeTable('member_groups'); |
602 | 602 | $membergroup_names = $this->makeTable('membergroup_names'); |
603 | 603 | |
604 | 604 | $rs = $this->query("SELECT `ug`.`user_group`, `ugn`.`name` FROM {$member_groups} as `ug` |
605 | 605 | INNER JOIN {$membergroup_names} as `ugn` ON `ugn`.`id`=`ug`.`user_group` |
606 | 606 | WHERE `ug`.`member` = " . $user->getID()); |
607 | - while ($row = $this->modx->db->getRow($rs)) { |
|
607 | + while ($row = $this->modx->db->getRow($rs)) { |
|
608 | 608 | $out[$row['user_group']] = $row['name']; |
609 | 609 | } |
610 | 610 | } |
@@ -618,20 +618,20 @@ discard block |
||
618 | 618 | * @param array $groupIds |
619 | 619 | * @return $this |
620 | 620 | */ |
621 | - public function setUserGroups($userID = 0, $groupIds = array()) |
|
622 | - { |
|
623 | - if (!is_array($groupIds)) { |
|
621 | + public function setUserGroups($userID = 0, $groupIds = array()) |
|
622 | + { |
|
623 | + if (!is_array($groupIds)) { |
|
624 | 624 | return $this; |
625 | 625 | } |
626 | - if ($this->newDoc && $userID == 0) { |
|
626 | + if ($this->newDoc && $userID == 0) { |
|
627 | 627 | $this->groupIds = $groupIds; |
628 | - } else { |
|
628 | + } else { |
|
629 | 629 | $user = $this->switchObject($userID); |
630 | - if ($uid = $user->getID()) { |
|
631 | - foreach ($groupIds as $gid) { |
|
630 | + if ($uid = $user->getID()) { |
|
631 | + foreach ($groupIds as $gid) { |
|
632 | 632 | $this->query("REPLACE INTO {$this->makeTable('member_groups')} (`user_group`, `member`) VALUES ('{$gid}', '{$uid}')"); |
633 | 633 | } |
634 | - if (!$this->newDoc) { |
|
634 | + if (!$this->newDoc) { |
|
635 | 635 | $groupIds = empty($groupIds) ? '0' : implode(',', $groupIds); |
636 | 636 | $this->query("DELETE FROM {$this->makeTable('member_groups')} WHERE `member`={$uid} AND `user_group` NOT IN ({$groupIds})"); |
637 | 637 | } |
@@ -647,14 +647,14 @@ discard block |
||
647 | 647 | * @param string $pass |
648 | 648 | * @return string |
649 | 649 | */ |
650 | - public function getPasswordHashType($pass) |
|
651 | - { |
|
650 | + public function getPasswordHashType($pass) |
|
651 | + { |
|
652 | 652 | $out = 'unknown'; |
653 | - if (substr($pass, 0, 1) === '$') { |
|
653 | + if (substr($pass, 0, 1) === '$') { |
|
654 | 654 | $out = 'phpass'; |
655 | - } elseif (strpos($pass, '>') !== false) { |
|
655 | + } elseif (strpos($pass, '>') !== false) { |
|
656 | 656 | $out = 'v1'; |
657 | - } elseif (strlen($pass) === 32) { |
|
657 | + } elseif (strlen($pass) === 32) { |
|
658 | 658 | $out = 'md5'; |
659 | 659 | } |
660 | 660 | |
@@ -665,8 +665,8 @@ discard block |
||
665 | 665 | * @param string $pass |
666 | 666 | * @return string |
667 | 667 | */ |
668 | - public function getPasswordHashAlgorithm($pass) |
|
669 | - { |
|
668 | + public function getPasswordHashAlgorithm($pass) |
|
669 | + { |
|
670 | 670 | $pointer = strpos($pass, '>'); |
671 | 671 | $out = $pointer === false ? 'NOSALT' : substr($pass, 0, $pointer); |
672 | 672 | |
@@ -679,11 +679,11 @@ discard block |
||
679 | 679 | * @param string $algorithm |
680 | 680 | * @return string |
681 | 681 | */ |
682 | - public function makeHash($pass, $seed, $algorithm) |
|
683 | - { |
|
682 | + public function makeHash($pass, $seed, $algorithm) |
|
683 | + { |
|
684 | 684 | $salt = md5($pass . $seed); |
685 | 685 | |
686 | - switch ($algorithm) { |
|
686 | + switch ($algorithm) { |
|
687 | 687 | case 'BLOWFISH_Y': |
688 | 688 | $salt = '$2y$07$' . substr($salt, 0, 22); |
689 | 689 | break; |
@@ -238,7 +238,7 @@ discard block |
||
238 | 238 | if ($this->newDoc) { |
239 | 239 | $SQL = "INSERT into {$this->makeTable('manager_users')} SET " . implode(', ', $this->set['user']); |
240 | 240 | } else { |
241 | - $SQL = "UPDATE {$this->makeTable('manager_users')} SET " . implode(', ', |
|
241 | + $SQL = "update {$this->makeTable('manager_users')} SET " . implode(', ', |
|
242 | 242 | $this->set['user']) . " WHERE id = " . $this->id; |
243 | 243 | } |
244 | 244 | $this->query($SQL); |
@@ -262,7 +262,7 @@ discard block |
||
262 | 262 | $SQL = "INSERT into {$this->makeTable('user_attributes')} SET " . implode(', ', |
263 | 263 | $this->set['attribute']); |
264 | 264 | } else { |
265 | - $SQL = "UPDATE {$this->makeTable('user_attributes')} SET " . implode(', ', |
|
265 | + $SQL = "update {$this->makeTable('user_attributes')} SET " . implode(', ', |
|
266 | 266 | $this->set['attribute']) . " WHERE internalKey = " . $this->getID(); |
267 | 267 | } |
268 | 268 | $this->query($SQL); |
@@ -274,7 +274,7 @@ discard block |
||
274 | 274 | } |
275 | 275 | $result = $this->query("SELECT `setting_value` FROM {$this->makeTable('user_settings')} WHERE `user` = '{$this->id}' AND `setting_name` = '{$key}'"); |
276 | 276 | if ($this->modx->db->getRecordCount($result) > 0) { |
277 | - $this->query("UPDATE {$this->makeTable('user_settings')} SET `setting_value` = '{$value}' WHERE `user` = '{$this->id}' AND `setting_name` = '{$key}';"); |
|
277 | + $this->query("update {$this->makeTable('user_settings')} SET `setting_value` = '{$value}' WHERE `user` = '{$this->id}' AND `setting_name` = '{$key}';"); |
|
278 | 278 | } else { |
279 | 279 | $this->query("INSERT into {$this->makeTable('user_settings')} SET `user` = {$this->id},`setting_name` = '{$key}',`setting_value` = '{$value}';"); |
280 | 280 | } |
@@ -4,8 +4,8 @@ discard block |
||
4 | 4 | /** |
5 | 5 | * Class modUsers |
6 | 6 | */ |
7 | -class modUsers extends MODxAPI |
|
8 | -{ |
|
7 | +class modUsers extends MODxAPI |
|
8 | +{ |
|
9 | 9 | /** |
10 | 10 | * @var array |
11 | 11 | */ |
@@ -57,8 +57,8 @@ discard block |
||
57 | 57 | * @param $key |
58 | 58 | * @return bool |
59 | 59 | */ |
60 | - public function issetField($key) |
|
61 | - { |
|
60 | + public function issetField($key) |
|
61 | + { |
|
62 | 62 | return (array_key_exists($key, $this->default_field['user']) || array_key_exists($key, |
63 | 63 | $this->default_field['attribute']) || in_array($key, $this->default_field['hidden'])); |
64 | 64 | } |
@@ -67,9 +67,9 @@ discard block |
||
67 | 67 | * @param string $data |
68 | 68 | * @return string|false |
69 | 69 | */ |
70 | - protected function findUser($data) |
|
71 | - { |
|
72 | - switch (true) { |
|
70 | + protected function findUser($data) |
|
71 | + { |
|
72 | + switch (true) { |
|
73 | 73 | case (is_int($data) || ((int)$data > 0 && (string)intval($data) === $data)): |
74 | 74 | $find = 'attribute.internalKey'; |
75 | 75 | break; |
@@ -90,8 +90,8 @@ discard block |
||
90 | 90 | * @param array $data |
91 | 91 | * @return $this |
92 | 92 | */ |
93 | - public function create($data = array()) |
|
94 | - { |
|
93 | + public function create($data = array()) |
|
94 | + { |
|
95 | 95 | parent::create($data); |
96 | 96 | $this->set('createdon', time()); |
97 | 97 | |
@@ -102,16 +102,16 @@ discard block |
||
102 | 102 | * @param $id |
103 | 103 | * @return $this |
104 | 104 | */ |
105 | - public function edit($id) |
|
106 | - { |
|
105 | + public function edit($id) |
|
106 | + { |
|
107 | 107 | $id = is_scalar($id) ? trim($id) : ''; |
108 | - if ($this->getID() != $id) { |
|
108 | + if ($this->getID() != $id) { |
|
109 | 109 | $this->close(); |
110 | 110 | $this->newDoc = false; |
111 | 111 | |
112 | - if (!$find = $this->findUser($id)) { |
|
112 | + if (!$find = $this->findUser($id)) { |
|
113 | 113 | $this->id = null; |
114 | - } else { |
|
114 | + } else { |
|
115 | 115 | $this->set('editedon', time()); |
116 | 116 | $result = $this->query(" |
117 | 117 | SELECT * from {$this->makeTable('web_user_attributes')} as attribute |
@@ -135,10 +135,10 @@ discard block |
||
135 | 135 | * @param $value |
136 | 136 | * @return $this |
137 | 137 | */ |
138 | - public function set($key, $value) |
|
139 | - { |
|
140 | - if (is_scalar($value) && is_scalar($key) && !empty($key)) { |
|
141 | - switch ($key) { |
|
138 | + public function set($key, $value) |
|
139 | + { |
|
140 | + if (is_scalar($value) && is_scalar($key) && !empty($key)) { |
|
141 | + switch ($key) { |
|
142 | 142 | case 'password': |
143 | 143 | $this->givenPassword = $value; |
144 | 144 | $value = $this->getPassword($value); |
@@ -162,8 +162,8 @@ discard block |
||
162 | 162 | * @param $pass |
163 | 163 | * @return string |
164 | 164 | */ |
165 | - public function getPassword($pass) |
|
166 | - { |
|
165 | + public function getPassword($pass) |
|
166 | + { |
|
167 | 167 | return md5($pass); |
168 | 168 | } |
169 | 169 | |
@@ -172,83 +172,83 @@ discard block |
||
172 | 172 | * @param bool $clearCache |
173 | 173 | * @return bool|int|null|void |
174 | 174 | */ |
175 | - public function save($fire_events = false, $clearCache = false) |
|
176 | - { |
|
177 | - if ($this->get('email') == '' || $this->get('username') == '' || $this->get('password') == '') { |
|
175 | + public function save($fire_events = false, $clearCache = false) |
|
176 | + { |
|
177 | + if ($this->get('email') == '' || $this->get('username') == '' || $this->get('password') == '') { |
|
178 | 178 | $this->log['EmptyPKField'] = 'Email, username or password is empty <pre>' . print_r($this->toArray(), |
179 | 179 | true) . '</pre>'; |
180 | 180 | |
181 | 181 | return false; |
182 | 182 | } |
183 | 183 | |
184 | - if (!$this->checkUnique('web_users', 'username')) { |
|
184 | + if (!$this->checkUnique('web_users', 'username')) { |
|
185 | 185 | $this->log['UniqueUsername'] = 'username not unique <pre>' . print_r($this->get('username'), |
186 | 186 | true) . '</pre>'; |
187 | 187 | |
188 | 188 | return false; |
189 | 189 | } |
190 | 190 | |
191 | - if (!$this->checkUnique('web_user_attributes', 'email', 'internalKey')) { |
|
191 | + if (!$this->checkUnique('web_user_attributes', 'email', 'internalKey')) { |
|
192 | 192 | $this->log['UniqueEmail'] = 'Email not unique <pre>' . print_r($this->get('email'), true) . '</pre>'; |
193 | 193 | |
194 | 194 | return false; |
195 | 195 | } |
196 | 196 | $this->set('sessionid', ''); |
197 | 197 | $fld = $this->toArray(); |
198 | - foreach ($this->default_field['user'] as $key => $value) { |
|
198 | + foreach ($this->default_field['user'] as $key => $value) { |
|
199 | 199 | $tmp = $this->get($key); |
200 | - if ($this->newDoc && (!is_int($tmp) && $tmp == '')) { |
|
200 | + if ($this->newDoc && (!is_int($tmp) && $tmp == '')) { |
|
201 | 201 | $this->field[$key] = $value; |
202 | 202 | } |
203 | 203 | $this->Uset($key, 'user'); |
204 | 204 | unset($fld[$key]); |
205 | 205 | } |
206 | - if (!empty($this->set['user'])) { |
|
207 | - if ($this->newDoc) { |
|
206 | + if (!empty($this->set['user'])) { |
|
207 | + if ($this->newDoc) { |
|
208 | 208 | $SQL = "INSERT into {$this->makeTable('web_users')} SET " . implode(', ', $this->set['user']); |
209 | - } else { |
|
209 | + } else { |
|
210 | 210 | $SQL = "UPDATE {$this->makeTable('web_users')} SET " . implode(', ', |
211 | 211 | $this->set['user']) . " WHERE id = " . $this->id; |
212 | 212 | } |
213 | 213 | $this->query($SQL); |
214 | 214 | } |
215 | 215 | |
216 | - if ($this->newDoc) { |
|
216 | + if ($this->newDoc) { |
|
217 | 217 | $this->id = $this->modx->db->getInsertId(); |
218 | 218 | } |
219 | 219 | |
220 | - foreach ($this->default_field['attribute'] as $key => $value) { |
|
220 | + foreach ($this->default_field['attribute'] as $key => $value) { |
|
221 | 221 | $tmp = $this->get($key); |
222 | - if ($this->newDoc && (!is_int($tmp) && $tmp == '')) { |
|
222 | + if ($this->newDoc && (!is_int($tmp) && $tmp == '')) { |
|
223 | 223 | $this->field[$key] = $value; |
224 | 224 | } |
225 | 225 | $this->Uset($key, 'attribute'); |
226 | 226 | unset($fld[$key]); |
227 | 227 | } |
228 | - if (!empty($this->set['attribute'])) { |
|
229 | - if ($this->newDoc) { |
|
228 | + if (!empty($this->set['attribute'])) { |
|
229 | + if ($this->newDoc) { |
|
230 | 230 | $this->set('internalKey', $this->id)->Uset('internalKey', 'attribute'); |
231 | 231 | $SQL = "INSERT into {$this->makeTable('web_user_attributes')} SET " . implode(', ', |
232 | 232 | $this->set['attribute']); |
233 | - } else { |
|
233 | + } else { |
|
234 | 234 | $SQL = "UPDATE {$this->makeTable('web_user_attributes')} SET " . implode(', ', |
235 | 235 | $this->set['attribute']) . " WHERE internalKey = " . $this->getID(); |
236 | 236 | } |
237 | 237 | $this->query($SQL); |
238 | 238 | } |
239 | 239 | unset($fld['id']); |
240 | - foreach ($fld as $key => $value) { |
|
241 | - if ($value == '' || !$this->isChanged($key)) { |
|
240 | + foreach ($fld as $key => $value) { |
|
241 | + if ($value == '' || !$this->isChanged($key)) { |
|
242 | 242 | continue; |
243 | 243 | } |
244 | 244 | $result = $this->query("SELECT `setting_value` FROM {$this->makeTable('web_user_settings')} WHERE `webuser` = '{$this->id}' AND `setting_name` = '{$key}'"); |
245 | - if ($this->modx->db->getRecordCount($result) > 0) { |
|
245 | + if ($this->modx->db->getRecordCount($result) > 0) { |
|
246 | 246 | $this->query("UPDATE {$this->makeTable('web_user_settings')} SET `setting_value` = '{$value}' WHERE `webuser` = '{$this->id}' AND `setting_name` = '{$key}';"); |
247 | - } else { |
|
247 | + } else { |
|
248 | 248 | $this->query("INSERT into {$this->makeTable('web_user_settings')} SET `webuser` = {$this->id},`setting_name` = '{$key}',`setting_value` = '{$value}';"); |
249 | 249 | } |
250 | 250 | } |
251 | - if (!$this->newDoc && $this->givenPassword) { |
|
251 | + if (!$this->newDoc && $this->givenPassword) { |
|
252 | 252 | $this->invokeEvent('OnWebChangePassword', array( |
253 | 253 | 'userObj' => $this, |
254 | 254 | 'userid' => $this->id, |
@@ -259,7 +259,9 @@ discard block |
||
259 | 259 | ), $fire_events); |
260 | 260 | } |
261 | 261 | |
262 | - if ($this->groupIds) $this->setUserGroups($this->id, $this->groupIds); |
|
262 | + if ($this->groupIds) { |
|
263 | + $this->setUserGroups($this->id, $this->groupIds); |
|
264 | + } |
|
263 | 265 | |
264 | 266 | $this->invokeEvent('OnWebSaveUser', array( |
265 | 267 | 'userObj' => $this, |
@@ -268,7 +270,7 @@ discard block |
||
268 | 270 | 'user' => $this->toArray() |
269 | 271 | ), $fire_events); |
270 | 272 | |
271 | - if ($clearCache) { |
|
273 | + if ($clearCache) { |
|
272 | 274 | $this->clearCache($fire_events); |
273 | 275 | } |
274 | 276 | |
@@ -280,9 +282,9 @@ discard block |
||
280 | 282 | * @param bool $fire_events |
281 | 283 | * @return bool|null|void |
282 | 284 | */ |
283 | - public function delete($ids, $fire_events = false) |
|
284 | - { |
|
285 | - if ($this->edit($ids)) { |
|
285 | + public function delete($ids, $fire_events = false) |
|
286 | + { |
|
287 | + if ($this->edit($ids)) { |
|
286 | 288 | $flag = $this->query(" |
287 | 289 | DELETE user,attribute FROM {$this->makeTable('web_user_attributes')} as attribute |
288 | 290 | LEFT JOIN {$this->makeTable('web_users')} as user ON user.id=attribute.internalKey |
@@ -296,7 +298,7 @@ discard block |
||
296 | 298 | 'username' => $this->get('username'), |
297 | 299 | 'timestamp' => time() |
298 | 300 | ), $fire_events); |
299 | - } else { |
|
301 | + } else { |
|
300 | 302 | $flag = false; |
301 | 303 | } |
302 | 304 | $this->close(); |
@@ -311,13 +313,13 @@ discard block |
||
311 | 313 | * @param bool $fire_events |
312 | 314 | * @return bool |
313 | 315 | */ |
314 | - public function authUser($id = 0, $fulltime = true, $cookieName = 'WebLoginPE', $fire_events = false) |
|
315 | - { |
|
316 | + public function authUser($id = 0, $fulltime = true, $cookieName = 'WebLoginPE', $fire_events = false) |
|
317 | + { |
|
316 | 318 | $flag = false; |
317 | - if (null === $this->getID() && $id) { |
|
319 | + if (null === $this->getID() && $id) { |
|
318 | 320 | $this->edit($id); |
319 | 321 | } |
320 | - if (null !== $this->getID()) { |
|
322 | + if (null !== $this->getID()) { |
|
321 | 323 | $flag = true; |
322 | 324 | $this->save(false); |
323 | 325 | $this->SessionHandler('start', $cookieName, $fulltime); |
@@ -337,10 +339,10 @@ discard block |
||
337 | 339 | * @param int $id |
338 | 340 | * @return bool |
339 | 341 | */ |
340 | - public function checkBlock($id = 0) |
|
341 | - { |
|
342 | + public function checkBlock($id = 0) |
|
343 | + { |
|
342 | 344 | $tmp = clone $this; |
343 | - if ($id && $tmp->getID() != $id) { |
|
345 | + if ($id && $tmp->getID() != $id) { |
|
344 | 346 | $tmp->edit($id); |
345 | 347 | } |
346 | 348 | $now = time(); |
@@ -361,17 +363,17 @@ discard block |
||
361 | 363 | * @param bool $fire_events |
362 | 364 | * @return bool |
363 | 365 | */ |
364 | - public function testAuth($id, $password, $blocker, $fire_events = false) |
|
365 | - { |
|
366 | + public function testAuth($id, $password, $blocker, $fire_events = false) |
|
367 | + { |
|
366 | 368 | $tmp = clone $this; |
367 | - if ($id && $tmp->getID() != $id) { |
|
369 | + if ($id && $tmp->getID() != $id) { |
|
368 | 370 | $tmp->edit($id); |
369 | 371 | } |
370 | 372 | |
371 | 373 | $flag = $pluginFlag = false; |
372 | 374 | if ( |
373 | 375 | (null !== $tmp->getID()) && (!$blocker || ($blocker && !$tmp->checkBlock($id))) |
374 | - ) { |
|
376 | + ) { |
|
375 | 377 | $eventResult = $this->getInvokeEventResult('OnWebAuthentication', array( |
376 | 378 | 'userObj' => $this, |
377 | 379 | 'userid' => $tmp->getID(), |
@@ -379,14 +381,14 @@ discard block |
||
379 | 381 | 'userpassword' => $password, |
380 | 382 | 'savedpassword' => $tmp->get('password') |
381 | 383 | ), $fire_events); |
382 | - if (is_array($eventResult)) { |
|
383 | - foreach ($eventResult as $result) { |
|
384 | + if (is_array($eventResult)) { |
|
385 | + foreach ($eventResult as $result) { |
|
384 | 386 | $pluginFlag = (bool)$result; |
385 | 387 | } |
386 | - } else { |
|
388 | + } else { |
|
387 | 389 | $pluginFlag = (bool)$eventResult; |
388 | 390 | } |
389 | - if (!$pluginFlag) { |
|
391 | + if (!$pluginFlag) { |
|
390 | 392 | $flag = ($tmp->get('password') == $tmp->getPassword($password)); |
391 | 393 | } |
392 | 394 | } |
@@ -400,12 +402,12 @@ discard block |
||
400 | 402 | * @param string $cookieName |
401 | 403 | * @return bool |
402 | 404 | */ |
403 | - public function AutoLogin($fulltime = true, $cookieName = 'WebLoginPE', $fire_events = null) |
|
404 | - { |
|
405 | + public function AutoLogin($fulltime = true, $cookieName = 'WebLoginPE', $fire_events = null) |
|
406 | + { |
|
405 | 407 | $flag = false; |
406 | - if (isset($_COOKIE[$cookieName])) { |
|
408 | + if (isset($_COOKIE[$cookieName])) { |
|
407 | 409 | $cookie = explode('|', $_COOKIE[$cookieName], 3); |
408 | - if (isset($cookie[0], $cookie[1], $cookie[2]) && strlen($cookie[0]) == 32 && strlen($cookie[1]) == 32) { |
|
410 | + if (isset($cookie[0], $cookie[1], $cookie[2]) && strlen($cookie[0]) == 32 && strlen($cookie[1]) == 32) { |
|
409 | 411 | $this->close(); |
410 | 412 | $q = $this->modx->db->query("SELECT id FROM " . $this->makeTable('web_users') . " WHERE md5(username)='{$this->escape($cookie[0])}'"); |
411 | 413 | $id = $this->modx->db->getValue($q); |
@@ -415,7 +417,7 @@ discard block |
||
415 | 417 | && $this->get('password') == $cookie[1] |
416 | 418 | && $this->get('sessionid') == $cookie[2] |
417 | 419 | && !$this->checkBlock($this->getID()) |
418 | - ) { |
|
420 | + ) { |
|
419 | 421 | $flag = $this->authUser($this->getID(), $fulltime, $cookieName, $fire_events); |
420 | 422 | |
421 | 423 | } |
@@ -429,9 +431,9 @@ discard block |
||
429 | 431 | * @param string $cookieName |
430 | 432 | * @param null $fire_events |
431 | 433 | */ |
432 | - public function logOut($cookieName = 'WebLoginPE', $fire_events = null) |
|
433 | - { |
|
434 | - if (!$uid = $this->modx->getLoginUserID('web')) { |
|
434 | + public function logOut($cookieName = 'WebLoginPE', $fire_events = null) |
|
435 | + { |
|
436 | + if (!$uid = $this->modx->getLoginUserID('web')) { |
|
435 | 437 | return; |
436 | 438 | } |
437 | 439 | $params = array( |
@@ -456,11 +458,11 @@ discard block |
||
456 | 458 | * |
457 | 459 | * remeber может быть числом в секундах |
458 | 460 | */ |
459 | - protected function SessionHandler($directive, $cookieName, $remember = true) |
|
460 | - { |
|
461 | - switch ($directive) { |
|
461 | + protected function SessionHandler($directive, $cookieName, $remember = true) |
|
462 | + { |
|
463 | + switch ($directive) { |
|
462 | 464 | case 'start': |
463 | - if ($this->getID()) { |
|
465 | + if ($this->getID()) { |
|
464 | 466 | $_SESSION['webShortname'] = $this->get('username'); |
465 | 467 | $_SESSION['webFullname'] = $this->get('fullname'); |
466 | 468 | $_SESSION['webEmail'] = $this->get('email'); |
@@ -474,13 +476,13 @@ discard block |
||
474 | 476 | $_SESSION['webUsrConfigSet'] = array(); |
475 | 477 | $_SESSION['webUserGroupNames'] = $this->getUserGroups(); |
476 | 478 | $_SESSION['webDocgroups'] = $this->getDocumentGroups(); |
477 | - if ($remember) { |
|
479 | + if ($remember) { |
|
478 | 480 | $this->setAutoLoginCookie($cookieName, $remember); |
479 | 481 | } |
480 | 482 | } |
481 | 483 | break; |
482 | 484 | case 'destroy': |
483 | - if (isset($_SESSION['mgrValidated'])) { |
|
485 | + if (isset($_SESSION['mgrValidated'])) { |
|
484 | 486 | unset($_SESSION['webShortname']); |
485 | 487 | unset($_SESSION['webFullname']); |
486 | 488 | unset($_SESSION['webEmail']); |
@@ -496,8 +498,8 @@ discard block |
||
496 | 498 | unset($_SESSION['webDocgroups']); |
497 | 499 | |
498 | 500 | setcookie($cookieName, '', time() - 60, MODX_BASE_URL); |
499 | - } else { |
|
500 | - if (isset($_COOKIE[session_name()])) { |
|
501 | + } else { |
|
502 | + if (isset($_COOKIE[session_name()])) { |
|
501 | 503 | setcookie(session_name(), '', time() - 60, MODX_BASE_URL); |
502 | 504 | } |
503 | 505 | setcookie($cookieName, '', time() - 60, MODX_BASE_URL); |
@@ -512,8 +514,8 @@ discard block |
||
512 | 514 | /** |
513 | 515 | * @return bool |
514 | 516 | */ |
515 | - public function isSecure() |
|
516 | - { |
|
517 | + public function isSecure() |
|
518 | + { |
|
517 | 519 | $out = $this->modxConfig('server_protocol') == 'http' ? false : true; |
518 | 520 | |
519 | 521 | return $out; |
@@ -524,9 +526,9 @@ discard block |
||
524 | 526 | * @param bool $remember |
525 | 527 | * @return $this |
526 | 528 | */ |
527 | - public function setAutoLoginCookie($cookieName, $remember = true) |
|
528 | - { |
|
529 | - if (!empty($cookieName) && $this->getID()) { |
|
529 | + public function setAutoLoginCookie($cookieName, $remember = true) |
|
530 | + { |
|
531 | + if (!empty($cookieName) && $this->getID()) { |
|
530 | 532 | $secure = $this->isSecure(); |
531 | 533 | $remember = is_bool($remember) ? (60 * 60 * 24 * 365 * 5) : (int)$remember; |
532 | 534 | $cookieValue = array(md5($this->get('username')), $this->get('password'), $this->get('sessionid'), $remember); |
@@ -542,11 +544,11 @@ discard block |
||
542 | 544 | * @param int $userID |
543 | 545 | * @return array |
544 | 546 | */ |
545 | - public function getDocumentGroups($userID = 0) |
|
546 | - { |
|
547 | + public function getDocumentGroups($userID = 0) |
|
548 | + { |
|
547 | 549 | $out = array(); |
548 | 550 | $user = $this->switchObject($userID); |
549 | - if (null !== $user->getID()) { |
|
551 | + if (null !== $user->getID()) { |
|
550 | 552 | $web_groups = $this->modx->getFullTableName('web_groups'); |
551 | 553 | $webgroup_access = $this->modx->getFullTableName('webgroup_access'); |
552 | 554 | |
@@ -565,18 +567,18 @@ discard block |
||
565 | 567 | * @param int $userID |
566 | 568 | * @return array |
567 | 569 | */ |
568 | - public function getUserGroups($userID = 0) |
|
569 | - { |
|
570 | + public function getUserGroups($userID = 0) |
|
571 | + { |
|
570 | 572 | $out = array(); |
571 | 573 | $user = $this->switchObject($userID); |
572 | - if (null !== $user->getID()) { |
|
574 | + if (null !== $user->getID()) { |
|
573 | 575 | $web_groups = $this->makeTable('web_groups'); |
574 | 576 | $webgroup_names = $this->makeTable('webgroup_names'); |
575 | 577 | |
576 | 578 | $rs = $this->query("SELECT `ug`.`webgroup`, `ugn`.`name` FROM {$web_groups} as `ug` |
577 | 579 | INNER JOIN {$webgroup_names} as `ugn` ON `ugn`.`id`=`ug`.`webgroup` |
578 | 580 | WHERE `ug`.`webuser` = " . $user->getID()); |
579 | - while ($row = $this->modx->db->getRow($rs)) { |
|
581 | + while ($row = $this->modx->db->getRow($rs)) { |
|
580 | 582 | $out[$row['webgroup']] = $row['name']; |
581 | 583 | } |
582 | 584 | } |
@@ -590,18 +592,20 @@ discard block |
||
590 | 592 | * @param array $groupIds |
591 | 593 | * @return $this |
592 | 594 | */ |
593 | - public function setUserGroups($userID = 0, $groupIds = array()) |
|
594 | - { |
|
595 | - if (!is_array($groupIds)) return $this; |
|
596 | - if ($this->newDoc && $userID == 0) { |
|
595 | + public function setUserGroups($userID = 0, $groupIds = array()) |
|
596 | + { |
|
597 | + if (!is_array($groupIds)) { |
|
598 | + return $this; |
|
599 | + } |
|
600 | + if ($this->newDoc && $userID == 0) { |
|
597 | 601 | $this->groupIds = $groupIds; |
598 | - } else { |
|
602 | + } else { |
|
599 | 603 | $user = $this->switchObject($userID); |
600 | - if ($uid = $user->getID()) { |
|
601 | - foreach ($groupIds as $gid) { |
|
604 | + if ($uid = $user->getID()) { |
|
605 | + foreach ($groupIds as $gid) { |
|
602 | 606 | $this->query("REPLACE INTO {$this->makeTable('web_groups')} (`webgroup`, `webuser`) VALUES ('{$gid}', '{$uid}')"); |
603 | 607 | } |
604 | - if (!$this->newDoc) { |
|
608 | + if (!$this->newDoc) { |
|
605 | 609 | $groupIds = empty($groupIds) ? '0' : implode(',', $groupIds); |
606 | 610 | $this->query("DELETE FROM {$this->makeTable('web_groups')} WHERE `webuser`={$uid} AND `webgroup` NOT IN ({$groupIds})"); |
607 | 611 | } |