@@ -109,7 +109,7 @@ discard block |
||
| 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 | 114 | } else { |
| 115 | 115 | $this->set('editedon', time()); |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | */ |
| 145 | 145 | public function set($key, $value) |
| 146 | 146 | { |
| 147 | - if (is_scalar($value) && is_scalar($key) && !empty($key)) { |
|
| 147 | + if (is_scalar($value) && is_scalar($key) && ! empty($key)) { |
|
| 148 | 148 | switch ($key) { |
| 149 | 149 | case 'password': |
| 150 | 150 | $this->givenPassword = $value; |
@@ -193,14 +193,14 @@ discard block |
||
| 193 | 193 | return false; |
| 194 | 194 | } |
| 195 | 195 | |
| 196 | - if (!$this->checkUnique('web_users', 'username')) { |
|
| 196 | + if ( ! $this->checkUnique('web_users', 'username')) { |
|
| 197 | 197 | $this->log['UniqueUsername'] = 'username not unique <pre>' . print_r($this->get('username'), |
| 198 | 198 | true) . '</pre>'; |
| 199 | 199 | |
| 200 | 200 | return false; |
| 201 | 201 | } |
| 202 | 202 | |
| 203 | - if (!$this->checkUnique('web_user_attributes', 'email', 'internalKey')) { |
|
| 203 | + if ( ! $this->checkUnique('web_user_attributes', 'email', 'internalKey')) { |
|
| 204 | 204 | $this->log['UniqueEmail'] = 'Email not unique <pre>' . print_r($this->get('email'), true) . '</pre>'; |
| 205 | 205 | |
| 206 | 206 | return false; |
@@ -209,13 +209,13 @@ discard block |
||
| 209 | 209 | $fld = $this->toArray(); |
| 210 | 210 | foreach ($this->default_field['user'] as $key => $value) { |
| 211 | 211 | $tmp = $this->get($key); |
| 212 | - if ($this->newDoc && (!is_int($tmp) && $tmp == '')) { |
|
| 212 | + if ($this->newDoc && ( ! is_int($tmp) && $tmp == '')) { |
|
| 213 | 213 | $this->field[$key] = $value; |
| 214 | 214 | } |
| 215 | 215 | $this->Uset($key, 'user'); |
| 216 | 216 | unset($fld[$key]); |
| 217 | 217 | } |
| 218 | - if (!empty($this->set['user'])) { |
|
| 218 | + if ( ! empty($this->set['user'])) { |
|
| 219 | 219 | if ($this->newDoc) { |
| 220 | 220 | $SQL = "INSERT into {$this->makeTable('web_users')} SET " . implode(', ', $this->set['user']); |
| 221 | 221 | } else { |
@@ -233,7 +233,7 @@ discard block |
||
| 233 | 233 | unset($fld['id']); |
| 234 | 234 | |
| 235 | 235 | foreach ($fld as $key => $value) { |
| 236 | - if ($value == '' || !$this->isChanged($key)) { |
|
| 236 | + if ($value == '' || ! $this->isChanged($key)) { |
|
| 237 | 237 | continue; |
| 238 | 238 | } |
| 239 | 239 | $result = $this->query("SELECT `setting_value` FROM {$this->makeTable('web_user_settings')} WHERE `webuser` = '{$this->id}' AND `setting_name` = '{$key}'"); |
@@ -243,7 +243,7 @@ discard block |
||
| 243 | 243 | $this->query("INSERT into {$this->makeTable('web_user_settings')} SET `webuser` = {$this->id},`setting_name` = '{$key}',`setting_value` = '{$value}';"); |
| 244 | 244 | } |
| 245 | 245 | } |
| 246 | - if (!$this->newDoc && $this->givenPassword) { |
|
| 246 | + if ( ! $this->newDoc && $this->givenPassword) { |
|
| 247 | 247 | $this->invokeEvent('OnWebChangePassword', array( |
| 248 | 248 | 'userObj' => $this, |
| 249 | 249 | 'userid' => $this->id, |
@@ -276,13 +276,13 @@ discard block |
||
| 276 | 276 | protected function saveQuery(array &$fld) { |
| 277 | 277 | foreach ($this->default_field['attribute'] as $key => $value) { |
| 278 | 278 | $tmp = $this->get($key); |
| 279 | - if ($this->newDoc && (!is_int($tmp) && $tmp == '')) { |
|
| 279 | + if ($this->newDoc && ( ! is_int($tmp) && $tmp == '')) { |
|
| 280 | 280 | $this->field[$key] = $value; |
| 281 | 281 | } |
| 282 | 282 | $this->Uset($key, 'attribute'); |
| 283 | 283 | unset($fld[$key]); |
| 284 | 284 | } |
| 285 | - if (!empty($this->set['attribute'])) { |
|
| 285 | + if ( ! empty($this->set['attribute'])) { |
|
| 286 | 286 | if ($this->newDoc) { |
| 287 | 287 | $this->set('internalKey', $this->id)->Uset('internalKey', 'attribute'); |
| 288 | 288 | $SQL = "INSERT into {$this->makeTable('web_user_attributes')} SET " . implode(', ', |
@@ -372,7 +372,7 @@ discard block |
||
| 372 | 372 | $b = $tmp->get('blocked'); |
| 373 | 373 | $bu = $tmp->get('blockeduntil'); |
| 374 | 374 | $ba = $tmp->get('blockedafter'); |
| 375 | - $flag = (($b && !$bu && !$ba) || ($bu && $now < $bu) || ($ba && $now > $ba)); |
|
| 375 | + $flag = (($b && ! $bu && ! $ba) || ($bu && $now < $bu) || ($ba && $now > $ba)); |
|
| 376 | 376 | unset($tmp); |
| 377 | 377 | |
| 378 | 378 | return $flag; |
@@ -394,7 +394,7 @@ discard block |
||
| 394 | 394 | |
| 395 | 395 | $flag = $pluginFlag = false; |
| 396 | 396 | if ( |
| 397 | - (null !== $tmp->getID()) && (!$blocker || ($blocker && !$tmp->checkBlock($id))) |
|
| 397 | + (null !== $tmp->getID()) && ( ! $blocker || ($blocker && ! $tmp->checkBlock($id))) |
|
| 398 | 398 | ) { |
| 399 | 399 | $eventResult = $this->getInvokeEventResult('OnWebAuthentication', array( |
| 400 | 400 | 'userObj' => $this, |
@@ -410,7 +410,7 @@ discard block |
||
| 410 | 410 | } else { |
| 411 | 411 | $pluginFlag = (bool)$eventResult; |
| 412 | 412 | } |
| 413 | - if (!$pluginFlag) { |
|
| 413 | + if ( ! $pluginFlag) { |
|
| 414 | 414 | $flag = ($tmp->get('password') == $tmp->getPassword($password)); |
| 415 | 415 | } |
| 416 | 416 | } |
@@ -430,7 +430,7 @@ discard block |
||
| 430 | 430 | if (isset($_COOKIE[$cookieName])) { |
| 431 | 431 | $cookie = explode('|', $_COOKIE[$cookieName], 4); |
| 432 | 432 | if (isset($cookie[0], $cookie[1], $cookie[2]) && strlen($cookie[0]) == 32 && strlen($cookie[1]) == 32) { |
| 433 | - if (!$fulltime && isset($cookie[4])) { |
|
| 433 | + if ( ! $fulltime && isset($cookie[4])) { |
|
| 434 | 434 | $fulltime = (int)$cookie[4]; |
| 435 | 435 | } |
| 436 | 436 | $this->close(); |
@@ -441,7 +441,7 @@ discard block |
||
| 441 | 441 | && null !== $this->getID() |
| 442 | 442 | && $this->get('password') == $cookie[1] |
| 443 | 443 | && $this->get('sessionid') == $cookie[2] |
| 444 | - && !$this->checkBlock($this->getID()) |
|
| 444 | + && ! $this->checkBlock($this->getID()) |
|
| 445 | 445 | ) { |
| 446 | 446 | $flag = $this->authUser($this->getID(), $fulltime, $cookieName, $fire_events); |
| 447 | 447 | |
@@ -458,7 +458,7 @@ discard block |
||
| 458 | 458 | */ |
| 459 | 459 | public function logOut($cookieName = 'WebLoginPE', $fire_events = null) |
| 460 | 460 | { |
| 461 | - if (!$uid = $this->modx->getLoginUserID('web')) { |
|
| 461 | + if ( ! $uid = $this->modx->getLoginUserID('web')) { |
|
| 462 | 462 | return; |
| 463 | 463 | } |
| 464 | 464 | $params = array( |
@@ -553,7 +553,7 @@ discard block |
||
| 553 | 553 | */ |
| 554 | 554 | public function setAutoLoginCookie($cookieName, $remember = true) |
| 555 | 555 | { |
| 556 | - if (!empty($cookieName) && $this->getID()) { |
|
| 556 | + if ( ! empty($cookieName) && $this->getID()) { |
|
| 557 | 557 | $secure = $this->isSecure(); |
| 558 | 558 | $remember = is_bool($remember) ? (60 * 60 * 24 * 365 * 5) : (int)$remember; |
| 559 | 559 | $cookieValue = array(md5($this->get('username')), $this->get('password'), $this->get('sessionid'), $remember); |
@@ -619,7 +619,7 @@ discard block |
||
| 619 | 619 | */ |
| 620 | 620 | public function setUserGroups($userID = 0, $groupIds = array()) |
| 621 | 621 | { |
| 622 | - if (!is_array($groupIds)) return $this; |
|
| 622 | + if ( ! is_array($groupIds)) return $this; |
|
| 623 | 623 | if ($this->newDoc && $userID == 0) { |
| 624 | 624 | $this->groupIds = $groupIds; |
| 625 | 625 | } else { |
@@ -628,7 +628,7 @@ discard block |
||
| 628 | 628 | foreach ($groupIds as $gid) { |
| 629 | 629 | $this->query("REPLACE INTO {$this->makeTable('web_groups')} (`webgroup`, `webuser`) VALUES ('{$gid}', '{$uid}')"); |
| 630 | 630 | } |
| 631 | - if (!$this->newDoc) { |
|
| 631 | + if ( ! $this->newDoc) { |
|
| 632 | 632 | $groupIds = empty($groupIds) ? '0' : implode(',', $groupIds); |
| 633 | 633 | $this->query("DELETE FROM {$this->makeTable('web_groups')} WHERE `webuser`={$uid} AND `webgroup` NOT IN ({$groupIds})"); |
| 634 | 634 | } |
@@ -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 | $this->editQuery($find, $id); |
| 117 | 117 | $this->id = empty($this->field['internalKey']) ? null : $this->get('internalKey'); |
@@ -128,7 +128,8 @@ discard block |
||
| 128 | 128 | * @param string $find |
| 129 | 129 | * @param string $id |
| 130 | 130 | */ |
| 131 | - protected function editQuery($find, $id) { |
|
| 131 | + protected function editQuery($find, $id) |
|
| 132 | + {
|
|
| 132 | 133 | $result = $this->query(" |
| 133 | 134 | SELECT * from {$this->makeTable('web_user_attributes')} as attribute |
| 134 | 135 | LEFT JOIN {$this->makeTable('web_users')} as user ON user.id=attribute.internalKey |
@@ -142,10 +143,10 @@ discard block |
||
| 142 | 143 | * @param $value |
| 143 | 144 | * @return $this |
| 144 | 145 | */ |
| 145 | - public function set($key, $value) |
|
| 146 | - { |
|
| 147 | - if (is_scalar($value) && is_scalar($key) && !empty($key)) { |
|
| 148 | - switch ($key) { |
|
| 146 | + public function set($key, $value) |
|
| 147 | + {
|
|
| 148 | + if (is_scalar($value) && is_scalar($key) && !empty($key)) {
|
|
| 149 | + switch ($key) {
|
|
| 149 | 150 | case 'password': |
| 150 | 151 | $this->givenPassword = $value; |
| 151 | 152 | $value = $this->getPassword($value); |
@@ -153,7 +154,7 @@ discard block |
||
| 153 | 154 | case 'sessionid': |
| 154 | 155 | session_regenerate_id(false); |
| 155 | 156 | $value = session_id(); |
| 156 | - if ($mid = $this->modx->getLoginUserID('mgr')) { |
|
| 157 | + if ($mid = $this->modx->getLoginUserID('mgr')) {
|
|
| 157 | 158 | $this->modx->db->query("UPDATE {$this->makeTable('active_user_locks')} SET `sid`='{$value}' WHERE `internalKey`={$mid}"); |
| 158 | 159 | $this->modx->db->query("UPDATE {$this->makeTable('active_user_sessions')} SET `sid`='{$value}' WHERE `internalKey`={$mid}"); |
| 159 | 160 | $this->modx->db->query("UPDATE {$this->makeTable('active_users')} SET `sid`='{$value}' WHERE `internalKey`={$mid}"); |
@@ -174,8 +175,8 @@ discard block |
||
| 174 | 175 | * @param $pass |
| 175 | 176 | * @return string |
| 176 | 177 | */ |
| 177 | - public function getPassword($pass) |
|
| 178 | - { |
|
| 178 | + public function getPassword($pass) |
|
| 179 | + {
|
|
| 179 | 180 | return md5($pass); |
| 180 | 181 | } |
| 181 | 182 | |
@@ -184,66 +185,66 @@ discard block |
||
| 184 | 185 | * @param bool $clearCache |
| 185 | 186 | * @return bool|int|null|void |
| 186 | 187 | */ |
| 187 | - public function save($fire_events = false, $clearCache = false) |
|
| 188 | - { |
|
| 189 | - if ($this->get('email') == '' || $this->get('username') == '' || $this->get('password') == '') { |
|
| 188 | + public function save($fire_events = false, $clearCache = false) |
|
| 189 | + {
|
|
| 190 | + if ($this->get('email') == '' || $this->get('username') == '' || $this->get('password') == '') {
|
|
| 190 | 191 | $this->log['EmptyPKField'] = 'Email, username or password is empty <pre>' . print_r($this->toArray(), |
| 191 | 192 | true) . '</pre>'; |
| 192 | 193 | |
| 193 | 194 | return false; |
| 194 | 195 | } |
| 195 | 196 | |
| 196 | - if (!$this->checkUnique('web_users', 'username')) { |
|
| 197 | + if (!$this->checkUnique('web_users', 'username')) {
|
|
| 197 | 198 | $this->log['UniqueUsername'] = 'username not unique <pre>' . print_r($this->get('username'), |
| 198 | 199 | true) . '</pre>'; |
| 199 | 200 | |
| 200 | 201 | return false; |
| 201 | 202 | } |
| 202 | 203 | |
| 203 | - if (!$this->checkUnique('web_user_attributes', 'email', 'internalKey')) { |
|
| 204 | + if (!$this->checkUnique('web_user_attributes', 'email', 'internalKey')) {
|
|
| 204 | 205 | $this->log['UniqueEmail'] = 'Email not unique <pre>' . print_r($this->get('email'), true) . '</pre>'; |
| 205 | 206 | |
| 206 | 207 | return false; |
| 207 | 208 | } |
| 208 | 209 | $this->set('sessionid', ''); |
| 209 | 210 | $fld = $this->toArray(); |
| 210 | - foreach ($this->default_field['user'] as $key => $value) { |
|
| 211 | + foreach ($this->default_field['user'] as $key => $value) {
|
|
| 211 | 212 | $tmp = $this->get($key); |
| 212 | - if ($this->newDoc && (!is_int($tmp) && $tmp == '')) { |
|
| 213 | + if ($this->newDoc && (!is_int($tmp) && $tmp == '')) {
|
|
| 213 | 214 | $this->field[$key] = $value; |
| 214 | 215 | } |
| 215 | 216 | $this->Uset($key, 'user'); |
| 216 | 217 | unset($fld[$key]); |
| 217 | 218 | } |
| 218 | - if (!empty($this->set['user'])) { |
|
| 219 | - if ($this->newDoc) { |
|
| 219 | + if (!empty($this->set['user'])) {
|
|
| 220 | + if ($this->newDoc) {
|
|
| 220 | 221 | $SQL = "INSERT into {$this->makeTable('web_users')} SET " . implode(', ', $this->set['user']); |
| 221 | - } else { |
|
| 222 | + } else {
|
|
| 222 | 223 | $SQL = "UPDATE {$this->makeTable('web_users')} SET " . implode(', ', |
| 223 | 224 | $this->set['user']) . " WHERE id = " . $this->id; |
| 224 | 225 | } |
| 225 | 226 | $this->query($SQL); |
| 226 | 227 | } |
| 227 | 228 | |
| 228 | - if ($this->newDoc) { |
|
| 229 | + if ($this->newDoc) {
|
|
| 229 | 230 | $this->id = $this->modx->db->getInsertId(); |
| 230 | 231 | } |
| 231 | 232 | |
| 232 | 233 | $this->saveQuery($fld); |
| 233 | 234 | unset($fld['id']); |
| 234 | 235 | |
| 235 | - foreach ($fld as $key => $value) { |
|
| 236 | - if ($value == '' || !$this->isChanged($key)) { |
|
| 236 | + foreach ($fld as $key => $value) {
|
|
| 237 | + if ($value == '' || !$this->isChanged($key)) {
|
|
| 237 | 238 | continue; |
| 238 | 239 | } |
| 239 | 240 | $result = $this->query("SELECT `setting_value` FROM {$this->makeTable('web_user_settings')} WHERE `webuser` = '{$this->id}' AND `setting_name` = '{$key}'"); |
| 240 | - if ($this->modx->db->getRecordCount($result) > 0) { |
|
| 241 | + if ($this->modx->db->getRecordCount($result) > 0) {
|
|
| 241 | 242 | $this->query("UPDATE {$this->makeTable('web_user_settings')} SET `setting_value` = '{$value}' WHERE `webuser` = '{$this->id}' AND `setting_name` = '{$key}';"); |
| 242 | - } else { |
|
| 243 | + } else {
|
|
| 243 | 244 | $this->query("INSERT into {$this->makeTable('web_user_settings')} SET `webuser` = {$this->id},`setting_name` = '{$key}',`setting_value` = '{$value}';"); |
| 244 | 245 | } |
| 245 | 246 | } |
| 246 | - if (!$this->newDoc && $this->givenPassword) { |
|
| 247 | + if (!$this->newDoc && $this->givenPassword) {
|
|
| 247 | 248 | $this->invokeEvent('OnWebChangePassword', array( |
| 248 | 249 | 'userObj' => $this, |
| 249 | 250 | 'userid' => $this->id, |
@@ -254,7 +255,9 @@ discard block |
||
| 254 | 255 | ), $fire_events); |
| 255 | 256 | } |
| 256 | 257 | |
| 257 | - if ($this->groupIds) $this->setUserGroups($this->id, $this->groupIds); |
|
| 258 | + if ($this->groupIds) {
|
|
| 259 | + $this->setUserGroups($this->id, $this->groupIds); |
|
| 260 | + } |
|
| 258 | 261 | |
| 259 | 262 | $this->invokeEvent('OnWebSaveUser', array( |
| 260 | 263 | 'userObj' => $this, |
@@ -263,7 +266,7 @@ discard block |
||
| 263 | 266 | 'user' => $this->toArray() |
| 264 | 267 | ), $fire_events); |
| 265 | 268 | |
| 266 | - if ($clearCache) { |
|
| 269 | + if ($clearCache) {
|
|
| 267 | 270 | $this->clearCache($fire_events); |
| 268 | 271 | } |
| 269 | 272 | |
@@ -273,21 +276,22 @@ discard block |
||
| 273 | 276 | /** |
| 274 | 277 | * @param array $fld |
| 275 | 278 | */ |
| 276 | - protected function saveQuery(array &$fld) { |
|
| 277 | - foreach ($this->default_field['attribute'] as $key => $value) { |
|
| 279 | + protected function saveQuery(array &$fld) |
|
| 280 | + {
|
|
| 281 | + foreach ($this->default_field['attribute'] as $key => $value) {
|
|
| 278 | 282 | $tmp = $this->get($key); |
| 279 | - if ($this->newDoc && (!is_int($tmp) && $tmp == '')) { |
|
| 283 | + if ($this->newDoc && (!is_int($tmp) && $tmp == '')) {
|
|
| 280 | 284 | $this->field[$key] = $value; |
| 281 | 285 | } |
| 282 | 286 | $this->Uset($key, 'attribute'); |
| 283 | 287 | unset($fld[$key]); |
| 284 | 288 | } |
| 285 | - if (!empty($this->set['attribute'])) { |
|
| 286 | - if ($this->newDoc) { |
|
| 289 | + if (!empty($this->set['attribute'])) {
|
|
| 290 | + if ($this->newDoc) {
|
|
| 287 | 291 | $this->set('internalKey', $this->id)->Uset('internalKey', 'attribute'); |
| 288 | 292 | $SQL = "INSERT into {$this->makeTable('web_user_attributes')} SET " . implode(', ', |
| 289 | 293 | $this->set['attribute']); |
| 290 | - } else { |
|
| 294 | + } else {
|
|
| 291 | 295 | $SQL = "UPDATE {$this->makeTable('web_user_attributes')} SET " . implode(', ', |
| 292 | 296 | $this->set['attribute']) . " WHERE internalKey = " . $this->getID(); |
| 293 | 297 | } |
@@ -300,9 +304,9 @@ discard block |
||
| 300 | 304 | * @param bool $fire_events |
| 301 | 305 | * @return bool|null|void |
| 302 | 306 | */ |
| 303 | - public function delete($ids, $fire_events = false) |
|
| 304 | - { |
|
| 305 | - if ($this->edit($ids)) { |
|
| 307 | + public function delete($ids, $fire_events = false) |
|
| 308 | + {
|
|
| 309 | + if ($this->edit($ids)) {
|
|
| 306 | 310 | $flag = $this->deleteQuery(); |
| 307 | 311 | $this->query("DELETE FROM {$this->makeTable('web_user_settings')} WHERE webuser='{$this->getID()}'"); |
| 308 | 312 | $this->query("DELETE FROM {$this->makeTable('web_groups')} WHERE webuser='{$this->getID()}'"); |
@@ -313,7 +317,7 @@ discard block |
||
| 313 | 317 | 'username' => $this->get('username'), |
| 314 | 318 | 'timestamp' => time() |
| 315 | 319 | ), $fire_events); |
| 316 | - } else { |
|
| 320 | + } else {
|
|
| 317 | 321 | $flag = false; |
| 318 | 322 | } |
| 319 | 323 | $this->close(); |
@@ -321,7 +325,8 @@ discard block |
||
| 321 | 325 | return $flag; |
| 322 | 326 | } |
| 323 | 327 | |
| 324 | - protected function deleteQuery() { |
|
| 328 | + protected function deleteQuery() |
|
| 329 | + {
|
|
| 325 | 330 | return $this->query(" |
| 326 | 331 | DELETE user,attribute FROM {$this->makeTable('web_user_attributes')} as attribute |
| 327 | 332 | LEFT JOIN {$this->makeTable('web_users')} as user ON user.id=attribute.internalKey |
@@ -335,13 +340,13 @@ discard block |
||
| 335 | 340 | * @param bool $fire_events |
| 336 | 341 | * @return bool |
| 337 | 342 | */ |
| 338 | - public function authUser($id = 0, $fulltime = true, $cookieName = 'WebLoginPE', $fire_events = false) |
|
| 339 | - { |
|
| 343 | + public function authUser($id = 0, $fulltime = true, $cookieName = 'WebLoginPE', $fire_events = false) |
|
| 344 | + {
|
|
| 340 | 345 | $flag = false; |
| 341 | - if (null === $this->getID() && $id) { |
|
| 346 | + if (null === $this->getID() && $id) {
|
|
| 342 | 347 | $this->edit($id); |
| 343 | 348 | } |
| 344 | - if (null !== $this->getID()) { |
|
| 349 | + if (null !== $this->getID()) {
|
|
| 345 | 350 | $flag = true; |
| 346 | 351 | $this->save(false); |
| 347 | 352 | $this->SessionHandler('start', $cookieName, $fulltime); |
@@ -361,10 +366,10 @@ discard block |
||
| 361 | 366 | * @param int $id |
| 362 | 367 | * @return bool |
| 363 | 368 | */ |
| 364 | - public function checkBlock($id = 0) |
|
| 365 | - { |
|
| 369 | + public function checkBlock($id = 0) |
|
| 370 | + {
|
|
| 366 | 371 | $tmp = clone $this; |
| 367 | - if ($id && $tmp->getID() != $id) { |
|
| 372 | + if ($id && $tmp->getID() != $id) {
|
|
| 368 | 373 | $tmp->edit($id); |
| 369 | 374 | } |
| 370 | 375 | $now = time(); |
@@ -385,17 +390,17 @@ discard block |
||
| 385 | 390 | * @param bool $fire_events |
| 386 | 391 | * @return bool |
| 387 | 392 | */ |
| 388 | - public function testAuth($id, $password, $blocker, $fire_events = false) |
|
| 389 | - { |
|
| 393 | + public function testAuth($id, $password, $blocker, $fire_events = false) |
|
| 394 | + {
|
|
| 390 | 395 | $tmp = clone $this; |
| 391 | - if ($id && $tmp->getID() != $id) { |
|
| 396 | + if ($id && $tmp->getID() != $id) {
|
|
| 392 | 397 | $tmp->edit($id); |
| 393 | 398 | } |
| 394 | 399 | |
| 395 | 400 | $flag = $pluginFlag = false; |
| 396 | 401 | if ( |
| 397 | 402 | (null !== $tmp->getID()) && (!$blocker || ($blocker && !$tmp->checkBlock($id))) |
| 398 | - ) { |
|
| 403 | + ) {
|
|
| 399 | 404 | $eventResult = $this->getInvokeEventResult('OnWebAuthentication', array( |
| 400 | 405 | 'userObj' => $this, |
| 401 | 406 | 'userid' => $tmp->getID(), |
@@ -403,14 +408,14 @@ discard block |
||
| 403 | 408 | 'userpassword' => $password, |
| 404 | 409 | 'savedpassword' => $tmp->get('password') |
| 405 | 410 | ), $fire_events); |
| 406 | - if (is_array($eventResult)) { |
|
| 407 | - foreach ($eventResult as $result) { |
|
| 411 | + if (is_array($eventResult)) {
|
|
| 412 | + foreach ($eventResult as $result) {
|
|
| 408 | 413 | $pluginFlag = (bool)$result; |
| 409 | 414 | } |
| 410 | - } else { |
|
| 415 | + } else {
|
|
| 411 | 416 | $pluginFlag = (bool)$eventResult; |
| 412 | 417 | } |
| 413 | - if (!$pluginFlag) { |
|
| 418 | + if (!$pluginFlag) {
|
|
| 414 | 419 | $flag = ($tmp->get('password') == $tmp->getPassword($password)); |
| 415 | 420 | } |
| 416 | 421 | } |
@@ -424,13 +429,13 @@ discard block |
||
| 424 | 429 | * @param string $cookieName |
| 425 | 430 | * @return bool |
| 426 | 431 | */ |
| 427 | - public function AutoLogin($fulltime = true, $cookieName = 'WebLoginPE', $fire_events = null) |
|
| 428 | - { |
|
| 432 | + public function AutoLogin($fulltime = true, $cookieName = 'WebLoginPE', $fire_events = null) |
|
| 433 | + {
|
|
| 429 | 434 | $flag = false; |
| 430 | - if (isset($_COOKIE[$cookieName])) { |
|
| 435 | + if (isset($_COOKIE[$cookieName])) {
|
|
| 431 | 436 | $cookie = explode('|', $_COOKIE[$cookieName], 4); |
| 432 | - if (isset($cookie[0], $cookie[1], $cookie[2]) && strlen($cookie[0]) == 32 && strlen($cookie[1]) == 32) { |
|
| 433 | - if (!$fulltime && isset($cookie[4])) { |
|
| 437 | + if (isset($cookie[0], $cookie[1], $cookie[2]) && strlen($cookie[0]) == 32 && strlen($cookie[1]) == 32) {
|
|
| 438 | + if (!$fulltime && isset($cookie[4])) {
|
|
| 434 | 439 | $fulltime = (int)$cookie[4]; |
| 435 | 440 | } |
| 436 | 441 | $this->close(); |
@@ -442,7 +447,7 @@ discard block |
||
| 442 | 447 | && $this->get('password') == $cookie[1] |
| 443 | 448 | && $this->get('sessionid') == $cookie[2] |
| 444 | 449 | && !$this->checkBlock($this->getID()) |
| 445 | - ) { |
|
| 450 | + ) {
|
|
| 446 | 451 | $flag = $this->authUser($this->getID(), $fulltime, $cookieName, $fire_events); |
| 447 | 452 | |
| 448 | 453 | } |
@@ -456,9 +461,9 @@ discard block |
||
| 456 | 461 | * @param string $cookieName |
| 457 | 462 | * @param null $fire_events |
| 458 | 463 | */ |
| 459 | - public function logOut($cookieName = 'WebLoginPE', $fire_events = null) |
|
| 460 | - { |
|
| 461 | - if (!$uid = $this->modx->getLoginUserID('web')) { |
|
| 464 | + public function logOut($cookieName = 'WebLoginPE', $fire_events = null) |
|
| 465 | + {
|
|
| 466 | + if (!$uid = $this->modx->getLoginUserID('web')) {
|
|
| 462 | 467 | return; |
| 463 | 468 | } |
| 464 | 469 | $params = array( |
@@ -483,11 +488,11 @@ discard block |
||
| 483 | 488 | * |
| 484 | 489 | * remeber может быть числом в секундах |
| 485 | 490 | */ |
| 486 | - protected function SessionHandler($directive, $cookieName, $remember = true) |
|
| 487 | - { |
|
| 488 | - switch ($directive) { |
|
| 491 | + protected function SessionHandler($directive, $cookieName, $remember = true) |
|
| 492 | + {
|
|
| 493 | + switch ($directive) {
|
|
| 489 | 494 | case 'start': |
| 490 | - if ($this->getID()) { |
|
| 495 | + if ($this->getID()) {
|
|
| 491 | 496 | $_SESSION['webShortname'] = $this->get('username'); |
| 492 | 497 | $_SESSION['webFullname'] = $this->get('fullname'); |
| 493 | 498 | $_SESSION['webEmail'] = $this->get('email'); |
@@ -501,13 +506,13 @@ discard block |
||
| 501 | 506 | $_SESSION['webUsrConfigSet'] = array(); |
| 502 | 507 | $_SESSION['webUserGroupNames'] = $this->getUserGroups(); |
| 503 | 508 | $_SESSION['webDocgroups'] = $this->getDocumentGroups(); |
| 504 | - if ($remember) { |
|
| 509 | + if ($remember) {
|
|
| 505 | 510 | $this->setAutoLoginCookie($cookieName, $remember); |
| 506 | 511 | } |
| 507 | 512 | } |
| 508 | 513 | break; |
| 509 | 514 | case 'destroy': |
| 510 | - if (isset($_SESSION['mgrValidated'])) { |
|
| 515 | + if (isset($_SESSION['mgrValidated'])) {
|
|
| 511 | 516 | unset($_SESSION['webShortname']); |
| 512 | 517 | unset($_SESSION['webFullname']); |
| 513 | 518 | unset($_SESSION['webEmail']); |
@@ -523,8 +528,8 @@ discard block |
||
| 523 | 528 | unset($_SESSION['webDocgroups']); |
| 524 | 529 | |
| 525 | 530 | setcookie($cookieName, '', time() - 60, MODX_BASE_URL); |
| 526 | - } else { |
|
| 527 | - if (isset($_COOKIE[session_name()])) { |
|
| 531 | + } else {
|
|
| 532 | + if (isset($_COOKIE[session_name()])) {
|
|
| 528 | 533 | setcookie(session_name(), '', time() - 60, MODX_BASE_URL); |
| 529 | 534 | } |
| 530 | 535 | setcookie($cookieName, '', time() - 60, MODX_BASE_URL); |
@@ -539,8 +544,8 @@ discard block |
||
| 539 | 544 | /** |
| 540 | 545 | * @return bool |
| 541 | 546 | */ |
| 542 | - public function isSecure() |
|
| 543 | - { |
|
| 547 | + public function isSecure() |
|
| 548 | + {
|
|
| 544 | 549 | $out = $this->modxConfig('server_protocol') == 'http' ? false : true; |
| 545 | 550 | |
| 546 | 551 | return $out; |
@@ -551,9 +556,9 @@ discard block |
||
| 551 | 556 | * @param bool $remember |
| 552 | 557 | * @return $this |
| 553 | 558 | */ |
| 554 | - public function setAutoLoginCookie($cookieName, $remember = true) |
|
| 555 | - { |
|
| 556 | - if (!empty($cookieName) && $this->getID()) { |
|
| 559 | + public function setAutoLoginCookie($cookieName, $remember = true) |
|
| 560 | + {
|
|
| 561 | + if (!empty($cookieName) && $this->getID()) {
|
|
| 557 | 562 | $secure = $this->isSecure(); |
| 558 | 563 | $remember = is_bool($remember) ? (60 * 60 * 24 * 365 * 5) : (int)$remember; |
| 559 | 564 | $cookieValue = array(md5($this->get('username')), $this->get('password'), $this->get('sessionid'), $remember); |
@@ -569,11 +574,11 @@ discard block |
||
| 569 | 574 | * @param int $userID |
| 570 | 575 | * @return array |
| 571 | 576 | */ |
| 572 | - public function getDocumentGroups($userID = 0) |
|
| 573 | - { |
|
| 577 | + public function getDocumentGroups($userID = 0) |
|
| 578 | + {
|
|
| 574 | 579 | $out = array(); |
| 575 | 580 | $user = $this->switchObject($userID); |
| 576 | - if (null !== $user->getID()) { |
|
| 581 | + if (null !== $user->getID()) {
|
|
| 577 | 582 | $web_groups = $this->modx->getFullTableName('web_groups'); |
| 578 | 583 | $webgroup_access = $this->modx->getFullTableName('webgroup_access'); |
| 579 | 584 | |
@@ -592,18 +597,18 @@ discard block |
||
| 592 | 597 | * @param int $userID |
| 593 | 598 | * @return array |
| 594 | 599 | */ |
| 595 | - public function getUserGroups($userID = 0) |
|
| 596 | - { |
|
| 600 | + public function getUserGroups($userID = 0) |
|
| 601 | + {
|
|
| 597 | 602 | $out = array(); |
| 598 | 603 | $user = $this->switchObject($userID); |
| 599 | - if (null !== $user->getID()) { |
|
| 604 | + if (null !== $user->getID()) {
|
|
| 600 | 605 | $web_groups = $this->makeTable('web_groups'); |
| 601 | 606 | $webgroup_names = $this->makeTable('webgroup_names'); |
| 602 | 607 | |
| 603 | 608 | $rs = $this->query("SELECT `ug`.`webgroup`, `ugn`.`name` FROM {$web_groups} as `ug` |
| 604 | 609 | INNER JOIN {$webgroup_names} as `ugn` ON `ugn`.`id`=`ug`.`webgroup` |
| 605 | 610 | WHERE `ug`.`webuser` = " . $user->getID()); |
| 606 | - while ($row = $this->modx->db->getRow($rs)) { |
|
| 611 | + while ($row = $this->modx->db->getRow($rs)) {
|
|
| 607 | 612 | $out[$row['webgroup']] = $row['name']; |
| 608 | 613 | } |
| 609 | 614 | } |
@@ -617,18 +622,20 @@ discard block |
||
| 617 | 622 | * @param array $groupIds |
| 618 | 623 | * @return $this |
| 619 | 624 | */ |
| 620 | - public function setUserGroups($userID = 0, $groupIds = array()) |
|
| 621 | - { |
|
| 622 | - if (!is_array($groupIds)) return $this; |
|
| 623 | - if ($this->newDoc && $userID == 0) { |
|
| 625 | + public function setUserGroups($userID = 0, $groupIds = array()) |
|
| 626 | + {
|
|
| 627 | + if (!is_array($groupIds)) {
|
|
| 628 | + return $this; |
|
| 629 | + } |
|
| 630 | + if ($this->newDoc && $userID == 0) {
|
|
| 624 | 631 | $this->groupIds = $groupIds; |
| 625 | - } else { |
|
| 632 | + } else {
|
|
| 626 | 633 | $user = $this->switchObject($userID); |
| 627 | - if ($uid = $user->getID()) { |
|
| 628 | - foreach ($groupIds as $gid) { |
|
| 634 | + if ($uid = $user->getID()) {
|
|
| 635 | + foreach ($groupIds as $gid) {
|
|
| 629 | 636 | $this->query("REPLACE INTO {$this->makeTable('web_groups')} (`webgroup`, `webuser`) VALUES ('{$gid}', '{$uid}')"); |
| 630 | 637 | } |
| 631 | - if (!$this->newDoc) { |
|
| 638 | + if (!$this->newDoc) {
|
|
| 632 | 639 | $groupIds = empty($groupIds) ? '0' : implode(',', $groupIds); |
| 633 | 640 | $this->query("DELETE FROM {$this->makeTable('web_groups')} WHERE `webuser`={$uid} AND `webgroup` NOT IN ({$groupIds})"); |
| 634 | 641 | } |
@@ -154,9 +154,9 @@ discard block |
||
| 154 | 154 | session_regenerate_id(false); |
| 155 | 155 | $value = session_id(); |
| 156 | 156 | if ($mid = $this->modx->getLoginUserID('mgr')) { |
| 157 | - $this->modx->db->query("UPDATE {$this->makeTable('active_user_locks')} SET `sid`='{$value}' WHERE `internalKey`={$mid}"); |
|
| 158 | - $this->modx->db->query("UPDATE {$this->makeTable('active_user_sessions')} SET `sid`='{$value}' WHERE `internalKey`={$mid}"); |
|
| 159 | - $this->modx->db->query("UPDATE {$this->makeTable('active_users')} SET `sid`='{$value}' WHERE `internalKey`={$mid}"); |
|
| 157 | + $this->modx->db->query("update {$this->makeTable('active_user_locks')} SET `sid`='{$value}' WHERE `internalKey`={$mid}"); |
|
| 158 | + $this->modx->db->query("update {$this->makeTable('active_user_sessions')} SET `sid`='{$value}' WHERE `internalKey`={$mid}"); |
|
| 159 | + $this->modx->db->query("update {$this->makeTable('active_users')} SET `sid`='{$value}' WHERE `internalKey`={$mid}"); |
|
| 160 | 160 | } |
| 161 | 161 | break; |
| 162 | 162 | case 'editedon': |
@@ -219,7 +219,7 @@ discard block |
||
| 219 | 219 | if ($this->newDoc) { |
| 220 | 220 | $SQL = "INSERT into {$this->makeTable('web_users')} SET " . implode(', ', $this->set['user']); |
| 221 | 221 | } else { |
| 222 | - $SQL = "UPDATE {$this->makeTable('web_users')} SET " . implode(', ', |
|
| 222 | + $SQL = "update {$this->makeTable('web_users')} SET " . implode(', ', |
|
| 223 | 223 | $this->set['user']) . " WHERE id = " . $this->id; |
| 224 | 224 | } |
| 225 | 225 | $this->query($SQL); |
@@ -238,7 +238,7 @@ discard block |
||
| 238 | 238 | } |
| 239 | 239 | $result = $this->query("SELECT `setting_value` FROM {$this->makeTable('web_user_settings')} WHERE `webuser` = '{$this->id}' AND `setting_name` = '{$key}'"); |
| 240 | 240 | if ($this->modx->db->getRecordCount($result) > 0) { |
| 241 | - $this->query("UPDATE {$this->makeTable('web_user_settings')} SET `setting_value` = '{$value}' WHERE `webuser` = '{$this->id}' AND `setting_name` = '{$key}';"); |
|
| 241 | + $this->query("update {$this->makeTable('web_user_settings')} SET `setting_value` = '{$value}' WHERE `webuser` = '{$this->id}' AND `setting_name` = '{$key}';"); |
|
| 242 | 242 | } else { |
| 243 | 243 | $this->query("INSERT into {$this->makeTable('web_user_settings')} SET `webuser` = {$this->id},`setting_name` = '{$key}',`setting_value` = '{$value}';"); |
| 244 | 244 | } |
@@ -288,7 +288,7 @@ discard block |
||
| 288 | 288 | $SQL = "INSERT into {$this->makeTable('web_user_attributes')} SET " . implode(', ', |
| 289 | 289 | $this->set['attribute']); |
| 290 | 290 | } else { |
| 291 | - $SQL = "UPDATE {$this->makeTable('web_user_attributes')} SET " . implode(', ', |
|
| 291 | + $SQL = "update {$this->makeTable('web_user_attributes')} SET " . implode(', ', |
|
| 292 | 292 | $this->set['attribute']) . " WHERE internalKey = " . $this->getID(); |
| 293 | 293 | } |
| 294 | 294 | $this->query($SQL); |