public function componentPagination() { $this->currentpage = ceil($this->offset / $this->ipp) + 1; $this->pagecount = ceil($this->resultcount / $this->ipp); $parameters = array(); foreach ($this->filters as $key => $filter) { if (is_array($filter)) { foreach ($filter as $subkey => $subfilter) { if (is_array($subfilter)) { foreach ($subfilter as $subsubkey => $subsubfilter) { $parameters[] = "filters[{$key}][{$subkey}][{$subsubkey}]=" . urlencode($subsubfilter); } } else { $parameters[] = "filters[{$key}][{$subkey}]=" . urlencode($subfilter); } } } else { $parameters[] = "filters[{$key}]=" . urlencode($filter); } } $parameters[] = 'template=' . $this->templatename; $parameters[] = 'template_parameter=' . $this->template_parameter; $parameters[] = 'searchterm=' . $this->searchterm; $parameters[] = 'groupby=' . $this->groupby; $parameters[] = 'grouporder=' . $this->grouporder; $parameters[] = 'issues_per_page=' . $this->ipp; $route = TBGContext::isProjectContext() ? TBGContext::getRouting()->generate('project_search_paginated', array('project_key' => TBGContext::getCurrentProject()->getKey())) : TBGContext::getRouting()->generate('search_paginated'); $this->route = $route; $this->parameters = join('&', $parameters); }
public function componentLeftmenu() { $i18n = TBGContext::getI18n(); $config_sections = array(); if (TBGContext::getUser()->getScope()->getID() == 1) { $config_sections[TBGSettings::CONFIGURATION_SECTION_SCOPES] = array('route' => 'configure_scopes', 'description' => $i18n->__('Scopes'), 'icon' => 'scopes', 'module' => 'core'); } $config_sections[TBGSettings::CONFIGURATION_SECTION_SETTINGS] = array('route' => 'configure_settings', 'description' => $i18n->__('Settings'), 'icon' => 'general', 'module' => 'core'); $config_sections[TBGSettings::CONFIGURATION_SECTION_PERMISSIONS] = array('route' => 'configure_permissions', 'description' => $i18n->__('Permissions'), 'icon' => 'permissions', 'module' => 'core'); $config_sections[TBGSettings::CONFIGURATION_SECTION_AUTHENTICATION] = array('route' => 'configure_authentication', 'description' => $i18n->__('Authentication'), 'icon' => 'authentication', 'module' => 'core'); if (TBGContext::getScope()->isUploadsEnabled()) { $config_sections[TBGSettings::CONFIGURATION_SECTION_UPLOADS] = array('route' => 'configure_files', 'description' => $i18n->__('Uploads & attachments'), 'icon' => 'files', 'module' => 'core'); } $config_sections[TBGSettings::CONFIGURATION_SECTION_IMPORT] = array('route' => 'configure_import', 'description' => $i18n->__('Import data'), 'icon' => 'import', 'module' => 'core'); $config_sections[TBGSettings::CONFIGURATION_SECTION_PROJECTS] = array('route' => 'configure_projects', 'description' => $i18n->__('Projects'), 'icon' => 'projects', 'module' => 'core'); $config_sections[TBGSettings::CONFIGURATION_SECTION_ISSUETYPES] = array('icon' => 'issuetypes', 'description' => $i18n->__('Issue types'), 'route' => 'configure_issuetypes', 'module' => 'core'); $config_sections[TBGSettings::CONFIGURATION_SECTION_ISSUEFIELDS] = array('icon' => 'resolutiontypes', 'description' => $i18n->__('Issue fields'), 'route' => 'configure_issuefields', 'module' => 'core'); $config_sections[TBGSettings::CONFIGURATION_SECTION_WORKFLOW] = array('icon' => 'workflow', 'description' => $i18n->__('Workflow'), 'route' => 'configure_workflow', 'module' => 'core'); $config_sections[TBGSettings::CONFIGURATION_SECTION_USERS] = array('route' => 'configure_users', 'description' => $i18n->__('Users, teams, clients & groups'), 'icon' => 'users', 'module' => 'core'); $config_sections[TBGSettings::CONFIGURATION_SECTION_MODULES][] = array('route' => 'configure_modules', 'description' => $i18n->__('Modules'), 'icon' => 'modules', 'module' => 'core'); foreach (TBGContext::getModules() as $module) { if ($module->hasConfigSettings() && $module->isEnabled()) { $config_sections[TBGSettings::CONFIGURATION_SECTION_MODULES][] = array('route' => array('configure_module', array('config_module' => $module->getName())), 'description' => $module->getConfigTitle(), 'icon' => $module->getName(), 'module' => $module->getName()); } } $breadcrumblinks = array(); foreach ($config_sections as $section) { if (is_array($section) && !array_key_exists('route', $section)) { foreach ($section as $subsection) { $url = is_array($subsection['route']) ? make_url($subsection['route'][0], $subsection['route'][1]) : make_url($subsection['route']); $breadcrumblinks[] = array('url' => $url, 'title' => $subsection['description']); } } else { $breadcrumblinks[] = array('url' => make_url($section['route']), 'title' => $section['description']); } } $this->breadcrumblinks = $breadcrumblinks; $this->config_sections = $config_sections; if ($this->selected_section == TBGSettings::CONFIGURATION_SECTION_MODULES) { if (TBGContext::getRouting()->getCurrentRouteName() == 'configure_modules') { $this->selected_subsection = 'core'; } else { $this->selected_subsection = TBGContext::getRequest()->getParameter('config_module'); } } }
/** * Send a test email * * @param TBGRequest $request */ public function runTestEmail(TBGRequest $request) { if ($email_to = $request->getParameter('test_email_to')) { try { if (TBGMailing::getModule()->sendTestEmail($email_to)) { TBGContext::setMessage('module_message', TBGContext::getI18n()->__('The email was successfully accepted for delivery')); } else { TBGContext::setMessage('module_error', TBGContext::getI18n()->__('The email was not sent')); TBGContext::setMessage('module_error_details', TBGLogging::getMessagesForCategory('mailing', TBGLogging::LEVEL_NOTICE)); } } catch (Exception $e) { TBGContext::setMessage('module_error', TBGContext::getI18n()->__('The email was not sent')); TBGContext::setMessage('module_error_details', $e->getMessage()); } } else { TBGContext::setMessage('module_error', TBGContext::getI18n()->__('Please specify an email address')); } $this->forward(TBGContext::getRouting()->generate('configure_module', array('config_module' => 'mailing'))); }
public function componentLeftmenu() { $config_sections = TBGSettings::getConfigSections(TBGContext::getI18n()); $breadcrumblinks = array(); foreach ($config_sections as $key => $sections) { foreach ($sections as $section) { if ($key == TBGSettings::CONFIGURATION_SECTION_MODULES) { $url = is_array($section['route']) ? make_url($section['route'][0], $section['route'][1]) : make_url($section['route']); $breadcrumblinks[] = array('url' => $url, 'title' => $section['description']); } else { $breadcrumblinks[] = array('url' => make_url($section['route']), 'title' => $section['description']); } } } $this->breadcrumblinks = $breadcrumblinks; $this->config_sections = $config_sections; if ($this->selected_section == TBGSettings::CONFIGURATION_SECTION_MODULES) { if (TBGContext::getRouting()->getCurrentRouteName() == 'configure_modules') { $this->selected_subsection = 'core'; } else { $this->selected_subsection = TBGContext::getRequest()->getParameter('config_module'); } } }
public function listen_MenustripLinks(TBGEvent $event) { $project_url = TBGContext::isProjectContext() ? TBGContext::getRouting()->generate('publish_article', array('article_name' => ucfirst(TBGContext::getCurrentProject()->getKey()) . ':MainPage')) : null; $url = TBGContext::getRouting()->generate('publish'); TBGActionComponent::includeTemplate('publish/menustriplinks', array('url' => $url, 'project_url' => $project_url, 'selected_tab' => $event->getParameter('selected_tab'))); }
public function runSiteIcons(TBGRequest $request) { if ($this->getAccessLevel($request['section'], 'core') == TBGSettings::ACCESS_FULL) { if ($request->isPost()) { switch ($request['small_icon_action']) { case 'upload_file': $file = $request->handleUpload('small_icon'); TBGSettings::saveSetting(TBGSettings::SETTING_FAVICON_TYPE, TBGSettings::APPEARANCE_FAVICON_CUSTOM); TBGSettings::saveSetting(TBGSettings::SETTING_FAVICON_ID, $file->getID()); break; case 'clear_file': TBGSettings::saveSetting(TBGSettings::SETTING_FAVICON_TYPE, TBGSettings::APPEARANCE_FAVICON_THEME); break; } switch ($request['large_icon_action']) { case 'upload_file': $file = $request->handleUpload('large_icon'); TBGSettings::saveSetting(TBGSettings::SETTING_HEADER_ICON_TYPE, TBGSettings::APPEARANCE_HEADER_CUSTOM); TBGSettings::saveSetting(TBGSettings::SETTING_HEADER_ICON_ID, $file->getID()); break; case 'clear_file': TBGSettings::saveSetting(TBGSettings::SETTING_HEADER_ICON_TYPE, TBGSettings::APPEARANCE_HEADER_THEME); break; } } $route = TBGContext::getRouting()->generate('configure_settings'); if ($request->isAjaxCall()) { return $this->renderJSON(array('forward' => $route)); } else { $this->forward($route); } } return $this->forward403($this->getI18n()->__("You don't have access to perform this action")); }
?> ><?php echo image_tag($tbg_user->getAvatarURL(true), array('alt' => '[avatar]', 'class' => 'guest_avatar'), true) . __('You are not logged in'); ?> </a> <?php } else { ?> <?php echo link_tag(make_url('dashboard'), image_tag($tbg_user->getAvatarURL(true), array('alt' => '[avatar]', 'id' => 'header_avatar'), true) . '<span id="header_user_fullname">' . tbg_decodeUTF8($tbg_user->getDisplayName()) . '</span>'); ?> <?php } ?> <?php if (TBGContext::getRouting()->getCurrentRouteName() != 'login_page') { ?> <?php echo javascript_link_tag(image_tag('tabmenu_dropdown.png', array('class' => 'menu_dropdown')), array('onmouseover' => "")); ?> <?php } ?> </div> <?php if (TBGEvent::createNew('core', 'header_usermenu_decider')->trigger()->getReturnValue() !== false) { ?> <?php require THEBUGGENIE_CORE_PATH . 'templates/headerusermenu.inc.php'; ?> <?php
public function runBulkUpdateIssues(TBGRequest $request) { $issue_ids = $request['issue_ids']; $options = array('issue_ids' => array_values($issue_ids)); TBGContext::loadLibrary('common'); $options['last_updated'] = tbg_formatTime(time(), 20); if (!empty($issue_ids)) { $options['bulk_action'] = $request['bulk_action']; switch ($request['bulk_action']) { case 'assign_milestone': $milestone = null; if ($request['milestone'] == 'new') { $milestone = new TBGMilestone(); $milestone->setProject(TBGContext::getCurrentProject()); $milestone->setName($request['milestone_name']); $milestone->save(); $options['milestone_url'] = TBGContext::getRouting()->generate('project_planning_milestone', array('project_key' => $milestone->getProject()->getKey(), 'milestone_id' => $milestone->getID())); } elseif ($request['milestone']) { $milestone = new TBGMilestone($request['milestone']); } $milestone_id = $milestone instanceof TBGMilestone ? $milestone->getID() : null; foreach (array_keys($issue_ids) as $issue_id) { if (is_numeric($issue_id)) { $issue = new TBGIssue($issue_id); $issue->setMilestone($milestone_id); $issue->save(); } } $options['milestone_id'] = $milestone_id; $options['milestone_name'] = $milestone_id ? $milestone->getName() : '-'; break; case 'set_status': if (is_numeric($request['status'])) { $status = new TBGStatus($request['status']); foreach (array_keys($issue_ids) as $issue_id) { if (is_numeric($issue_id)) { $issue = new TBGIssue($issue_id); $issue->setStatus($status->getID()); $issue->save(); } } $options['status'] = array('color' => $status->getColor(), 'name' => $status->getName(), 'id' => $status->getID()); } break; case 'set_severity': if (is_numeric($request['severity'])) { $severity = $request['severity'] ? new TBGSeverity($request['severity']) : null; foreach (array_keys($issue_ids) as $issue_id) { if (is_numeric($issue_id)) { $issue = new TBGIssue($issue_id); $severity_id = $severity instanceof TBGSeverity ? $severity->getID() : 0; $issue->setSeverity($severity_id); $issue->save(); } } $options['severity'] = array('name' => $severity instanceof TBGSeverity ? $severity->getName() : '-', 'id' => $severity instanceof TBGSeverity ? $severity->getID() : 0); } break; case 'set_resolution': if (is_numeric($request['resolution'])) { $resolution = $request['resolution'] ? new TBGResolution($request['resolution']) : null; foreach (array_keys($issue_ids) as $issue_id) { if (is_numeric($issue_id)) { $issue = new TBGIssue($issue_id); $resolution_id = $resolution instanceof TBGResolution ? $resolution->getID() : 0; $issue->setResolution($resolution_id); $issue->save(); } } $options['resolution'] = array('name' => $resolution instanceof TBGResolution ? $resolution->getName() : '-', 'id' => $resolution instanceof TBGResolution ? $resolution->getID() : 0); } break; case 'set_priority': if (is_numeric($request['priority'])) { $priority = $request['priority'] ? new TBGPriority($request['priority']) : null; foreach (array_keys($issue_ids) as $issue_id) { if (is_numeric($issue_id)) { $issue = new TBGIssue($issue_id); $priority_id = $priority instanceof TBGPriority ? $priority->getID() : 0; $issue->setPriority($priority_id); $issue->save(); } } $options['priority'] = array('name' => $priority instanceof TBGPriority ? $priority->getName() : '-', 'id' => $priority instanceof TBGPriority ? $priority->getID() : 0); } break; case 'set_category': if (is_numeric($request['category'])) { $category = $request['category'] ? new TBGCategory($request['category']) : null; foreach (array_keys($issue_ids) as $issue_id) { if (is_numeric($issue_id)) { $issue = new TBGIssue($issue_id); $category_id = $category instanceof TBGCategory ? $category->getID() : 0; $issue->setCategory($category_id); $issue->save(); } } $options['category'] = array('name' => $category instanceof TBGCategory ? $category->getName() : '-', 'id' => $category instanceof TBGCategory ? $category->getID() : 0); } break; } } return $this->renderJSON($options); }
protected function getRemoteURL($route_name, $params = array()) { $real_params = array_merge(array('api_username' => $this->_getCurrentRemoteUser(), 'api_token' => $this->_getCurrentRemotePasswordHash()), $params); $url = TBGContext::getRouting()->generate($route_name, $real_params, true); $host = $this->_getCurrentRemoteServer(); if (mb_substr($host, mb_strlen($host) - 2) != '/') { $host .= '/'; } return $host . mb_substr($url, 1); }
} ?> <!--[if lt IE 9]> <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> <?php TBGEvent::createNew('core', 'header_ends')->trigger(); ?> </head> <body id="body"> <?php require THEBUGGENIE_CORE_PATH . 'templates/backdrops.inc.php'; ?> <div id="main_container"> <?php if (!in_array(TBGContext::getRouting()->getCurrentRouteName(), array('login_page', 'elevated_login_page', 'reset_password'))) { ?> <?php TBGLogging::log('Rendering header'); ?> <?php require THEBUGGENIE_CORE_PATH . 'templates/headertop.inc.php'; ?> <?php TBGLogging::log('done (rendering header)'); ?> <?php } ?> <div id="content_container"> <?php
public function getRSSUrl() { switch ($this->getType()) { case self::VIEW_PREDEFINED_SEARCH: case self::VIEW_SAVED_SEARCH: return TBGContext::getRouting()->generate('search', $this->getSearchParameters(true)); break; case self::VIEW_PROJECT_RECENT_ACTIVITIES: return TBGContext::getRouting()->generate('project_timeline', array('project_key' => $this->getProject()->getKey(), 'format' => 'rss')); break; } }
public function runUpgrade(TBGRequest $request) { $version_info = explode(',', file_get_contents(THEBUGGENIE_PATH . 'installed')); $this->current_version = $version_info[0]; $this->upgrade_available = $this->current_version != '3.1'; if ($this->upgrade_available) { $scope = new TBGScope(); $scope->setID(1); $scope->setEnabled(); TBGContext::setScope($scope); } $this->upgrade_complete = false; if ($this->upgrade_available && $request->isMethod(TBGRequest::POST)) { $this->upgrade_complete = false; switch ($this->current_version) { case '3.0': $this->_upgradeFrom3dot0(); break; } if ($this->upgrade_complete) { $existing_installed_content = file_get_contents(THEBUGGENIE_PATH . 'installed'); file_put_contents(THEBUGGENIE_PATH . 'installed', TBGSettings::getVersion(false, false) . ', upgraded ' . date('d.m.Y H:i') . "\n" . $existing_installed_content); unlink(THEBUGGENIE_PATH . 'upgrade'); $this->current_version = '3.1'; $this->upgrade_available = false; } } elseif ($this->current_version != '3.1') { $this->permissions_ok = false; if (is_writable(THEBUGGENIE_PATH . 'installed') && is_writable(THEBUGGENIE_PATH . 'upgrade')) { $this->permissions_ok = true; } } else { $this->forward(TBGContext::getRouting()->generate('home')); } }
protected final function _loadRoutes() { foreach ($this->_routes as $route) { $this->log('adding route ' . $route[0]); call_user_func_array(array(TBGContext::getRouting(), 'addRoute'), $route); $this->log('done (adding route ' . $route[0] . ')'); } }
public function runAddScope(TBGRequest $request) { if ($request->isPost()) { $scope = TBGContext::getScope(); $this->getUser()->addScope($scope, false); $this->getUser()->confirmScope($scope->getID()); $route = TBGSettings::getLoginReturnRoute() != 'referer' ? TBGSettings::getLoginReturnRoute() : 'home'; $this->forward(TBGContext::getRouting()->generate($route)); } }
/** * Generate a url based on a route * * @param string $name The route key * @param array $params key => value pairs of route parameters * @param bool $relative[optional] Whether to generate a full url or relative * * @return string */ function make_url($name, $params = array(), $relative = true) { return TBGContext::getRouting()->generate($name, $params, $relative); }
public function componentLogin() { $this->selected_tab = isset($this->section) ? $this->section : 'login'; $this->options = $this->getParameterHolder(); if (TBGContext::hasMessage('login_referer')) { $this->referer = htmlentities(TBGContext::getMessage('login_referer'), ENT_COMPAT, TBGContext::getI18n()->getCharset()); } elseif (array_key_exists('HTTP_REFERER', $_SERVER)) { $this->referer = htmlentities($_SERVER['HTTP_REFERER'], ENT_COMPAT, TBGContext::getI18n()->getCharset()); } else { $this->referer = TBGContext::getRouting()->generate('dashboard'); } try { $this->loginintro = null; $this->registrationintro = null; $this->loginintro = TBGArticlesTable::getTable()->getArticleByName('LoginIntro'); $this->registrationintro = TBGArticlesTable::getTable()->getArticleByName('RegistrationIntro'); } catch (Exception $e) { } if (TBGSettings::isLoginRequired()) { TBGContext::getResponse()->deleteCookie('tbg3_username'); TBGContext::getResponse()->deleteCookie('tbg3_password'); $this->error = TBGContext::geti18n()->__('You need to log in to access this site'); } elseif (!TBGContext::getUser()->isAuthenticated()) { $this->error = TBGContext::geti18n()->__('Please log in'); } else { //$this->error = TBGContext::geti18n()->__('Please log in'); } }
public function getPredefinedBreadcrumbLinks($type, $project = null) { $i18n = TBGContext::getI18n(); $links = array(); switch ($type) { case 'main_links': $links[] = array('url' => TBGContext::getRouting()->generate('home'), 'title' => $i18n->__('Frontpage')); $links[] = array('url' => TBGContext::getRouting()->generate('dashboard'), 'title' => $i18n->__('Personal dashboard')); $links[] = array('title' => $i18n->__('Issues')); $links[] = array('title' => $i18n->__('Teams')); $links[] = array('title' => $i18n->__('Clients')); $links = TBGEvent::createNew('core', 'breadcrumb_main_links', null, array(), $links)->trigger()->getReturnList(); if (TBGContext::getUser()->canAccessConfigurationPage()) { $links[] = array('url' => make_url('configure'), 'title' => $i18n->__('Configure The Bug Genie')); } $links[] = array('url' => TBGContext::getRouting()->generate('about'), 'title' => $i18n->__('About %sitename%', array('%sitename%' => TBGSettings::getTBGname()))); $links[] = array('url' => TBGContext::getRouting()->generate('account'), 'title' => $i18n->__('Account details')); break; case 'project_summary': $links[] = array('url' => TBGContext::getRouting()->generate('project_dashboard', array('project_key' => $project->getKey())), 'title' => $i18n->__('Dashboard')); $links[] = array('url' => TBGContext::getRouting()->generate('project_scrum', array('project_key' => $project->getKey())), 'title' => $i18n->__('Sprint planning')); $links[] = array('url' => TBGContext::getRouting()->generate('project_roadmap', array('project_key' => $project->getKey())), 'title' => $i18n->__('Roadmap')); $links[] = array('url' => TBGContext::getRouting()->generate('project_team', array('project_key' => $project->getKey())), 'title' => $i18n->__('Team overview')); $links[] = array('url' => TBGContext::getRouting()->generate('project_statistics', array('project_key' => $project->getKey())), 'title' => $i18n->__('Statistics')); $links[] = array('url' => TBGContext::getRouting()->generate('project_timeline', array('project_key' => $project->getKey())), 'title' => $i18n->__('Timeline')); $links[] = array('url' => TBGContext::getRouting()->generate('project_reportissue', array('project_key' => $project->getKey())), 'title' => $i18n->__('Report an issue')); $links[] = array('url' => TBGContext::getRouting()->generate('project_issues', array('project_key' => $project->getKey())), 'title' => $i18n->__('Issues')); $links = TBGEvent::createNew('core', 'breadcrumb_project_links', null, array(), $links)->trigger()->getReturnList(); break; case 'client_list': foreach (TBGClient::getAll() as $client) { if ($client->hasAccess()) { $links[] = array('url' => TBGContext::getRouting()->generate('client_dashboard', array('client_id' => $client->getID())), 'title' => $client->getName()); } } break; case 'team_list': foreach (TBGTeam::getAll() as $team) { if ($team->hasAccess()) { $links[] = array('url' => TBGContext::getRouting()->generate('team_dashboard', array('team_id' => $team->getID())), 'title' => $team->getName()); } } break; } return $links; }
$routes[] = array('project_scrum_release_burndown_image', '/:project_key/scrum/burndown/release/image/*', 'project', 'scrumShowBurndownImage', array('mode' => 'release')); $routes[] = array('project_scrum_assign_story', '/:project_key/scrum/assign/story', 'project', 'scrumAssignStory'); $routes[] = array('project_scrum_add_sprint', '/:project_key/scrum/add/sprint', 'project', 'scrumAddSprint'); $routes[] = array('project_scrum_story_setcolor', '/:project_key/scrum/set/color/for/story/:story_id', 'project', 'scrumSetStoryDetail', array('detail' => 'color')); $routes[] = array('project_scrum_story_setestimates', '/:project_key/scrum/set/estimates/for/story/:story_id', 'project', 'scrumSetStoryDetail', array('detail' => 'estimates')); $routes[] = array('project_scrum_story_addtask', '/:project_key/scrum/add/task/for/story/:story_id/*', 'project', 'scrumAddTask'); $routes[] = array('project_search_paginated', '/:project_key/issues/paginated/*', 'search', 'findIssuesPaginated'); $routes[] = array('project_search_add_filter', '/:project_key/issues/add/filter/*', 'search', 'addFilter'); $routes[] = array('project_issues', '/:project_key/issues/find/*', 'search', 'findIssues'); $routes[] = array('viewissue', '/:project_key/issues/:issue_no/*', 'main', 'viewIssue'); $routes[] = array('project_quicksearch', '/:project_key/quicksearch/*', 'search', 'findIssues', array('quicksearch' => true, 'issues_per_page' => 6)); $routes[] = array('project_opensearch', '/:project_key/opensearch.xml', 'search', 'opensearch', array('format' => 'xml')); $routes[] = array('project_team', '/:project_key/team', 'project', 'team'); $routes[] = array('project_statistics', '/:project_key/statistics', 'project', 'statistics'); $routes[] = array('project_statistics_last_30', '/:project_key/statistics/last/30', 'project', 'statisticsLast30'); $routes[] = array('project_statistics_imagesets', '/:project_key/statistics/imagesets/:set', 'project', 'statisticsImagesets'); $routes[] = array('project_statistics_image', '/:project_key/statistics/image/:key/:mode/:image_number/*', 'project', 'statisticsGetImage'); $routes[] = array('project_timeline', '/:project_key/timeline/*', 'project', 'timeline'); $routes[] = array('project_timeline_important', '/:project_key/timeline/show/important/*', 'project', 'timeline'); $routes[] = array('project_files', '/:project_key/files', 'project', 'files'); $routes[] = array('project_roadmap', '/:project_key/roadmap', 'project', 'roadmap'); $routes[] = array('project_roadmap_milestone_issues', '/:project_key/milestone/:milestone_id/get/issues', 'project', 'getMilestoneIssues'); $routes[] = array('project_roadmap_milestone_refresh', '/:project_key/milestone/:milestone_id/get/details', 'project', 'getMilestoneDetails'); $routes[] = array('project_list_issues', '/:project_key/list/issues/:format/*', 'project', 'listIssues'); $routes[] = array('project_list_issuefields', '/:project_key/list/issuefields/for/type/:issuetype/:format', 'project', 'listIssuefields'); $routes[] = array('project_update_issuedetails', '/:project_key/update/issue/:issue_no/:format/*', 'project', 'updateIssueDetails'); $routes[] = array('project_list_workflowtransitions', '/:project_key/list/workflowtransitions/:issue_no/:format/*', 'project', 'listWorkflowTransitions'); $routes[] = array('project_dashboard', '/:project_key', 'project', 'dashboard'); foreach ($routes as $route) { call_user_func_array(array(TBGContext::getRouting(), 'addRoute'), $route); }
/** * Import all valid users * * @param TBGRequest $request */ public function runImportUsers(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'); $buddyname_attr = TBGContext::getModule('auth_ldap')->getSetting('b_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 = array(); $importcount = 0; $updatecount = 0; try { /* * Connect and bind to the control user */ $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')); /* * Get a list of all users of a certain objectClass */ $fields = array($fullname_attr, $buddyname_attr, $username_attr, $email_attr, 'cn', $dn_attr); $filter = '(objectClass=' . TBGLDAPAuthentication::getModule()->escape($user_class) . ')'; $results = ldap_search($connection, $base_dn, $filter, $fields); if (!$results) { TBGLogging::log('failed to search for users: ' . ldap_error($connection), 'ldap', TBGLogging::LEVEL_FATAL); throw new Exception(TBGContext::geti18n()->__('Search failed: ') . ldap_error($connection)); } $data = ldap_get_entries($connection, $results); /* * For every user that exists, process it. */ for ($i = 0; $i != $data['count']; $i++) { $user_dn = $data[$i][strtolower($dn_attr)][0]; /* * If groups are specified, perform group restriction tests */ if ($validgroups != '') { /* * We will repeat this for every group, but groups are supplied as a comma-separated list */ if (strstr($validgroups, ',')) { $groups = explode(',', $validgroups); } else { $groups = array(); $groups[] = $validgroups; } // Assumed we are initially banned $allowed = false; foreach ($groups as $group) { // No need to carry on looking if we have access if ($allowed == true) { continue; } /* * Find the group we are looking for, we search the entire directory * We want to find 1 group, if we don't get 1, silently ignore this group. */ $fields2 = array($groups_members_attr); $filter2 = '(&(cn=' . TBGLDAPAuthentication::getModule()->escape($group) . ')(objectClass=' . TBGLDAPAuthentication::getModule()->escape($group_class) . '))'; $results2 = ldap_search($connection, $base_dn, $filter2, $fields2); if (!$results2) { TBGLogging::log('failed to search for user: '******'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; } /* * Look through the group's member list. If we are found, grant access. */ foreach ($data2[0][strtolower($groups_members_attr)] as $member) { $member = preg_replace('/(?<=,) +(?=[a-zA-Z])/', '', $member); $user_dn = preg_replace('/(?<=,) +(?=[a-zA-Z])/', '', $user_dn); if (!is_numeric($member) && strtolower($member) == strtolower($user_dn)) { $allowed = true; } } } if ($allowed == false) { continue; } } $users[$i] = array(); /* * Set user's properties. * Realname is obtained from directory, if not found we set it to the username * Email is obtained from directory, if not found we set it to blank */ if (!array_key_exists(strtolower($fullname_attr), $data[$i])) { $users[$i]['realname'] = $data[$i]['cn'][0]; } else { $users[$i]['realname'] = $data[$i][strtolower($fullname_attr)][0]; } if (!array_key_exists(strtolower($buddyname_attr), $data[$i])) { $users[$i]['buddyname'] = $data[$i]['cn'][0]; } else { $users[$i]['buddyname'] = $data[$i][strtolower($buddyname_attr)][0]; } if (!array_key_exists(strtolower($email_attr), $data[$i])) { $users[$i]['email'] = ''; } else { $users[$i]['email'] = $data[$i][strtolower($email_attr)][0]; } $users[$i]['username'] = $data[$i][strtolower($username_attr)][0]; } } catch (Exception $e) { TBGContext::setMessage('module_error', TBGContext::getI18n()->__('Import failed')); TBGContext::setMessage('module_error_details', $e->getMessage()); $this->forward(TBGContext::getRouting()->generate('configure_module', array('config_module' => 'auth_ldap'))); } /* * For every user that was found, either create a new user object, or update * the existing one. This will update the created and updated counts as appropriate. */ foreach ($users as $ldapuser) { $username = $ldapuser['username']; $email = $ldapuser['email']; $realname = $ldapuser['realname']; $buddyname = $ldapuser['buddyname']; try { $user = TBGUser::getByUsername($username); if ($user instanceof TBGUser) { $user->setRealname($realname); $user->setEmail($email); // update email address $user->save(); $updatecount++; } else { // create user $user = new TBGUser(); $user->setUsername($username); $user->setRealname($realname); $user->setBuddyname($buddyname); $user->setEmail($email); $user->setEnabled(); $user->setActivated(); $user->setPassword($user->getJoinedDate() . $username); $user->setJoined(); $user->save(); $importcount++; } } catch (Exception $e) { ldap_unbind($connection); TBGContext::setMessage('module_error', TBGContext::getI18n()->__('Import 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()->__('Import successful! %imp users imported, %upd users updated from LDAP', array('%imp' => $importcount, '%upd' => $updatecount))); $this->forward(TBGContext::getRouting()->generate('configure_module', array('config_module' => 'auth_ldap'))); }
public function hasTranslatedTemplate($template, $is_component = false) { if (strpos($template, '/')) { $templateinfo = explode('/', $template); $module = $templateinfo[0]; $templatefile = $is_component ? '_' . $templateinfo[1] . '.inc.php' : $templateinfo[1] . '.' . TBGContext::getRequest()->getRequestedFormat() . '.php'; } else { $module = TBGContext::getRouting()->getCurrentRouteModule(); $templatefile = $is_component ? '_' . $template . '.inc.php' : $template . '.' . TBGContext::getRequest()->getRequestedFormat() . '.php'; } if (file_exists(THEBUGGENIE_MODULES_PATH . $module . DS . 'i18n' . DS . $this->_language . DS . 'templates' . DS . $templatefile)) { return THEBUGGENIE_MODULES_PATH . $module . DS . 'i18n' . DS . $this->_language . DS . 'templates' . DS . $templatefile; } elseif (file_exists(THEBUGGENIE_PATH . 'i18n' . DS . $this->getCurrentLanguage() . DS . 'templates' . DS . $module . DS . $templatefile)) { return THEBUGGENIE_PATH . 'i18n' . DS . $this->getCurrentLanguage() . DS . 'templates' . DS . $module . DS . $templatefile; } return false; }
public function runProjectIcons(TBGRequest $request) { if ($this->getUser()->canManageProject($this->selected_project) || $this->getUser()->canManageProjectReleases($this->selected_project)) { if ($request->isPost()) { if ($request['clear_icons']) { $this->selected_project->clearSmallIcon(); $this->selected_project->clearLargeIcon(); } else { switch ($request['small_icon_action']) { case 'upload_file': $file = $request->handleUpload('small_icon'); $this->selected_project->setSmallIcon($file); break; case 'clear_file': $this->selected_project->clearSmallIcon(); break; } switch ($request['large_icon_action']) { case 'upload_file': $file = $request->handleUpload('large_icon'); $this->selected_project->setLargeIcon($file); break; case 'clear_file': $this->selected_project->clearLargeIcon(); break; } } $this->selected_project->save(); } $route = TBGContext::getRouting()->generate('project_settings', array('project_key' => $this->selected_project->getKey())); if ($request->isAjaxCall()) { return $this->renderJSON(array('forward' => $route)); } else { $this->forward($route); } } return $this->forward403($this->getI18n()->__("You don't have access to perform this action")); }
} ?> <?php if ($tbg_user->canAccessConfigurationPage()) { ?> <?php echo link_tag(make_url('configure'), image_tag('tab_config.png') . __('Configure %thebuggenie_name', array('%thebuggenie_name' => TBGSettings::getTBGname()))); ?> <?php } ?> <?php TBGEvent::createNew('core', 'user_dropdown_reg')->trigger(); ?> <?php echo link_tag('http://www.thebuggenie.com/help/' . TBGContext::getRouting()->getCurrentRouteName(), image_tag('help.png') . __('Help for this page'), array('id' => 'global_help_link')); ?> <a href="<?php echo make_url('logout'); ?> " onclick="<?php if (TBGSettings::isPersonaAvailable()) { ?> if (navigator.id) { navigator.id.logout();return false; }<?php } ?> "><?php echo image_tag('logout.png') . __('Logout'); ?> </a> <div class="header"><?php
public static function getFaviconURL() { return self::isUsingCustomFavicon() ? TBGContext::getRouting()->generate('showfile', array('id' => self::getFaviconID())) : 'favicon.png'; }
/** * Performs the "find issues" action * * @param TBGRequest $request */ public function runFindIssues(TBGRequest $request) { $this->_getSearchDetailsFromRequest($request); if ($request->isMethod(TBGRequest::POST) && !$request->getParameter('quicksearch')) { if ($request->getParameter('delete_saved_search')) { try { $search = TBGSavedSearchesTable::getTable()->getByID($request->getParameter('saved_search_id')); if ($search->get(TBGSavedSearchesTable::UID) == TBGContext::getUser()->getID() || $search->get(TBGSavedSearchesTable::IS_PUBLIC) && TBGContext::getUser()->canCreatePublicSearches()) { TBGSavedSearchesTable::getTable()->doDeleteById($request->getParameter('saved_search_id')); return $this->renderJSON(array('failed' => false, 'message' => TBGContext::getI18n()->__('The saved search was deleted successfully'))); } } catch (Exception $e) { return $this->renderJSON(array('failed' => true, 'message' => TBGContext::getI18n()->__('Cannot delete this saved search'))); } } elseif ($request->getParameter('saved_search_name') != '') { $project_id = TBGContext::isProjectContext() ? TBGContext::getCurrentProject()->getID() : 0; TBGSavedSearchesTable::getTable()->saveSearch($request->getParameter('saved_search_name'), $request->getParameter('saved_search_description'), $request->getParameter('saved_search_public'), $this->filters, $this->groupby, $this->grouporder, $this->ipp, $this->templatename, $this->template_parameter, $project_id, $request->getParameter('saved_search_id')); if ($request->getParameter('saved_search_id')) { TBGContext::setMessage('search_message', TBGContext::getI18n()->__('The saved search was updated')); } else { TBGContext::setMessage('search_message', TBGContext::getI18n()->__('The saved search has been created')); } $params = array(); } else { TBGContext::setMessage('search_error', TBGContext::getI18n()->__('You have to specify a name for the saved search')); $params = array('filters' => $this->filters, 'groupby' => $this->groupby, 'grouporder' => $this->grouporder, 'templatename' => $this->templatename, 'saved_search' => $request->getParameter('saved_search_id'), 'issues_per_page' => $this->ipp); } if (TBGContext::isProjectContext()) { $route = 'project_issues'; $params['project_key'] = TBGContext::getCurrentProject()->getKey(); } else { $route = 'search'; } $this->forward(TBGContext::getRouting()->generate($route, $params)); } else { $this->doSearch($request); $this->issues = $this->foundissues; if ($request->getParameter('quicksearch') == true) { $this->redirect('quicksearch'); } } $this->search_error = TBGContext::getMessageAndClear('search_error'); $this->search_message = TBGContext::getMessageAndClear('search_message'); $this->appliedfilters = $this->filters; $this->templates = $this->getTemplates(); $this->savedsearches = B2DB::getTable('TBGSavedSearchesTable')->getAllSavedSearchesByUserIDAndPossiblyProjectID(TBGContext::getUser()->getID(), TBGContext::isProjectContext() ? TBGContext::getCurrentProject()->getID() : 0); }
</div> </div> <div id="fullpage_backdrop" style="display: none; background-color: transparent; z-index: 1; width: 100%; height: 100%; position: fixed; top: 0; left: 0; margin: 0; padding: 0; text-align: center;"> <div style="position: absolute; top: 45%; left: 40%; z-index: 100001; color: #FFF; font-size: 15px; font-weight: bold;" id="fullpage_backdrop_indicator"> <?php echo image_tag('spinning_32.gif'); ?> <br> <?php echo __('Please wait, loading content'); ?> ... </div> <div id="fullpage_backdrop_content"> </div> <div style="background-color: #000; width: 100%; height: 100%; position: absolute; top: 0; left: 0; margin: 0; padding: 0; z-index: 100000;" class="semi_transparent" <?php if (TBGContext::getRouting()->getCurrentRouteAction() != 'login') { ?> onclick="resetFadedBackdrop();"<?php } ?> > </div> </div> <table style="width: 100%; height: 100%; table-layout: fixed; min-width: 1020px;" cellpadding=0 cellspacing=0> <tr> <td style="height: auto; overflow: hidden;" valign="top" id="maintd"> <table class="main_header" cellpadding=0 cellspacing=0 width="100%" style="table-layout: fixed;"> <tr> <td align="left" valign="middle" id="logo_td"> <?php $link = TBGSettings::getHeaderLink() == '' ? TBGContext::getTBGPath() : TBGSettings::getHeaderLink(); ?>
protected function _parse_internallink($matches) { $href = html_entity_decode($matches[4]); if (isset($matches[6]) && $matches[6]) { $title = $matches[6]; } else { $title = $href; if (isset($matches[7]) && $matches[7]) { $title .= $matches[7]; } } $namespace = $matches[3]; if (strtolower($namespace) == 'category') { if (substr($matches[2], 0, 1) != ':') { $this->addCategorizer($href); return ''; } } if (strtolower($namespace) == 'wikipedia') { if (TBGContext::isCLI()) { return $href; } $options = explode('|', $title); $title = (array_key_exists(5, $matches) && strpos($matches[5], '|') !== false ? '' : $namespace . ':') . array_pop($options); return link_tag('http://en.wikipedia.org/wiki/' . $href, $title); } if (in_array(strtolower($namespace), array('image', 'file'))) { $retval = $namespace . ':' . $href; if (!TBGContext::isCLI()) { $options = explode('|', $title); $filename = $href; $issuemode = (bool) (isset($this->options['issue']) && $this->options['issue'] instanceof TBGIssue); $articlemode = (bool) (isset($this->options['article']) && $this->options['article'] instanceof TBGWikiArticle); $file = null; $file_link = $filename; $caption = $filename; if ($issuemode) { $file = $this->options['issue']->getFileByFilename($filename); } elseif ($articlemode) { $file = $this->options['article']->getFileByFilename($filename); } if ($file instanceof TBGFile) { $caption = !empty($options) ? array_pop($options) : $file->getDescription(); $caption = $caption != '' ? $caption : $file->getOriginalFilename(); $file_link = make_url('showfile', array('id' => $file->getID())); } if (($file instanceof TBGFile && $file->isImage() || $articlemode) && (strtolower($namespace) == 'image' || $issuemode) && TBGSettings::isCommentImagePreviewEnabled()) { $divclasses = array('image_container'); $style_dimensions = ''; foreach ($options as $option) { $optionlen = strlen($option); if (substr($option, $optionlen - 2) == 'px') { if (is_numeric($option[0])) { $style_dimensions = ' width: ' . $option[0] . ';'; break; } else { $style_dimensions = ' height: ' . substr($option[0], 1) . ';'; break; } } } if (in_array('thumb', $options)) { $divclasses[] = 'thumb'; } if (in_array('left', $options)) { $divclasses[] = 'icleft'; } if (in_array('center', $options)) { $divclasses[] = 'iccenter'; } if (in_array('right', $options)) { $divclasses[] = 'icright'; } $retval = '<div class="' . join(' ', $divclasses) . '"'; if ($issuemode) { $retval .= ' style="float: left; clear: left;"'; } $retval .= '>'; $retval .= image_tag($file_link, array('alt' => $caption, 'title' => $caption, 'style' => $style_dimensions, 'class' => 'image'), true); if ($caption != '') { $retval .= '<br>' . $caption; } $retval .= link_tag($file_link, image_tag('icon_open_new.png', array('style' => 'margin-left: 5px;')), array('target' => 'new_window_' . rand(0, 10000), 'title' => __('Open image in new window'))); $retval .= '</div>'; } else { $retval = link_tag($file_link, $caption . image_tag('icon_open_new.png', array('style' => 'margin-left: 5px;')), array('target' => 'new_window_' . rand(0, 10000), 'title' => __('Open file in new window'))); } } return $retval; //$file_id = TBGFilesTable::get } if ($namespace == 'TBG') { if (TBGContext::isCLI()) { return $href; } $options = explode('|', $title); $title = array_pop($options); return link_tag(make_url($href), $title); // $this->parse_image($href,$title,$options); } if (substr($href, 0, 1) == '/') { if (TBGContext::isCLI()) { return $href; } $options = explode('|', $title); $title = array_pop($options); return link_tag($href, $title); // $this->parse_image($href,$title,$options); } $title = preg_replace('/\\(.*?\\)/', '', $title); $title = preg_replace('/^.*?\\:/', '', $title); if (!$namespace || !array_key_exists($namespace, array('ftp', 'http', 'https', 'gopher', 'mailto', 'news', 'nntp', 'telnet', 'wais', 'file', 'prospero', 'aim', 'webcal'))) { if ($namespace) { $href = $namespace . ':' . $href; } $href = $this->_wiki_link($href); $title = isset($title) ? $title : $href; $this->addInternalLinkOccurrence($href); if (TBGContext::isCLI()) { return $href; } $href = TBGContext::getRouting()->generate('publish_article', array('article_name' => $href)); } else { $href = $namespace . ':' . $this->_wiki_link($href); } if (TBGContext::isCLI()) { return $href; } return link_tag($href, $title); }
public function runScopes(TBGRequest $request) { if ($request->isMethod(TBGRequest::POST)) { $hostname = $request->getParameter('hostname'); $scopename = $request->getParameter('name'); if (!$hostname || TBGScopesTable::getTable()->getByHostname($hostname) instanceof TBGScope) { $this->scope_hostname_error = true; } elseif (!$scopename) { $this->scope_name_error = true; } else { $scope = new TBGScope(); $scope->addHostname($hostname); $scope->setName($scopename); $scope->setEnabled(); $scope->save(); $this->forward(TBGContext::getRouting()->generate('configure_scopes')); } } $this->scope_deleted = TBGContext::getMessageAndClear('scope_deleted'); $this->scopes = TBGScope::getAll(); }
public function runTransitionIssue(TBGRequest $request) { try { $transition = TBGContext::factory()->TBGWorkflowTransition($request->getParameter('transition_id')); $issue = TBGContext::factory()->TBGIssue($request->getParameter('issue_id')); if (!$issue->isWorkflowTransitionsAvailable()) { throw new Exception(TBGContext::getI18n()->__('You are not allowed to perform any workflow transitions on this issue')); } if ($transition->validateFromRequest($request)) { $transition->transitionIssueToOutgoingStepFromRequest($issue); } else { TBGContext::setMessage('issue_error', 'transition_error'); TBGContext::setMessage('issue_workflow_errors', $transition->getValidationErrors()); } $this->forward(TBGContext::getRouting()->generate('viewissue', array('project_key' => $issue->getProject()->getKey(), 'issue_no' => $issue->getFormattedIssueNo()))); } catch (Exception $e) { throw $e; return $this->return404(); } }
/** * Forward the user with HTTP status code 403 and an (optional) message * based on a boolean check * * @param boolean $condition * @param string $message[optional] The message */ public function forward403unless($condition, $message = null) { if (!$condition) { $message = $message === null ? TBGContext::getI18n()->__("You are not allowed to access to this page") : $message; TBGContext::setMessage('forward', $message); $this->forward(TBGContext::getRouting()->generate('login_redirect'), 403); } }
/** * Returns the logged in user, or default user if not logged in * * @param TBGRequest $request * @param TBGAction $action * * @return TBGUser */ public static function loginCheck(TBGRequest $request, TBGAction $action) { try { $authentication_method = $action->getAuthenticationMethodForAction(TBGContext::getRouting()->getCurrentRouteAction()); $user = null; $external = false; switch ($authentication_method) { case TBGAction::AUTHENTICATION_METHOD_ELEVATED: case TBGAction::AUTHENTICATION_METHOD_CORE: $username = $request['tbg3_username']; $password = $request['tbg3_password']; if ($authentication_method == TBGAction::AUTHENTICATION_METHOD_ELEVATED) { $elevated_password = $request['tbg3_elevated_password']; } $raw = true; // If no username and password specified, check if we have a session that exists already if ($username === null && $password === null) { if (TBGContext::getRequest()->hasCookie('tbg3_username') && TBGContext::getRequest()->hasCookie('tbg3_password')) { $username = TBGContext::getRequest()->getCookie('tbg3_username'); $password = TBGContext::getRequest()->getCookie('tbg3_password'); $user = TBGUsersTable::getTable()->getByUsername($username); if ($authentication_method == TBGAction::AUTHENTICATION_METHOD_ELEVATED) { $elevated_password = TBGContext::getRequest()->getCookie('tbg3_elevated_password'); if ($user instanceof TBGUser && !$user->hasPasswordHash($password)) { $user = null; } else { if ($user instanceof TBGUser && !$user->hasPasswordHash($elevated_password)) { TBGContext::setUser($user); TBGContext::getRouting()->setCurrentRouteName('elevated_login_page'); throw new TBGElevatedLoginException('reenter'); } } } else { if ($user instanceof TBGUser && !$user->hasPasswordHash($password)) { $user = null; } } $raw = false; if (!$user instanceof TBGUser) { TBGContext::logout(); throw new Exception('No such login'); } } } // If we have authentication details, validate them if (TBGSettings::isUsingExternalAuthenticationBackend() && $username !== null && $password !== null) { $external = true; TBGLogging::log('Authenticating with backend: ' . TBGSettings::getAuthenticationBackend(), 'auth', TBGLogging::LEVEL_INFO); try { $mod = TBGContext::getModule(TBGSettings::getAuthenticationBackend()); if ($mod->getType() !== TBGModule::MODULE_AUTH) { TBGLogging::log('Auth module is not the right type', 'auth', TBGLogging::LEVEL_FATAL); } if (TBGContext::getRequest()->hasCookie('tbg3_username') && TBGContext::getRequest()->hasCookie('tbg3_password')) { $user = $mod->verifyLogin($username, $password); } else { $user = $mod->doLogin($username, $password); } if (!$user instanceof TBGUser) { // Invalid TBGContext::logout(); throw new Exception('No such login'); //TBGContext::getResponse()->headerRedirect(TBGContext::getRouting()->generate('login')); } } catch (Exception $e) { throw $e; } } elseif (TBGSettings::isUsingExternalAuthenticationBackend()) { $external = true; TBGLogging::log('Authenticating without credentials with backend: ' . TBGSettings::getAuthenticationBackend(), 'auth', TBGLogging::LEVEL_INFO); try { $mod = TBGContext::getModule(TBGSettings::getAuthenticationBackend()); if ($mod->getType() !== TBGModule::MODULE_AUTH) { TBGLogging::log('Auth module is not the right type', 'auth', TBGLogging::LEVEL_FATAL); } $user = $mod->doAutoLogin(); if ($user == false) { // Invalid TBGContext::logout(); throw new Exception('No such login'); //TBGContext::getResponse()->headerRedirect(TBGContext::getRouting()->generate('login')); } } catch (Exception $e) { throw $e; } } elseif ($username !== null && $password !== null && !$user instanceof TBGUser) { $external = false; TBGLogging::log('Using internal authentication', 'auth', TBGLogging::LEVEL_INFO); $user = TBGUsersTable::getTable()->getByUsername($username); if (!$user->hasPassword($password)) { $user = null; } if (!$user instanceof TBGUser) { TBGContext::logout(); } } break; case TBGAction::AUTHENTICATION_METHOD_DUMMY: $user = TBGUsersTable::getTable()->getByUserID(TBGSettings::getDefaultUserID()); break; case TBGAction::AUTHENTICATION_METHOD_CLI: $user = TBGUsersTable::getTable()->getByUsername(TBGContext::getCurrentCLIusername()); break; case TBGAction::AUTHENTICATION_METHOD_RSS_KEY: $user = TBGUsersTable::getTable()->getByRssKey($request['rsskey']); break; case TBGAction::AUTHENTICATION_METHOD_APPLICATION_PASSWORD: $user = TBGUsersTable::getTable()->getByUsername($request['api_username']); if (!$user->authenticateApplicationPassword($request['api_token'])) { $user = null; } break; default: if (!TBGSettings::isLoginRequired()) { $user = TBGUsersTable::getTable()->getByUserID(TBGSettings::getDefaultUserID()); } } if ($user instanceof TBGUser) { if (!$user->isActivated()) { throw new Exception('This account has not been activated yet'); } elseif (!$user->isEnabled()) { throw new Exception('This account has been suspended'); } elseif (!$user->isConfirmedMemberOfScope(TBGContext::getScope())) { if (!TBGSettings::isRegistrationAllowed()) { throw new Exception('This account does not have access to this scope'); } } if ($external == false && $authentication_method == TBGAction::AUTHENTICATION_METHOD_CORE) { $password = $user->getHashPassword(); if (!$request->hasCookie('tbg3_username')) { if ($request->getParameter('tbg3_rememberme')) { TBGContext::getResponse()->setCookie('tbg3_username', $user->getUsername()); TBGContext::getResponse()->setCookie('tbg3_password', $user->getPassword()); } else { TBGContext::getResponse()->setSessionCookie('tbg3_username', $user->getUsername()); TBGContext::getResponse()->setSessionCookie('tbg3_password', $user->getPassword()); } } } } elseif (TBGSettings::isLoginRequired()) { throw new Exception('Login required'); } else { throw new Exception('No such login'); } } catch (Exception $e) { throw $e; } return $user; }