本文整理汇总了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')));
}