@@ -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); |
@@ -163,7 +163,7 @@ discard block |
||
163 | 163 | case 'sessionid': |
164 | 164 | session_regenerate_id(false); |
165 | 165 | $value = session_id(); |
166 | - if ($mid = $this->modx->getLoginUserID('mgr')) { |
|
166 | + if ($mid = $this->modx->getLoginUserID('mgr')) { |
|
167 | 167 | $this->modx->db->query("UPDATE {$this->makeTable('active_user_locks')} SET `sid`='{$value}' WHERE `internalKey`={$mid}"); |
168 | 168 | $this->modx->db->query("UPDATE {$this->makeTable('active_user_sessions')} SET `sid`='{$value}' WHERE `internalKey`={$mid}"); |
169 | 169 | $this->modx->db->query("UPDATE {$this->makeTable('active_users')} SET `sid`='{$value}' WHERE `internalKey`={$mid}"); |
@@ -184,8 +184,8 @@ discard block |
||
184 | 184 | * @param $pass |
185 | 185 | * @return string |
186 | 186 | */ |
187 | - public function getPassword($pass) |
|
188 | - { |
|
187 | + public function getPassword($pass) |
|
188 | + { |
|
189 | 189 | return $this->modx->phpass->HashPassword($pass); |
190 | 190 | } |
191 | 191 | |
@@ -193,8 +193,8 @@ discard block |
||
193 | 193 | * @param string $name |
194 | 194 | * @return bool |
195 | 195 | */ |
196 | - public function hasPermission($name) |
|
197 | - { |
|
196 | + public function hasPermission($name) |
|
197 | + { |
|
198 | 198 | return (is_string($name) && $name && isset($this->mgrPermissions[$name])); |
199 | 199 | } |
200 | 200 | |
@@ -203,89 +203,89 @@ discard block |
||
203 | 203 | * @param bool $clearCache |
204 | 204 | * @return bool|int|null|void |
205 | 205 | */ |
206 | - public function save($fire_events = false, $clearCache = false) |
|
207 | - { |
|
208 | - if ($this->get('email') == '' || $this->get('username') == '' || $this->get('password') == '') { |
|
206 | + public function save($fire_events = false, $clearCache = false) |
|
207 | + { |
|
208 | + if ($this->get('email') == '' || $this->get('username') == '' || $this->get('password') == '') { |
|
209 | 209 | $this->log['EmptyPKField'] = 'Email, username or password is empty <pre>' . print_r($this->toArray(), |
210 | 210 | true) . '</pre>'; |
211 | 211 | |
212 | 212 | return false; |
213 | 213 | } |
214 | 214 | |
215 | - if (!$this->checkUnique('manager_users', 'username')) { |
|
215 | + if (!$this->checkUnique('manager_users', 'username')) { |
|
216 | 216 | $this->log['UniqueUsername'] = 'username not unique <pre>' . print_r($this->get('username'), |
217 | 217 | true) . '</pre>'; |
218 | 218 | |
219 | 219 | return false; |
220 | 220 | } |
221 | 221 | |
222 | - if (!$this->checkUnique('user_attributes', 'email', 'internalKey')) { |
|
222 | + if (!$this->checkUnique('user_attributes', 'email', 'internalKey')) { |
|
223 | 223 | $this->log['UniqueEmail'] = 'Email not unique <pre>' . print_r($this->get('email'), true) . '</pre>'; |
224 | 224 | |
225 | 225 | return false; |
226 | 226 | } |
227 | 227 | |
228 | - if(!$this->get('role')) { |
|
228 | + if(!$this->get('role')) { |
|
229 | 229 | $this->log['UniqueEmail'] = 'Wrong manager role <pre>' . print_r($this->get('role'), true) . '</pre>'; |
230 | 230 | } |
231 | 231 | |
232 | 232 | $this->set('sessionid', ''); |
233 | 233 | $fld = $this->toArray(); |
234 | - foreach ($this->default_field['user'] as $key => $value) { |
|
234 | + foreach ($this->default_field['user'] as $key => $value) { |
|
235 | 235 | $tmp = $this->get($key); |
236 | - if ($this->newDoc && (!is_int($tmp) && $tmp == '')) { |
|
236 | + if ($this->newDoc && (!is_int($tmp) && $tmp == '')) { |
|
237 | 237 | $this->field[$key] = $value; |
238 | 238 | } |
239 | 239 | $this->Uset($key, 'user'); |
240 | 240 | unset($fld[$key]); |
241 | 241 | } |
242 | - if (!empty($this->set['user'])) { |
|
243 | - if ($this->newDoc) { |
|
242 | + if (!empty($this->set['user'])) { |
|
243 | + if ($this->newDoc) { |
|
244 | 244 | $SQL = "INSERT into {$this->makeTable('manager_users')} SET " . implode(', ', $this->set['user']); |
245 | - } else { |
|
245 | + } else { |
|
246 | 246 | $SQL = "UPDATE {$this->makeTable('manager_users')} SET " . implode(', ', |
247 | 247 | $this->set['user']) . " WHERE id = " . $this->id; |
248 | 248 | } |
249 | 249 | $this->query($SQL); |
250 | 250 | } |
251 | 251 | |
252 | - if ($this->newDoc) { |
|
252 | + if ($this->newDoc) { |
|
253 | 253 | $this->id = $this->modx->db->getInsertId(); |
254 | 254 | } |
255 | 255 | |
256 | - foreach ($this->default_field['attribute'] as $key => $value) { |
|
256 | + foreach ($this->default_field['attribute'] as $key => $value) { |
|
257 | 257 | $tmp = $this->get($key); |
258 | - if ($this->newDoc && (!is_int($tmp) && $tmp == '')) { |
|
258 | + if ($this->newDoc && (!is_int($tmp) && $tmp == '')) { |
|
259 | 259 | $this->field[$key] = $value; |
260 | 260 | } |
261 | 261 | $this->Uset($key, 'attribute'); |
262 | 262 | unset($fld[$key]); |
263 | 263 | } |
264 | - if (!empty($this->set['attribute'])) { |
|
265 | - if ($this->newDoc) { |
|
264 | + if (!empty($this->set['attribute'])) { |
|
265 | + if ($this->newDoc) { |
|
266 | 266 | $this->set('internalKey', $this->id)->Uset('internalKey', 'attribute'); |
267 | 267 | $SQL = "INSERT into {$this->makeTable('user_attributes')} SET " . implode(', ', |
268 | 268 | $this->set['attribute']); |
269 | - } else { |
|
269 | + } else { |
|
270 | 270 | $SQL = "UPDATE {$this->makeTable('user_attributes')} SET " . implode(', ', |
271 | 271 | $this->set['attribute']) . " WHERE internalKey = " . $this->getID(); |
272 | 272 | } |
273 | 273 | $this->query($SQL); |
274 | 274 | } |
275 | 275 | unset($fld['id']); |
276 | - foreach ($fld as $key => $value) { |
|
277 | - if ($value == '' || !$this->isChanged($key)) { |
|
276 | + foreach ($fld as $key => $value) { |
|
277 | + if ($value == '' || !$this->isChanged($key)) { |
|
278 | 278 | continue; |
279 | 279 | } |
280 | 280 | $result = $this->query("SELECT `setting_value` FROM {$this->makeTable('user_settings')} WHERE `user` = '{$this->id}' AND `setting_name` = '{$key}'"); |
281 | - if ($this->modx->db->getRecordCount($result) > 0) { |
|
281 | + if ($this->modx->db->getRecordCount($result) > 0) { |
|
282 | 282 | $this->query("UPDATE {$this->makeTable('user_settings')} SET `setting_value` = '{$value}' WHERE `user` = '{$this->id}' AND `setting_name` = '{$key}';"); |
283 | - } else { |
|
283 | + } else { |
|
284 | 284 | $this->query("INSERT into {$this->makeTable('user_settings')} SET `user` = {$this->id},`setting_name` = '{$key}',`setting_value` = '{$value}';"); |
285 | 285 | } |
286 | 286 | } |
287 | 287 | // TODO |
288 | - if (!$this->newDoc && $this->givenPassword) { |
|
288 | + if (!$this->newDoc && $this->givenPassword) { |
|
289 | 289 | $this->invokeEvent('OnManagerChangePassword', array( |
290 | 290 | 'userObj' => $this, |
291 | 291 | 'userid' => $this->id, |
@@ -295,7 +295,7 @@ discard block |
||
295 | 295 | ), $fire_events); |
296 | 296 | } |
297 | 297 | |
298 | - if ($this->groupIds) { |
|
298 | + if ($this->groupIds) { |
|
299 | 299 | $this->setUserGroups($this->id, $this->groupIds); |
300 | 300 | } |
301 | 301 | // TODO |
@@ -311,7 +311,7 @@ discard block |
||
311 | 311 | "userroleid" => $this->get('role') |
312 | 312 | ), $fire_events); |
313 | 313 | |
314 | - if ($clearCache) { |
|
314 | + if ($clearCache) { |
|
315 | 315 | $this->clearCache($fire_events); |
316 | 316 | } |
317 | 317 | |
@@ -323,9 +323,9 @@ discard block |
||
323 | 323 | * @param bool $fire_events |
324 | 324 | * @return bool|null|void |
325 | 325 | */ |
326 | - public function delete($ids, $fire_events = false) |
|
327 | - { |
|
328 | - if ($this->edit($ids)) { |
|
326 | + public function delete($ids, $fire_events = false) |
|
327 | + { |
|
328 | + if ($this->edit($ids)) { |
|
329 | 329 | $flag = $this->query(" |
330 | 330 | DELETE user,attribute FROM {$this->makeTable('user_attributes')} as attribute |
331 | 331 | LEFT JOIN {$this->makeTable('manager_users')} as user ON user.id=attribute.internalKey |
@@ -339,7 +339,7 @@ discard block |
||
339 | 339 | 'username' => $this->get('username'), |
340 | 340 | 'timestamp' => time() |
341 | 341 | ), $fire_events); |
342 | - } else { |
|
342 | + } else { |
|
343 | 343 | $flag = false; |
344 | 344 | } |
345 | 345 | $this->close(); |
@@ -354,13 +354,13 @@ discard block |
||
354 | 354 | * @param bool $fire_events |
355 | 355 | * @return bool |
356 | 356 | */ |
357 | - public function authUser($id = 0, $fulltime = true, $cookieName = 'modx_remember_manager', $fire_events = false) |
|
358 | - { |
|
357 | + public function authUser($id = 0, $fulltime = true, $cookieName = 'modx_remember_manager', $fire_events = false) |
|
358 | + { |
|
359 | 359 | $flag = false; |
360 | - if (null === $this->getID() && $id) { |
|
360 | + if (null === $this->getID() && $id) { |
|
361 | 361 | $this->edit($id); |
362 | 362 | } |
363 | - if (null !== $this->getID()) { |
|
363 | + if (null !== $this->getID()) { |
|
364 | 364 | $flag = true; |
365 | 365 | $this->save(false); |
366 | 366 | $this->SessionHandler('start', $cookieName, $fulltime); |
@@ -380,10 +380,10 @@ discard block |
||
380 | 380 | * @param int $id |
381 | 381 | * @return bool |
382 | 382 | */ |
383 | - public function checkBlock($id = 0) |
|
384 | - { |
|
383 | + public function checkBlock($id = 0) |
|
384 | + { |
|
385 | 385 | $tmp = clone $this; |
386 | - if ($id && $tmp->getID() != $id) { |
|
386 | + if ($id && $tmp->getID() != $id) { |
|
387 | 387 | $tmp->edit($id); |
388 | 388 | } |
389 | 389 | $now = time(); |
@@ -404,17 +404,17 @@ discard block |
||
404 | 404 | * @param bool $fire_events |
405 | 405 | * @return bool |
406 | 406 | */ |
407 | - public function testAuth($id, $password, $blocker, $fire_events = false) |
|
408 | - { |
|
407 | + public function testAuth($id, $password, $blocker, $fire_events = false) |
|
408 | + { |
|
409 | 409 | $tmp = clone $this; |
410 | - if ($id && $tmp->getID() != $id) { |
|
410 | + if ($id && $tmp->getID() != $id) { |
|
411 | 411 | $tmp->edit($id); |
412 | 412 | } |
413 | 413 | |
414 | 414 | $flag = $pluginFlag = false; |
415 | 415 | if ( |
416 | 416 | (null !== $tmp->getID()) && (!$blocker || ($blocker && !$tmp->checkBlock($id))) |
417 | - ) { |
|
417 | + ) { |
|
418 | 418 | $_password = $tmp->get('password'); |
419 | 419 | $eventResult = $this->getInvokeEventResult('OnManagerAuthentication', array( |
420 | 420 | 'userObj' => $this, |
@@ -423,16 +423,16 @@ discard block |
||
423 | 423 | 'userpassword' => $password, |
424 | 424 | 'savedpassword' => $_password |
425 | 425 | ), $fire_events); |
426 | - if (is_array($eventResult)) { |
|
427 | - foreach ($eventResult as $result) { |
|
426 | + if (is_array($eventResult)) { |
|
427 | + foreach ($eventResult as $result) { |
|
428 | 428 | $pluginFlag = (bool)$result; |
429 | 429 | } |
430 | - } else { |
|
430 | + } else { |
|
431 | 431 | $pluginFlag = (bool)$eventResult; |
432 | 432 | } |
433 | - if (!$pluginFlag) { |
|
433 | + if (!$pluginFlag) { |
|
434 | 434 | $hashType = $this->getPasswordHashType($_password); |
435 | - switch ($hashType) { |
|
435 | + switch ($hashType) { |
|
436 | 436 | case 'phpass': |
437 | 437 | $flag = $this->modx->phpass->CheckPassword($password, $_password); |
438 | 438 | break; |
@@ -442,15 +442,15 @@ discard block |
||
442 | 442 | case 'v1': |
443 | 443 | $algorithm = \APIhelpers::getkey($this->modx->config, 'pwd_hash_algo', 'UNCRYPT'); |
444 | 444 | $userAlgorithm = $this->getPasswordHashAlgorithm($_password); |
445 | - if ($algorithm !== $userAlgorithm) { |
|
445 | + if ($algorithm !== $userAlgorithm) { |
|
446 | 446 | $algorithm = $userAlgorithm; |
447 | 447 | } |
448 | 448 | $flag = $_password == $this->makeHash($password, $tmp->getID(), $algorithm); |
449 | 449 | break; |
450 | 450 | } |
451 | - if ($flag && $hashType == 'md5' || $hashType == 'v1') { |
|
451 | + if ($flag && $hashType == 'md5' || $hashType == 'v1') { |
|
452 | 452 | $tmp->set('password', $password)->save(); |
453 | - if ($id == $this->getID()) { |
|
453 | + if ($id == $this->getID()) { |
|
454 | 454 | $this->field['password'] = $tmp->get('password'); |
455 | 455 | } |
456 | 456 | } |
@@ -465,9 +465,9 @@ discard block |
||
465 | 465 | * @param string $cookieName |
466 | 466 | * @param null $fire_events |
467 | 467 | */ |
468 | - public function logOut($cookieName = 'modx_remember_manager', $fire_events = null) |
|
469 | - { |
|
470 | - if (!$uid = $this->modx->getLoginUserID('mgr')) { |
|
468 | + public function logOut($cookieName = 'modx_remember_manager', $fire_events = null) |
|
469 | + { |
|
470 | + if (!$uid = $this->modx->getLoginUserID('mgr')) { |
|
471 | 471 | return; |
472 | 472 | } |
473 | 473 | $params = array( |
@@ -494,11 +494,11 @@ discard block |
||
494 | 494 | * |
495 | 495 | * remeber может быть числом в секундах |
496 | 496 | */ |
497 | - protected function SessionHandler($directive, $cookieName, $remember = true) |
|
498 | - { |
|
499 | - switch ($directive) { |
|
497 | + protected function SessionHandler($directive, $cookieName, $remember = true) |
|
498 | + { |
|
499 | + switch ($directive) { |
|
500 | 500 | case 'start': |
501 | - if ($this->getID()) { |
|
501 | + if ($this->getID()) { |
|
502 | 502 | $_SESSION['usertype'] = 'manager'; |
503 | 503 | $_SESSION['mgrShortname'] = $this->get('username'); |
504 | 504 | $_SESSION['mgrFullname'] = $this->get('fullname'); |
@@ -512,13 +512,13 @@ discard block |
||
512 | 512 | $_SESSION['mgrPermissions'] = $this->mgrPermissions; |
513 | 513 | $_SESSION['mgrDocgroups'] = $this->getDocumentGroups(); |
514 | 514 | $_SESSION['mgrToken'] = md5($this->get('sessionid')); |
515 | - if ($remember) { |
|
515 | + if ($remember) { |
|
516 | 516 | $this->setAutoLoginCookie($cookieName, $remember); |
517 | 517 | } |
518 | 518 | } |
519 | 519 | break; |
520 | 520 | case 'destroy': |
521 | - if (isset($_SESSION['mgrValidated'])) { |
|
521 | + if (isset($_SESSION['mgrValidated'])) { |
|
522 | 522 | unset($_SESSION['usertype']); |
523 | 523 | unset($_SESSION['mgrShortname']); |
524 | 524 | unset($_SESSION['mgrFullname']); |
@@ -532,8 +532,8 @@ discard block |
||
532 | 532 | unset($_SESSION['mgrPermissions']); |
533 | 533 | unset($_SESSION['mgrToken']); |
534 | 534 | setcookie($cookieName, '', time() - 60, MODX_BASE_URL); |
535 | - } else { |
|
536 | - if (isset($_COOKIE[session_name()])) { |
|
535 | + } else { |
|
536 | + if (isset($_COOKIE[session_name()])) { |
|
537 | 537 | setcookie(session_name(), '', time() - 60, MODX_BASE_URL); |
538 | 538 | } |
539 | 539 | setcookie($cookieName, '', time() - 60, MODX_BASE_URL); |
@@ -548,8 +548,8 @@ discard block |
||
548 | 548 | /** |
549 | 549 | * @return bool |
550 | 550 | */ |
551 | - public function isSecure() |
|
552 | - { |
|
551 | + public function isSecure() |
|
552 | + { |
|
553 | 553 | $out = $this->modxConfig('server_protocol') == 'http' ? false : true; |
554 | 554 | |
555 | 555 | return $out; |
@@ -560,9 +560,9 @@ discard block |
||
560 | 560 | * @param bool $remember |
561 | 561 | * @return $this |
562 | 562 | */ |
563 | - public function setAutoLoginCookie($cookieName, $remember = true) |
|
564 | - { |
|
565 | - if (!empty($cookieName) && $this->getID()) { |
|
563 | + public function setAutoLoginCookie($cookieName, $remember = true) |
|
564 | + { |
|
565 | + if (!empty($cookieName) && $this->getID()) { |
|
566 | 566 | $secure = $this->isSecure(); |
567 | 567 | $remember = is_bool($remember) ? (60 * 60 * 24 * 365 * 5) : (int)$remember; |
568 | 568 | $cookieValue = $this->get('username'); |
@@ -577,11 +577,11 @@ discard block |
||
577 | 577 | * @param int $userID |
578 | 578 | * @return array |
579 | 579 | */ |
580 | - public function getDocumentGroups($userID = 0) |
|
581 | - { |
|
580 | + public function getDocumentGroups($userID = 0) |
|
581 | + { |
|
582 | 582 | $out = array(); |
583 | 583 | $user = $this->switchObject($userID); |
584 | - if (null !== $user->getID()) { |
|
584 | + if (null !== $user->getID()) { |
|
585 | 585 | $member_groups = $this->modx->getFullTableName('member_groups'); |
586 | 586 | $membergroup_access = $this->modx->getFullTableName('membergroup_access'); |
587 | 587 | |
@@ -599,18 +599,18 @@ discard block |
||
599 | 599 | * @param int $userID |
600 | 600 | * @return array |
601 | 601 | */ |
602 | - public function getUserGroups($userID = 0) |
|
603 | - { |
|
602 | + public function getUserGroups($userID = 0) |
|
603 | + { |
|
604 | 604 | $out = array(); |
605 | 605 | $user = $this->switchObject($userID); |
606 | - if (null !== $user->getID()) { |
|
606 | + if (null !== $user->getID()) { |
|
607 | 607 | $member_groups = $this->makeTable('member_groups'); |
608 | 608 | $membergroup_names = $this->makeTable('membergroup_names'); |
609 | 609 | |
610 | 610 | $rs = $this->query("SELECT `ug`.`user_group`, `ugn`.`name` FROM {$member_groups} as `ug` |
611 | 611 | INNER JOIN {$membergroup_names} as `ugn` ON `ugn`.`id`=`ug`.`user_group` |
612 | 612 | WHERE `ug`.`member` = " . $user->getID()); |
613 | - while ($row = $this->modx->db->getRow($rs)) { |
|
613 | + while ($row = $this->modx->db->getRow($rs)) { |
|
614 | 614 | $out[$row['user_group']] = $row['name']; |
615 | 615 | } |
616 | 616 | } |
@@ -624,20 +624,20 @@ discard block |
||
624 | 624 | * @param array $groupIds |
625 | 625 | * @return $this |
626 | 626 | */ |
627 | - public function setUserGroups($userID = 0, $groupIds = array()) |
|
628 | - { |
|
629 | - if (!is_array($groupIds)) { |
|
627 | + public function setUserGroups($userID = 0, $groupIds = array()) |
|
628 | + { |
|
629 | + if (!is_array($groupIds)) { |
|
630 | 630 | return $this; |
631 | 631 | } |
632 | - if ($this->newDoc && $userID == 0) { |
|
632 | + if ($this->newDoc && $userID == 0) { |
|
633 | 633 | $this->groupIds = $groupIds; |
634 | - } else { |
|
634 | + } else { |
|
635 | 635 | $user = $this->switchObject($userID); |
636 | - if ($uid = $user->getID()) { |
|
637 | - foreach ($groupIds as $gid) { |
|
636 | + if ($uid = $user->getID()) { |
|
637 | + foreach ($groupIds as $gid) { |
|
638 | 638 | $this->query("REPLACE INTO {$this->makeTable('member_groups')} (`user_group`, `member`) VALUES ('{$gid}', '{$uid}')"); |
639 | 639 | } |
640 | - if (!$this->newDoc) { |
|
640 | + if (!$this->newDoc) { |
|
641 | 641 | $groupIds = empty($groupIds) ? '0' : implode(',', $groupIds); |
642 | 642 | $this->query("DELETE FROM {$this->makeTable('member_groups')} WHERE `member`={$uid} AND `user_group` NOT IN ({$groupIds})"); |
643 | 643 | } |
@@ -653,14 +653,14 @@ discard block |
||
653 | 653 | * @param string $pass |
654 | 654 | * @return string |
655 | 655 | */ |
656 | - public function getPasswordHashType($pass) |
|
657 | - { |
|
656 | + public function getPasswordHashType($pass) |
|
657 | + { |
|
658 | 658 | $out = 'unknown'; |
659 | - if (substr($pass, 0, 1) === '$') { |
|
659 | + if (substr($pass, 0, 1) === '$') { |
|
660 | 660 | $out = 'phpass'; |
661 | - } elseif (strpos($pass, '>') !== false) { |
|
661 | + } elseif (strpos($pass, '>') !== false) { |
|
662 | 662 | $out = 'v1'; |
663 | - } elseif (strlen($pass) === 32) { |
|
663 | + } elseif (strlen($pass) === 32) { |
|
664 | 664 | $out = 'md5'; |
665 | 665 | } |
666 | 666 | |
@@ -671,8 +671,8 @@ discard block |
||
671 | 671 | * @param string $pass |
672 | 672 | * @return string |
673 | 673 | */ |
674 | - public function getPasswordHashAlgorithm($pass) |
|
675 | - { |
|
674 | + public function getPasswordHashAlgorithm($pass) |
|
675 | + { |
|
676 | 676 | $pointer = strpos($pass, '>'); |
677 | 677 | $out = $pointer === false ? 'NOSALT' : substr($pass, 0, $pointer); |
678 | 678 | |
@@ -685,11 +685,11 @@ discard block |
||
685 | 685 | * @param string $algorithm |
686 | 686 | * @return string |
687 | 687 | */ |
688 | - public function makeHash($pass, $seed, $algorithm) |
|
689 | - { |
|
688 | + public function makeHash($pass, $seed, $algorithm) |
|
689 | + { |
|
690 | 690 | $salt = md5($pass . $seed); |
691 | 691 | |
692 | - switch ($algorithm) { |
|
692 | + switch ($algorithm) { |
|
693 | 693 | case 'BLOWFISH_Y': |
694 | 694 | $salt = '$2y$07$' . substr($salt, 0, 22); |
695 | 695 | break; |
@@ -164,9 +164,9 @@ discard block |
||
164 | 164 | session_regenerate_id(false); |
165 | 165 | $value = session_id(); |
166 | 166 | if ($mid = $this->modx->getLoginUserID('mgr')) { |
167 | - $this->modx->db->query("UPDATE {$this->makeTable('active_user_locks')} SET `sid`='{$value}' WHERE `internalKey`={$mid}"); |
|
168 | - $this->modx->db->query("UPDATE {$this->makeTable('active_user_sessions')} SET `sid`='{$value}' WHERE `internalKey`={$mid}"); |
|
169 | - $this->modx->db->query("UPDATE {$this->makeTable('active_users')} SET `sid`='{$value}' WHERE `internalKey`={$mid}"); |
|
167 | + $this->modx->db->query("update {$this->makeTable('active_user_locks')} SET `sid`='{$value}' WHERE `internalKey`={$mid}"); |
|
168 | + $this->modx->db->query("update {$this->makeTable('active_user_sessions')} SET `sid`='{$value}' WHERE `internalKey`={$mid}"); |
|
169 | + $this->modx->db->query("update {$this->makeTable('active_users')} SET `sid`='{$value}' WHERE `internalKey`={$mid}"); |
|
170 | 170 | } |
171 | 171 | break; |
172 | 172 | case 'editedon': |
@@ -243,7 +243,7 @@ discard block |
||
243 | 243 | if ($this->newDoc) { |
244 | 244 | $SQL = "INSERT into {$this->makeTable('manager_users')} SET " . implode(', ', $this->set['user']); |
245 | 245 | } else { |
246 | - $SQL = "UPDATE {$this->makeTable('manager_users')} SET " . implode(', ', |
|
246 | + $SQL = "update {$this->makeTable('manager_users')} SET " . implode(', ', |
|
247 | 247 | $this->set['user']) . " WHERE id = " . $this->id; |
248 | 248 | } |
249 | 249 | $this->query($SQL); |
@@ -267,7 +267,7 @@ discard block |
||
267 | 267 | $SQL = "INSERT into {$this->makeTable('user_attributes')} SET " . implode(', ', |
268 | 268 | $this->set['attribute']); |
269 | 269 | } else { |
270 | - $SQL = "UPDATE {$this->makeTable('user_attributes')} SET " . implode(', ', |
|
270 | + $SQL = "update {$this->makeTable('user_attributes')} SET " . implode(', ', |
|
271 | 271 | $this->set['attribute']) . " WHERE internalKey = " . $this->getID(); |
272 | 272 | } |
273 | 273 | $this->query($SQL); |
@@ -279,7 +279,7 @@ discard block |
||
279 | 279 | } |
280 | 280 | $result = $this->query("SELECT `setting_value` FROM {$this->makeTable('user_settings')} WHERE `user` = '{$this->id}' AND `setting_name` = '{$key}'"); |
281 | 281 | if ($this->modx->db->getRecordCount($result) > 0) { |
282 | - $this->query("UPDATE {$this->makeTable('user_settings')} SET `setting_value` = '{$value}' WHERE `user` = '{$this->id}' AND `setting_name` = '{$key}';"); |
|
282 | + $this->query("update {$this->makeTable('user_settings')} SET `setting_value` = '{$value}' WHERE `user` = '{$this->id}' AND `setting_name` = '{$key}';"); |
|
283 | 283 | } else { |
284 | 284 | $this->query("INSERT into {$this->makeTable('user_settings')} SET `user` = {$this->id},`setting_name` = '{$key}',`setting_value` = '{$value}';"); |
285 | 285 | } |