本文整理汇总了PHP中TBGContext::getResponse方法的典型用法代码示例。如果您正苦于以下问题:PHP TBGContext::getResponse方法的具体用法?PHP TBGContext::getResponse怎么用?PHP TBGContext::getResponse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TBGContext
的用法示例。
在下文中一共展示了TBGContext::getResponse方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: preExecute
/**
* Pre-execute function for search functions
*
* @param TBGRequest $request
*/
public function preExecute(TBGRequest $request, $action)
{
$this->forward403unless(TBGContext::getUser()->hasPageAccess('search') && TBGContext::getUser()->canSearchForIssues());
if ($project_key = $request['project_key']) {
$project = TBGProject::getByKey($project_key);
} elseif (is_numeric($request['project_id']) && ($project_id = (int) $request['project_id'])) {
$project = TBGProjectsTable::getTable()->selectById($project_id);
} else {
$project = false;
}
if ($project instanceof TBGProject) {
$this->forward403unless(TBGContext::getUser()->hasProjectPageAccess('project_issues', $project));
TBGContext::getResponse()->setPage('project_issues');
TBGContext::setCurrentProject($project);
}
$this->search_object = TBGSavedSearch::getFromRequest($request);
$this->issavedsearch = $this->search_object instanceof TBGSavedSearch && $this->search_object->getB2DBID();
$this->show_results = $this->issavedsearch || $request->hasParameter('quicksearch') || $request->hasParameter('fs') || $request->getParameter('search', false) ? true : false;
$this->searchterm = $this->search_object->getSearchterm();
$this->searchtitle = $this->search_object->getTitle();
if ($this->issavedsearch) {
if (!($this->search_object instanceof TBGSavedSearch && TBGContext::getUser()->canAccessSavedSearch($this->search_object))) {
TBGContext::setMessage('search_error', TBGContext::getI18n()->__("You don't have access to this saved search"));
}
}
}
示例2: preExecute
/**
* Pre-execute function for search functions
*
* @param TBGRequest $request
*/
public function preExecute(TBGRequest $request, $action)
{
$this->forward403unless(TBGContext::getUser()->hasPageAccess('search') && TBGContext::getUser()->canSearchForIssues());
if ($request->hasParameter('project_key')) {
if (($project = TBGProject::getByKey($request->getParameter('project_key'))) instanceof TBGProject) {
$this->forward403unless(TBGContext::getUser()->hasProjectPageAccess('project_issues', $project->getID()));
TBGContext::getResponse()->setPage('project_issues');
TBGContext::setCurrentProject($project);
}
}
$filters = $request->getParameter('filters', array());
$this->searchterm = null;
if (array_key_exists('text', $filters) && array_key_exists('value', $filters['text'])) {
$this->searchterm = $filters['text']['value'];
}
}
示例3: tbg_get_breadcrumblinks
function tbg_get_breadcrumblinks($type, $project = null)
{
return TBGContext::getResponse()->getPredefinedBreadcrumbLinks($type, $project);
}
示例4: loginCheck
//.........这里部分代码省略.........
$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;
}
示例5: _parse_variable
protected function _parse_variable($matches)
{
switch ($matches[2]) {
case 'CURRENTMONTH':
return date('m');
case 'CURRENTMONTHNAMEGEN':
case 'CURRENTMONTHNAME':
return date('F');
case 'CURRENTDAY':
return date('d');
case 'CURRENTDAYNAME':
return date('l');
case 'CURRENTYEAR':
return date('Y');
case 'CURRENTTIME':
return date('H:i');
case 'NUMBEROFARTICLES':
return 0;
case 'PAGENAME':
return TBGContext::getResponse()->getPage();
case 'NAMESPACE':
return 'None';
case 'TOC':
return '{{TOC}}';
case 'SITENAME':
return TBGSettings::getTBGname();
case 'SITETAGLINE':
return TBGSettings::getTBGtagline();
default:
return '';
}
}
示例6: tbg_get_stylesheets
function tbg_get_stylesheets()
{
$tbg_response = TBGContext::getResponse();
$cssstrings = array();
$sepcss = array();
// Add stylesheets to minify and non-minify lists
foreach ($tbg_response->getStylesheets() as $stylesheet => $minify) {
if ($minify == true && file_exists(THEBUGGENIE_PATH . THEBUGGENIE_PUBLIC_FOLDER_NAME . DIRECTORY_SEPARATOR . 'themes' . DIRECTORY_SEPARATOR . TBGSettings::getThemeName() . DIRECTORY_SEPARATOR . $stylesheet)) {
$cssstrings[] = 'themes/' . TBGSettings::getThemeName() . '/' . $stylesheet;
} else {
$sepcss[] = $stylesheet;
}
}
$cssstrings = join(',', $cssstrings);
return array($cssstrings, $sepcss);
}
示例7: runDoLogin
/**
* Do login (AJAX call)
*
* @param TBGRequest $request
*/
public function runDoLogin(TBGRequest $request)
{
$i18n = TBGContext::getI18n();
$options = $request->getParameters();
$forward_url = TBGContext::getRouting()->generate('home');
if ($request->hasParameter('persona') && $request['persona'] == 'true') {
$url = 'https://verifier.login.persona.org/verify';
$assert = filter_input(INPUT_POST, 'assertion', FILTER_UNSAFE_RAW, FILTER_FLAG_STRIP_LOW | FILTER_FLAG_STRIP_HIGH);
//Use the $_POST superglobal array for PHP < 5.2 and write your own filter
$params = 'assertion=' . urlencode($assert) . '&audience=' . urlencode(TBGContext::getURLhost() . ':80');
$ch = curl_init();
$options = array(CURLOPT_URL => $url, CURLOPT_RETURNTRANSFER => TRUE, CURLOPT_POST => 2, CURLOPT_POSTFIELDS => $params);
curl_setopt_array($ch, $options);
$result = curl_exec($ch);
curl_close($ch);
$details = json_decode($result);
$user = null;
if ($details->status == 'okay') {
$user = TBGUser::getByEmail($details->email);
if ($user instanceof TBGUser) {
TBGContext::getResponse()->setCookie('tbg3_password', $user->getPassword());
TBGContext::getResponse()->setCookie('tbg3_username', $user->getUsername());
TBGContext::getResponse()->setCookie('tbg3_persona_session', true);
return $this->renderJSON(array('status' => 'login ok', 'redirect' => in_array($request['referrer_route'], array('home', 'login'))));
}
}
if (!$user instanceof TBGUser) {
$this->getResponse()->setHttpStatus(401);
$this->renderJSON(array('message' => $this->getI18n()->__('Invalid login')));
}
return;
}
if (TBGSettings::isOpenIDavailable()) {
$openid = new LightOpenID(TBGContext::getRouting()->generate('login_page', array(), false));
}
if (TBGSettings::isOpenIDavailable() && !$openid->mode && $request->isPost() && $request->hasParameter('openid_identifier')) {
$openid->identity = $request->getRawParameter('openid_identifier');
$openid->required = array('contact/email');
$openid->optional = array('namePerson/first', 'namePerson/friendly');
return $this->forward($openid->authUrl());
} elseif (TBGSettings::isOpenIDavailable() && $openid->mode == 'cancel') {
$this->error = TBGContext::getI18n()->__("OpenID authentication cancelled");
} elseif (TBGSettings::isOpenIDavailable() && $openid->mode) {
try {
if ($openid->validate()) {
if ($this->getUser()->isAuthenticated() && !$this->getUser()->isGuest()) {
if (TBGOpenIdAccountsTable::getTable()->getUserIDfromIdentity($openid->identity)) {
TBGContext::setMessage('openid_used', true);
throw new Exception('OpenID already in use');
}
$user = $this->getUser();
} else {
$user = TBGUser::getByOpenID($openid->identity);
}
if ($user instanceof TBGUser) {
$attributes = $openid->getAttributes();
$email = array_key_exists('contact/email', $attributes) ? $attributes['contact/email'] : null;
if (!$user->getEmail()) {
if (array_key_exists('contact/email', $attributes)) {
$user->setEmail($attributes['contact/email']);
}
if (array_key_exists('namePerson/first', $attributes)) {
$user->setRealname($attributes['namePerson/first']);
}
if (array_key_exists('namePerson/friendly', $attributes)) {
$user->setBuddyname($attributes['namePerson/friendly']);
}
if (!$user->getNickname() || $user->isOpenIdLocked()) {
$user->setBuddyname($user->getEmail());
}
if (!$user->getRealname()) {
$user->setRealname($user->getBuddyname());
}
$user->save();
}
if (!$user->hasOpenIDIdentity($openid->identity)) {
TBGOpenIdAccountsTable::getTable()->addIdentity($openid->identity, $email, $user->getID());
}
TBGContext::getResponse()->setCookie('tbg3_password', $user->getPassword());
TBGContext::getResponse()->setCookie('tbg3_username', $user->getUsername());
if ($this->checkScopeMembership($user)) {
return true;
}
return $this->forward(TBGContext::getRouting()->generate(TBGSettings::get('returnfromlogin')));
} else {
$this->error = TBGContext::getI18n()->__("Didn't recognize this OpenID. Please log in using your username and password, associate it with your user account in your account settings and try again.");
}
} else {
$this->error = TBGContext::getI18n()->__("Could not validate against the OpenID provider");
}
} catch (Exception $e) {
$this->error = TBGContext::getI18n()->__("Could not validate against the OpenID provider: %message", array('%message' => htmlentities($e->getMessage(), ENT_COMPAT, TBGContext::getI18n()->getCharset())));
}
} elseif ($request->getMethod() == TBGRequest::POST) {
try {
//.........这里部分代码省略.........
示例8: _parse_insert_template
protected function _parse_insert_template($matches)
{
switch ($matches[1]) {
case 'CURRENTMONTH':
return date('m');
case 'CURRENTMONTHNAMEGEN':
case 'CURRENTMONTHNAME':
return date('F');
case 'CURRENTDAY':
return date('d');
case 'CURRENTDAYNAME':
return date('l');
case 'CURRENTYEAR':
return date('Y');
case 'CURRENTTIME':
return date('H:i');
case 'NUMBEROFARTICLES':
return 0;
case 'PAGENAME':
return TBGContext::getResponse()->getPage();
case 'NAMESPACE':
return 'None';
case 'TOC':
return isset($this->options['included']) ? '' : '{{TOC}}';
case 'SITENAME':
case 'SITETAGLINE':
return TBGSettings::getTBGname();
default:
$details = explode('|', $matches[1]);
$template_name = array_shift($details);
if (substr($template_name, 0, 1) == ':') {
$template_name = substr($template_name, 1);
}
$template_name = TBGWikiArticle::doesArticleExist($template_name) ? $template_name : 'Template:' . $template_name;
$template_article = TBGArticlesTable::getTable()->getArticleByName($template_name);
$parameters = array();
if (count($details)) {
foreach ($details as $parameter) {
$param = explode('=', $parameter);
if (count($param) == 2) {
$parameters[$param[0]] = $param[1];
} else {
$parameters[] = $parameter;
}
}
}
if ($template_article instanceof TBGWikiArticle) {
return tbg_parse_text($template_article->getContent(), false, null, array('included' => true, 'parameters' => $parameters));
} else {
return $matches[0];
}
}
}
示例9: componentLogin
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');
}
}
示例10: url
<?php
/**
* Configuration for theme
*/
TBGContext::getResponse()->addStylesheet('oxygen.css');
?>
<style>
#tbg3_username, #fieldusername { background-image: url('<?php
echo TBGContext::getTBGPath() . 'iconsets/' . TBGSettings::getIconsetName() . '/';
?>
user_mono.png'); }
#fieldusername.invalid { background-image: url('<?php
echo TBGContext::getTBGPath() . 'iconsets/' . TBGSettings::getIconsetName() . '/';
?>
icon_error.png'); background-color: rgba(255, 220, 220, 0.5); }
#fieldusername.valid { background-image: url('<?php
echo TBGContext::getTBGPath() . 'iconsets/' . TBGSettings::getIconsetName() . '/';
?>
icon_ok.png'); background-color: rgba(220, 255, 220, 0.5); }
.login_popup input[type=password] { background-image: url('<?php
echo TBGContext::getTBGPath() . 'iconsets/' . TBGSettings::getIconsetName() . '/';
?>
password_mono.png'); }
#openid-signin-button.persona-button span:after{ background-image: url('<?php
echo TBGContext::getTBGPath() . 'iconsets/' . TBGSettings::getIconsetName() . '/';
?>
openid_providers.small/openid.ico.png'); }
#regular-signin-button.persona-button span:after{ background-image: url('<?php
echo TBGContext::getTBGPath() . 'iconsets/' . TBGSettings::getIconsetName() . '/';
?>
示例11: runAddCommitGitorious
public function runAddCommitGitorious(TBGRequest $request)
{
TBGContext::getResponse()->setContentType('text/plain');
TBGContext::getResponse()->renderHeaders();
$passkey = TBGContext::getRequest()->getParameter('passkey');
$project_id = urldecode(TBGContext::getRequest()->getParameter('project_id'));
$project = TBGContext::factory()->TBGProject($project_id);
// Validate access
if (!$project) {
echo 'Error: The project with the ID ' . $project_id . ' does not exist';
exit;
}
if (TBGSettings::get('access_method_' . $project->getID(), 'vcs_integration') == TBGVCSIntegration::ACCESS_DIRECT) {
echo 'Error: This project uses the CLI access method, and so access via HTTP has been disabled';
exit;
}
if (TBGSettings::get('access_passkey_' . $project->getID(), 'vcs_integration') != $passkey) {
echo 'Error: The passkey specified does not match the passkey specified for this project';
exit;
}
// Validate data
$data = html_entity_decode(TBGContext::getRequest()->getParameter('payload', null, false));
if (empty($data) || $data == null) {
die('Error: No payload was provided');
}
$entries = json_decode($data);
if ($entries == null) {
die('Error: The payload could not be decoded');
}
$entries = json_decode($data);
$previous = $entries->before;
// Branch is stored in the ref
$ref = $entries->ref;
$parts = explode('/', $ref);
if (count($parts) == 3) {
$branch = $parts[2];
} else {
$branch = null;
}
// Parse each commit individually
foreach (array_reverse($entries->commits) as $commit) {
$email = $commit->author->email;
$author = $commit->author->name;
$new_rev = $commit->id;
$old_rev = $previous;
$commit_msg = $commit->message;
$time = strtotime($commit->timestamp);
// Add commit
echo TBGVCSIntegration::processCommit($project, $commit_msg, $old_rev, $previous, $time, "", $author, $branch);
$previous = $new_rev;
exit;
}
}
示例12: array
<?php
TBGContext::getResponse()->addHeader('Content-Disposition: attachment; filename="' . $searchtitle . '.csv"');
include_template('search/results_normal_csv', array('issues' => $issues));
示例13: loginCheck
/**
* Returns the logged in user, or default user if not logged in
*
* @param string $uname
* @param string $upwd
*
* @return TBGUser
*/
public static function loginCheck($username = null, $password = null)
{
try {
$row = null;
// 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');
$row = TBGUsersTable::getTable()->getByUsernameAndPassword($username, $password);
if (!$row) {
TBGContext::getResponse()->deleteCookie('tbg3_username');
TBGContext::getResponse()->deleteCookie('tbg3_password');
throw new Exception('No such login');
//TBGContext::getResponse()->headerRedirect(TBGContext::getRouting()->generate('login'));
}
}
}
// If we have authentication details, validate them
if (TBGSettings::getAuthenticationBackend() !== null && TBGSettings::getAuthenticationBackend() !== 'tbg' && $username !== null && $password !== null) {
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);
throw new Exception('Invalid module type');
}
if (TBGContext::getRequest()->hasCookie('tbg3_username') && TBGContext::getRequest()->hasCookie('tbg3_password')) {
$row = $mod->verifyLogin($username, $password);
} else {
$row = $mod->doLogin($username, $password);
}
if (!$row) {
// Invalid
TBGContext::getResponse()->deleteCookie('tbg3_username');
TBGContext::getResponse()->deleteCookie('tbg3_password');
throw new Exception('No such login');
//TBGContext::getResponse()->headerRedirect(TBGContext::getRouting()->generate('login'));
}
} catch (Exception $e) {
throw $e;
}
} elseif ($username !== null && $password !== null) {
TBGLogging::log('Using internal authentication', 'auth', TBGLogging::LEVEL_INFO);
// First test a pre-encrypted password
$row = TBGUsersTable::getTable()->getByUsernameAndPassword($username, $password);
if (!$row) {
// Then test an unencrypted password
$row = TBGUsersTable::getTable()->getByUsernameAndPassword($username, self::hashPassword($password));
if (!$row) {
// This is a legacy account from a 2.1 upgrade - try md5
$row = TBGUsersTable::getTable()->getByUsernameAndPassword($username, md5($password));
if (!$row) {
// Invalid
TBGContext::getResponse()->deleteCookie('tbg3_username');
TBGContext::getResponse()->deleteCookie('tbg3_password');
throw new Exception('No such login');
//TBGContext::getResponse()->headerRedirect(TBGContext::getRouting()->generate('login'));
} else {
// convert md5 to new password type
$user = new TBGUser($row->get(TBGUsersTable::ID), $row);
$user->changePassword($password);
$user->save();
unset($user);
}
}
}
} elseif (TBGContext::isCLI()) {
$row = TBGUsersTable::getTable()->getByUsername(TBGContext::getCurrentCLIusername());
} elseif (!TBGSettings::isLoginRequired()) {
$row = TBGUsersTable::getTable()->getByUserID(TBGSettings::getDefaultUserID());
}
if ($row) {
if (!$row->get(TBGScopesTable::ENABLED)) {
throw new Exception('This account belongs to a scope that is not active');
} elseif (!$row->get(TBGUsersTable::ACTIVATED)) {
throw new Exception('This account has not been activated yet');
} elseif (!$row->get(TBGUsersTable::ENABLED)) {
throw new Exception('This account has been suspended');
}
$user = TBGContext::factory()->TBGUser($row->get(TBGUsersTable::ID), $row);
} elseif (TBGSettings::isLoginRequired()) {
throw new Exception('Login required');
} else {
throw new Exception('No such login');
}
} catch (Exception $e) {
throw $e;
}
return $user;
}
示例14: doLogin
//.........这里部分代码省略.........
}
if ($allowed == false) {
throw new Exception(TBGContext::getI18n()->__('You are not a member of a group allowed to log in'));
}
}
/*
* 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[0])) {
$realname = $username;
} else {
$realname = $data[0][strtolower($fullname_attr)][0];
}
if (!array_key_exists(strtolower($buddyname_attr), $data[0])) {
$buddyname = $username;
} else {
$buddyname = $data[0][strtolower($buddyname_attr)][0];
}
if (!array_key_exists(strtolower($email_attr), $data[0])) {
$email = '';
} else {
$email = $data[0][strtolower($email_attr)][0];
}
/*
* If we are performing a non integrated authentication login,
* now bind to the user and see if the credentials
* are valid. We bind using the full DN of the user, so no need for DOMAIN\ stuff
* on Windows, and more importantly it fixes other servers.
*
* If the bind fails (exception), we throw a nicer exception and don't continue.
*/
if ($mode == 1 && !$integrated_auth) {
try {
if (!is_array($data[0][strtolower($dn_attr)])) {
$dn = $data[0][strtolower($dn_attr)];
} else {
$dn = $data[0][strtolower($dn_attr)][0];
}
$bind = $this->bind($connection, $this->escape($dn), $password);
} catch (Exception $e) {
throw new Exception(TBGContext::geti18n()->__('Your password was not accepted by the server'));
}
} elseif ($mode == 1) {
if (!isset($_SERVER[$this->getSetting('integrated_auth_header')]) || $_SERVER[$this->getSetting('integrated_auth_header')] != $username) {
throw new Exception(TBGContext::geti18n()->__('HTTP authentication internal error.'));
}
}
} catch (Exception $e) {
ldap_unbind($connection);
throw $e;
}
try {
/*
* Get the user object. If the user exists, update the user's
* data from the directory.
*/
$user = TBGUser::getByUsername($username);
if ($user instanceof TBGUser) {
$user->setBuddyname($buddyname);
$user->setRealname($realname);
$user->setPassword($user->getJoinedDate() . $username);
// update password
$user->setEmail($email);
// update email address
$user->save();
} else {
/*
* If not, and we are performing an initial login, create the user object
* if we are validating a log in, kick the user out as the session is invalid.
*/
if ($mode == 1) {
// create user
$user = new TBGUser();
$user->setUsername($username);
$user->setRealname('temporary');
$user->setBuddyname($username);
$user->setEmail('temporary');
$user->setEnabled();
$user->setActivated();
$user->setJoined();
$user->setPassword($user->getJoinedDate() . $username);
$user->save();
} else {
throw new Exception('User does not exist in TBG');
}
}
} catch (Exception $e) {
ldap_unbind($connection);
throw $e;
}
ldap_unbind($connection);
/*
* Set cookies and return user row for general operations.
*/
TBGContext::getResponse()->setCookie('tbg3_username', $username);
TBGContext::getResponse()->setCookie('tbg3_password', TBGUser::hashPassword($user->getJoinedDate() . $username, $user->getSalt()));
return TBGUsersTable::getTable()->getByUsername($username);
}
示例15:
<?php
/**
* Configuration for theme
*/
TBGContext::getResponse()->addStylesheet('firehouse.css');