コード例 #1
0
ファイル: UserBase.php プロジェクト: hotarucms/hotarucms
 /**
  * Change username or email
  *
  * @param int $userid
  * @return bool
  */
 public function updateAccount($h, $userid = 0)
 {
     // $viewee is the person whose account is being modified
     $viewee = new UserBase($h);
     // Get the details of the account to show.
     // If no account is specified, assume it's your own.
     if (!$userid) {
         $userid = $this->id;
     }
     $viewee->getUser($h, $userid);
     $error = 0;
     // fill checks
     $checks['userid_check'] = '';
     $checks['username_check'] = '';
     $checks['email_check'] = '';
     $checks['role_check'] = '';
     $checks['password_check_old'] = '';
     $checks['password_check_new'] = '';
     $checks['password_check_new2'] = '';
     // Updating account info (username and email address)
     if ($h->cage->post->testAlnumLines('update_type') == 'update_general') {
         // check CSRF key
         if (!$h->csrf()) {
             $h->messages[$h->lang('error_csrf')] = 'red';
             $error = 1;
         }
         $username_check = $h->cage->post->testUsername('username');
         // alphanumeric, dashes and underscores okay, case insensitive
         if (!$username_check) {
             $h->messages[$h->lang('main_user_account_update_username_error')] = 'red';
             $error = 1;
         } elseif ($h->nameExists($username_check, '', $viewee->id) || $h->isBlocked('user', $username_check)) {
             $h->messages[$h->lang('main_user_account_update_username_exists')] = 'red';
             $error = 1;
         } else {
             //success
             $viewee->name = $username_check;
         }
         $email_check = $h->cage->post->testEmail('email');
         if (!$email_check) {
             $h->messages[$h->lang('main_user_account_update_email_error')] = 'red';
             $error = 1;
         } elseif ($h->emailExists($email_check, '', $viewee->id) || $h->isBlocked('email', $email_check)) {
             $h->messages[$h->lang('main_user_account_update_email_exists')] = 'red';
             $error = 1;
         } else {
             //success
             $viewee->email = $email_check;
         }
         $role_check = $h->cage->post->testUsername('user_role');
         // from Users plugin account page
         // compare with current role and update if different
         if (!$error && $role_check && $role_check != $viewee->role) {
             $viewee->role = $role_check;
             $new_perms = $viewee->getDefaultPermissions($h, $role_check);
             $viewee->setAllPermissions($new_perms);
             $viewee->updatePermissions($h);
             if ($role_check == 'killspammed' || $role_check == 'deleted') {
                 $h->deleteComments($viewee->id);
                 // includes child comments from *other* users
                 $h->deletePosts($viewee->id);
                 // includes tags and votes for self-submitted posts
                 $h->pluginHook('userbase_killspam', '', array('target_user' => $viewee->id));
                 if ($role_check == 'deleted') {
                     $h->deleteUser($viewee->id);
                     $checks['username_check'] = 'deleted';
                     $h->message = $h->lang("users_account_deleted");
                     $h->messageType = 'red';
                     return $checks;
                     // This will then show a red "deleted" notice
                 }
             }
         }
         // If we've just edited our own account, let's refresh the cookie so it uses our latest username:
         if ($h->currentUser->id == $h->cage->post->testInt('userid')) {
             $h->setCookie($h, false);
             // delete the cookie
             $h->getUser($h, $h->currentUser->id, '', true);
             // re-read the database record to get updated info
             $h->setCookie($h, true);
             // create a new, updated cookie
         }
     }
     if (!isset($username_check) && !isset($email_check)) {
         $username_check = $viewee->name;
         $email_check = $viewee->email;
         $role_check = $viewee->role;
         // do nothing
     } elseif ($error == 0) {
         $exists = $h->userExists(0, $username_check, $email_check);
         if ($exists != 'no' && $exists != 'error') {
             // user exists
             //success
             $viewee->updateUserBasic($h, $userid);
             // only update the cookie if it's your own account:
             if ($userid == $this->id) {
                 $h->setCookie($h, false);
                 // delete the cookie
                 $h->getUser($h, $h->currentUser->id, '', true);
                 // re-read the database record to get updated info
                 $h->setCookie($h, true);
                 // create a new, updated cookie
             }
             $h->messages[$h->lang('main_user_account_update_success')] = 'green';
         } else {
             //fail
             $h->messages[$h->lang("main_user_account_update_unexpected_error")] = 'red';
         }
     } else {
         // error must = 1 so fall through and display the form again
     }
     //update checks
     $this->updatePassword($h, $userid);
     $userid_check = $viewee->id;
     $checks['userid_check'] = $userid_check;
     $checks['username_check'] = $username_check;
     $checks['email_check'] = $email_check;
     $checks['role_check'] = $role_check;
     return $checks;
 }
コード例 #2
0
ファイル: UserInfo.php プロジェクト: hotarucms/hotarucms
 /**
  * Get all users with permission to access admin
  */
 public function getMods($h, $permission = 'can_access_admin', $value = 'yes')
 {
     $sql = "SELECT user_id FROM " . TABLE_USERS . " WHERE (user_role = %s) || (user_role = %s) || (user_role = %s)";
     $users = $h->db->get_results($h->db->prepare($sql, 'admin', 'supermod', 'moderator'));
     if (!$users) {
         return false;
     }
     $mods = array();
     foreach ($users as $user) {
         $details = new UserBase();
         $details->getUser($h, $user->user_id);
         if ($details->getPermission($permission) == $value) {
             $mods[$details->id]['id'] = $details->id;
             $mods[$details->id]['role'] = $details->role;
             $mods[$details->id]['name'] = $details->name;
             $mods[$details->id]['email'] = $details->email;
         }
     }
     return $mods;
 }