當前位置: 首頁>>代碼示例>>PHP>>正文


PHP User::getAll方法代碼示例

本文整理匯總了PHP中thebuggenie\core\entities\User::getAll方法的典型用法代碼示例。如果您正苦於以下問題:PHP User::getAll方法的具體用法?PHP User::getAll怎麽用?PHP User::getAll使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在thebuggenie\core\entities\User的用法示例。


在下文中一共展示了User::getAll方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: runPruneUsers

 /**
  * Prune users from users table who aren't in LDAP
  *
  * @param \thebuggenie\core\framework\Request $request
  */
 public function runPruneUsers(framework\Request $request)
 {
     $validgroups = framework\Context::getModule('auth_ldap')->getSetting('groups');
     $base_dn = framework\Context::getModule('auth_ldap')->getSetting('b_dn');
     $dn_attr = framework\Context::getModule('auth_ldap')->getSetting('dn_attr');
     $username_attr = framework\Context::getModule('auth_ldap')->getSetting('u_attr');
     $fullname_attr = framework\Context::getModule('auth_ldap')->getSetting('f_attr');
     $email_attr = framework\Context::getModule('auth_ldap')->getSetting('e_attr');
     $groups_members_attr = framework\Context::getModule('auth_ldap')->getSetting('g_attr');
     $user_class = framework\Context::getModule('auth_ldap')->getSetting('u_type');
     $group_class = framework\Context::getModule('auth_ldap')->getSetting('g_type');
     $users = \thebuggenie\core\entities\User::getAll();
     $deletecount = 0;
     try {
         $connection = framework\Context::getModule('auth_ldap')->connect();
         framework\Context::getModule('auth_ldap')->bind($connection, framework\Context::getModule('auth_ldap')->getSetting('control_user'), framework\Context::getModule('auth_ldap')->getSetting('control_pass'));
         $default = framework\Settings::getDefaultUserID();
         foreach ($users as $user) {
             if ($user->getID() == $default) {
                 continue;
             }
             $username = $user->getUsername();
             $fields = array($fullname_attr, $email_attr, 'cn', $dn_attr);
             $filter = '(&(objectClass=' . framework\Context::getModule('auth_ldap')->escape($user_class) . ')(' . $username_attr . '=' . framework\Context::getModule('auth_ldap')->escape($username) . '))';
             $results = ldap_search($connection, $base_dn, $filter, $fields);
             if (!$results) {
                 framework\Logging::log('failed to search for user: ' . ldap_error($connection), 'ldap', framework\Logging::LEVEL_FATAL);
                 throw new \Exception(framework\Context::geti18n()->__('Search failed: ') . ldap_error($connection));
             }
             $data = ldap_get_entries($connection, $results);
             /*
              * If a user is not found, delete it
              */
             if ($data['count'] != 1) {
                 $user->delete();
                 $deletecount++;
                 continue;
             }
             if ($validgroups != '') {
                 if (strstr($validgroups, ',')) {
                     $groups = explode(',', $validgroups);
                 } else {
                     $groups = array();
                     $groups[] = $validgroups;
                 }
                 $allowed = false;
                 foreach ($groups as $group) {
                     $fields2 = array($groups_members_attr);
                     $filter2 = '(&(objectClass=' . framework\Context::getModule('auth_ldap')->escape($group_class) . ')(cn=' . framework\Context::getModule('auth_ldap')->escape($group) . '))';
                     $results2 = ldap_search($connection, $base_dn, $filter2, $fields2);
                     if (!$results2) {
                         framework\Logging::log('failed to search for user: ' . ldap_error($connection), 'ldap', framework\Logging::LEVEL_FATAL);
                         throw new \Exception(framework\Context::geti18n()->__('Search failed: ') . ldap_error($connection));
                     }
                     $data2 = ldap_get_entries($connection, $results2);
                     if ($data2['count'] != 1) {
                         continue;
                     }
                     foreach ($data2[0][$groups_members_attr] as $member) {
                         $member = preg_replace('/(?<=,) +(?=[a-zA-Z])/', '', $member);
                         $user_dn = preg_replace('/(?<=,) +(?=[a-zA-Z])/', '', $data[0][strtolower($dn_attr)][0]);
                         if (!is_numeric($member) && strtolower($member) == strtolower($user_dn)) {
                             $allowed = true;
                         }
                     }
                 }
                 /*
                  * If a user is not allowed access, delete it
                  */
                 if ($allowed == false) {
                     $user->delete();
                     $deletecount++;
                     continue;
                 }
             }
         }
     } catch (\Exception $e) {
         ldap_unbind($connection);
         framework\Context::setMessage('module_error', framework\Context::getI18n()->__('Pruning failed'));
         framework\Context::setMessage('module_error_details', $e->getMessage());
         $this->forward(framework\Context::getRouting()->generate('configure_module', array('config_module' => 'auth_ldap')));
     }
     ldap_unbind($connection);
     framework\Context::setMessage('module_message', framework\Context::getI18n()->__('Pruning successful! %del users deleted', array('%del' => $deletecount)));
     $this->forward(framework\Context::getRouting()->generate('configure_module', array('config_module' => 'auth_ldap')));
 }
開發者ID:RTechSoft,項目名稱:thebuggenie,代碼行數:91,代碼來源:Actions.php


注:本文中的thebuggenie\core\entities\User::getAll方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。