本文整理汇总了PHP中TBGSettings::getDefaultUserID方法的典型用法代码示例。如果您正苦于以下问题:PHP TBGSettings::getDefaultUserID方法的具体用法?PHP TBGSettings::getDefaultUserID怎么用?PHP TBGSettings::getDefaultUserID使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TBGSettings
的用法示例。
在下文中一共展示了TBGSettings::getDefaultUserID方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: isGuest
/**
* Checks whether or not the current user is a "regular" or "guest" user
*
* @return boolean
*/
public function isGuest()
{
return (bool) (!$this->isLoggedIn() || $this->getID() == TBGSettings::getDefaultUserID() && TBGSettings::isDefaultUserGuest());
}
示例2: runDeleteUser
public function runDeleteUser(TBGRequest $request)
{
try {
try {
$return_options = array();
$user = TBGContext::factory()->TBGUser($request['user_id']);
if ($user->getGroup() instanceof TBGGroup) {
$return_options['update_groups'] = array('ids' => array(), 'membercounts' => array());
$group_id = $user->getGroup()->getID();
$return_options['update_groups']['ids'][] = $group_id;
$return_options['update_groups']['membercounts'][$group_id] = $user->getGroup()->getNumberOfMembers();
}
if (count($user->getTeams())) {
$return_options['update_teams'] = array('ids' => array(), 'membercounts' => array());
foreach ($user->getTeams() as $team) {
$team_id = $team->getID();
$return_options['update_teams']['ids'][] = $team_id;
$return_options['update_teams']['membercounts'][$team_id] = $team->getNumberOfMembers();
}
}
if (in_array($user->getID(), array(1, TBGSettings::getDefaultUserID()))) {
throw new Exception(TBGContext::getI18n()->__("You cannot delete this system user"));
}
} catch (Exception $e) {
}
if (!$user instanceof TBGUser) {
throw new Exception(TBGContext::getI18n()->__("You cannot delete this user"));
}
if (TBGContext::getScope()->isDefault()) {
$user->markAsDeleted();
$user->save();
$return_options['message'] = TBGContext::getI18n()->__('The user was deleted');
} else {
$user->removeScope(TBGContext::getScope()->getID());
$return_options['message'] = TBGContext::getI18n()->__('The user has been removed from this scope');
}
$return_options['total_count'] = TBGUser::getUsersCount();
$return_options['more_available'] = TBGContext::getScope()->hasUsersAvailable();
return $this->renderJSON($return_options);
} catch (Exception $e) {
$this->getResponse()->setHttpStatus(400);
return $this->renderJSON(array('error' => $e->getMessage()));
}
}
示例3: runPruneUsers
/**
* Prune users from users table who aren't in LDAP
*
* @param TBGRequest $request
*/
public function runPruneUsers(TBGRequest $request)
{
$validgroups = TBGContext::getModule('auth_ldap')->getSetting('groups');
$base_dn = TBGContext::getModule('auth_ldap')->getSetting('b_dn');
$dn_attr = TBGContext::getModule('auth_ldap')->getSetting('dn_attr');
$username_attr = TBGContext::getModule('auth_ldap')->getSetting('u_attr');
$fullname_attr = TBGContext::getModule('auth_ldap')->getSetting('f_attr');
$email_attr = TBGContext::getModule('auth_ldap')->getSetting('e_attr');
$groups_members_attr = TBGContext::getModule('auth_ldap')->getSetting('g_attr');
$user_class = TBGContext::getModule('auth_ldap')->getSetting('u_type');
$group_class = TBGContext::getModule('auth_ldap')->getSetting('g_type');
$users = TBGUser::getAll();
$deletecount = 0;
try {
$connection = TBGContext::getModule('auth_ldap')->connect();
TBGContext::getModule('auth_ldap')->bind($connection, TBGContext::getModule('auth_ldap')->getSetting('control_user'), TBGContext::getModule('auth_ldap')->getSetting('control_pass'));
$default = TBGSettings::getDefaultUserID();
foreach ($users as $user) {
if ($user->getID() == $default) {
continue;
}
$username = $user->getUsername();
$fields = array($fullname_attr, $email_attr, 'cn', $dn_attr);
$filter = '(&(objectClass=' . TBGLDAPAuthentication::getModule()->escape($user_class) . ')(' . $username_attr . '=' . TBGLDAPAuthentication::getModule()->escape($username) . '))';
$results = ldap_search($connection, $base_dn, $filter, $fields);
if (!$results) {
TBGLogging::log('failed to search for user: ' . ldap_error($connection), 'ldap', TBGLogging::LEVEL_FATAL);
throw new Exception(TBGContext::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=' . TBGLDAPAuthentication::getModule()->escape($group_class) . ')(cn=' . TBGLDAPAuthentication::getModule()->escape($group) . '))';
$results2 = ldap_search($connection, $base_dn, $filter2, $fields2);
if (!$results2) {
TBGLogging::log('failed to search for user: ' . ldap_error($connection), 'ldap', TBGLogging::LEVEL_FATAL);
throw new Exception(TBGContext::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);
TBGContext::setMessage('module_error', TBGContext::getI18n()->__('Pruning failed'));
TBGContext::setMessage('module_error_details', $e->getMessage());
$this->forward(TBGContext::getRouting()->generate('configure_module', array('config_module' => 'auth_ldap')));
}
ldap_unbind($connection);
TBGContext::setMessage('module_message', TBGContext::getI18n()->__('Pruning successful! %del users deleted', array('%del' => $deletecount)));
$this->forward(TBGContext::getRouting()->generate('configure_module', array('config_module' => 'auth_ldap')));
}
示例4: initializeUser
protected static function initializeUser()
{
TBGLogging::log('Loading user');
try {
TBGLogging::log('is this logout?');
if (self::getRequest()->getParameter('logout')) {
TBGLogging::log('yes');
self::logout();
} else {
TBGLogging::log('no');
TBGLogging::log('sets up user object');
$event = TBGEvent::createNew('core', 'pre_login');
$event->trigger();
if ($event->isProcessed()) {
self::loadUser($event->getReturnValue());
} else {
self::loadUser();
}
TBGEvent::createNew('core', 'post_login', self::getUser())->trigger();
TBGLogging::log('loaded');
self::cacheAllPermissions();
}
} catch (Exception $e) {
TBGLogging::log("Something happened while setting up user: " . $e->getMessage(), 'main', TBGLogging::LEVEL_WARNING);
if (!self::isCLI() && (self::getRouting()->getCurrentRouteModule() != 'main' || self::getRouting()->getCurrentRouteAction() != 'register1' && self::getRouting()->getCurrentRouteAction() != 'register2' && self::getRouting()->getCurrentRouteAction() != 'activate' && self::getRouting()->getCurrentRouteAction() != 'reset_password' && self::getRouting()->getCurrentRouteAction() != 'captcha' && self::getRouting()->getCurrentRouteAction() != 'login' && self::getRouting()->getCurrentRouteAction() != 'getBackdropPartial' && self::getRouting()->getCurrentRouteAction() != 'serve')) {
self::$_redirect_login = true;
} else {
self::$_user = self::factory()->TBGUser(TBGSettings::getDefaultUserID());
}
}
TBGLogging::log('...done');
}
示例5: _upgrade
protected function _upgrade()
{
switch ($this->_version) {
case "1.0":
// Upgrade tables
\b2db\Core::getTable('TBGVCSIntegrationCommitsTable')->create();
\b2db\Core::getTable('TBGVCSIntegrationFilesTable')->create();
\b2db\Core::getTable('TBGVCSIntegrationIssueLinksTable')->create();
TBGVCSIntegrationCommitsTable::getTable()->createIndexes();
TBGVCSIntegrationFilesTable::getTable()->createIndexes();
TBGVCSIntegrationIssueLinksTable::getTable()->createIndexes();
// Migrate data from old table to new tables
$crit = new \b2db\Criteria();
$crit->addOrderBy(TBGVCSIntegrationTable::DATE, \b2db\Criteria::SORT_DESC);
$results = TBGVCSIntegrationTable::getTable()->doSelect($crit);
if ($results instanceof \b2db\Resultset && $results->count() > 0) {
$commits = array();
while ($row = $results->getNextRow()) {
$rev = $row->get(TBGVCSIntegrationTable::NEW_REV);
if (array_key_exists($rev, $commits)) {
// Add a new file or issue to the commit data
$commits[$rev]['files'][$row->get(TBGVCSIntegrationTable::FILE_NAME)] = array('file_name' => $row->get(TBGVCSIntegrationTable::FILE_NAME), 'action' => $row->get(TBGVCSIntegrationTable::ACTION));
$commits[$rev]['issues'][$row->get(TBGVCSIntegrationTable::ISSUE_NO)] = $row->get(TBGVCSIntegrationTable::ISSUE_NO);
} else {
// All issues will be of the same project, so use one issue
$issue = TBGContext::factory()->TBGIssue($results->get(TBGVCSIntegrationTable::ISSUE_NO));
// Add details of a new commit
$commits[$rev] = array('commit' => array(), 'files' => array(), 'issues' => array());
$commits[$rev]['commit'] = array('new_rev' => $rev, 'old_rev' => $row->get(TBGVCSIntegrationTable::OLD_REV), 'author' => $row->get(TBGVCSIntegrationTable::AUTHOR), 'date' => $row->get(TBGVCSIntegrationTable::DATE), 'log' => $row->get(TBGVCSIntegrationTable::LOG), 'scope' => $row->get(TBGVCSIntegrationTable::SCOPE), 'project' => $issue->getProject());
$commits[$rev]['files'][$row->get(TBGVCSIntegrationTable::FILE_NAME)] = array('file_name' => $row->get(TBGVCSIntegrationTable::FILE_NAME), 'action' => $row->get(TBGVCSIntegrationTable::ACTION));
$commits[$rev]['issues'][$row->get(TBGVCSIntegrationTable::ISSUE_NO)] = $row->get(TBGVCSIntegrationTable::ISSUE_NO);
}
}
foreach ($commits as $commit) {
$files = array();
$issues = array();
$scope = TBGContext::factory()->TBGScope($commit['commit']['scope']);
try {
$author = TBGContext::factory()->TBGUser($commit['commit']['author']);
} catch (Exception $e) {
$author = TBGContext::factory()->TBGUser(TBGSettings::getDefaultUserID());
}
if (!$author instanceof TBGUser) {
$author = TBGContext::factory()->TBGUser(TBGSettings::getDefaultUserID());
}
// Add the commit
$inst = new TBGVCSIntegrationCommit();
$inst->setAuthor($author);
$inst->setDate($commit['commit']['date']);
$inst->setLog($commit['commit']['log']);
$inst->setPreviousRevision($commit['commit']['old_rev']);
$inst->setRevision($commit['commit']['new_rev']);
$inst->setProject($commit['commit']['project']);
$inst->setScope($scope);
$inst->save();
// Process issue list, remove duplicates
$issues = $commit['issues'];
$files = $commit['files'];
$commit = $inst;
foreach ($files as $file) {
// Add affected files
$inst = new TBGVCSIntegrationFile();
$inst->setCommit($commit);
$inst->setFile($file['file_name']);
$inst->setAction($file['action']);
$inst->setScope($scope);
$inst->save();
}
foreach ($issues as $issue) {
// Add affected issues
$issue = TBGContext::factory()->TBGIssue($issue);
$inst = new TBGVCSIntegrationIssueLink();
$inst->setIssue($issue);
$inst->setCommit($commit);
$inst->setScope($scope);
$inst->save();
}
}
}
// Migrate settings to new format
$access_method = $this->getSetting('use_web_interface');
$passkey = $this->getSetting('vcs_passkey');
foreach (TBGProject::getAll() as $project) {
$projectId = $project->getID();
$web_path = $this->getSetting('web_path_' . $projectId);
$web_repo = $this->getSetting('web_repo_' . $projectId);
// Check if enabled
if ($web_path == '') {
continue;
}
switch ($this->getSetting('web_type_' . $projectId)) {
case 'viewvc':
$base_url = $web_path . '/' . '?root=' . $web_repo;
$link_rev = '&view=rev&revision=%revno';
$link_file = '&view=log';
$link_diff = '&r1=%revno&r2=%oldrev';
$link_view = '&revision=%revno&view=markup';
break;
case 'viewvc_repo':
$base_url = $web_path;
//.........这里部分代码省略.........
示例6: initializeUser
protected static function initializeUser()
{
TBGLogging::log('Loading user');
try {
TBGLogging::log('is this logout?');
if (self::getRequest()->getParameter('logout')) {
TBGLogging::log('yes');
self::logout();
} else {
TBGLogging::log('no');
TBGLogging::log('sets up user object');
$event = TBGEvent::createNew('core', 'pre_login');
$event->trigger();
if ($event->isProcessed()) {
self::loadUser($event->getReturnValue());
} elseif (!self::isCLI()) {
self::loadUser();
} else {
self::$_user = new TBGUser();
}
TBGEvent::createNew('core', 'post_login', self::getUser())->trigger();
TBGLogging::log('loaded');
TBGLogging::log('caching permissions');
self::cacheAllPermissions();
TBGLogging::log('done (caching permissions)');
}
} catch (TBGElevatedLoginException $e) {
TBGLogging::log("Could not reauthenticate elevated permissions: " . $e->getMessage(), 'main', TBGLogging::LEVEL_INFO);
TBGContext::setMessage('elevated_login_message_err', $e->getMessage());
self::$_redirect_login = 'elevated_login';
} catch (Exception $e) {
TBGLogging::log("Something happened while setting up user: " . $e->getMessage(), 'main', TBGLogging::LEVEL_WARNING);
$allow_anonymous_routes = array('register', 'register_check_username', 'register1', 'register2', 'activate', 'reset_password', 'captcha', 'login', 'login_page', 'getBackdropPartial', 'serve', 'doLogin');
if (!self::isCLI() && (!in_array(self::getRouting()->getCurrentRouteModule(), array('main', 'remote')) || !in_array(self::getRouting()->getCurrentRouteName(), $allow_anonymous_routes))) {
TBGContext::setMessage('login_message_err', $e->getMessage());
self::$_redirect_login = 'login';
} else {
self::$_user = self::factory()->TBGUser(TBGSettings::getDefaultUserID());
}
}
TBGLogging::log('...done');
}
示例7: hasUserVoted
/**
* Whether or not the current user has voted
*
* @return boolean
*/
public function hasUserVoted($user_id, $up)
{
$user_id = is_object($user_id) ? $user_id->getID() : $user_id;
$this->_setupVotes();
if ($user_id == TBGSettings::getDefaultUserID() && TBGSettings::isDefaultUserGuest() || !$this->getProject()->canVoteOnIssues()) {
return true;
}
if (array_key_exists($user_id, $this->_votes)) {
return $up ? (int) $this->_votes[$user_id] > 0 : (int) $this->_votes[$user_id] < 0;
} else {
return false;
}
}