Hello,
I'm running a drupal 5.x installation with phpbb module in order to achive an integration between the forum and drupal.
My problem is that i change the default home page (node) with something else, after the login drupal redirct the user to the forum profile page instead of the home page that i setted. If i leave "node" everything is fine.
I talked with the developer and we think that the problem is drupal-related and not module-related. The module implements the hook_user function.
It seems that if the home page is different, after the "login" option is executed the "view profile" option of the hook_user.
here's the module code.
<?php
/**
* http://drupal.org/project/phpbb
* Copyright 2007, Arne Kepp 2007
* This work is licensed under the GNU GPL, see LICENSE.txt
*
* Many thanks to (Drupal.org users): Jimbo, brdwo, sfurman, maartenvg
*/
// This file contains the configuration for the link.
require_once('configuration.inc');
/**
* Implementation of hook_user
*/
function phpbb_user($op, &$edit, &$user, $category = NULL) {
global $phpbbcfg;
switch ($op) {
case 'insert':
// Inserts a new user into the phpBB database
//Check that there is no collision
if(_phpbb_knows_user($edit['uid'])) {
watchdog('phpBB', 'Attempt to insert user with id '.$edit['uid'].', but this user already exists in the phpBB database. Aborted, but you now have incosistent databases!',WATCHDOG_ERROR);
die('There is a problem with the system. Ask the administrator to check the watchdog log.');
}
// Get the board timezone
$query = "SELECT * FROM {$phpbbcfg['db_config']} WHERE `config_name` = 'board_timezone'";
$res = db_query($query) or die('Query failed: ' . db_error() . " \n" . $query . "\n");
$row = db_fetch_array($res);
$timezone = $row['config_value'];
// Get the default language
$query = "SELECT * FROM {$phpbbcfg['db_config']} WHERE `config_name` = 'default_lang'";
$res = db_query($query) or die('Query failed: ' . db_error() . " \n" . $query . "\n");
$row = db_fetch_array($res);
$language = $row['config_value'];
// Get the group for registered users
$query = "SELECT * FROM {$phpbbcfg['db_groups']} WHERE `group_name` = 'REGISTERED'";
$res = db_query($query) or die('Query failed: ' . db_error() . " \n" . $query . "\n");
$row = db_fetch_array($res);
$gid = $row['group_id'];
// The stuff below is all to get hold of utf8_clean_string()
global $phpbb_root_path, $phpEx;
$phpbb_root_path = $phpbbcfg['path_rel'];
$phpEx = 'php';
@define('IN_PHPBB', true);
$utf_tool_path = $phpbbcfg['path_rel'] . 'includes/utf/';
require_once($utf_tool_path . 'utf_normalizer.php');
require_once($utf_tool_path . 'utf_tools.php');
// Insert a minimal user.
$query = "INSERT INTO {$phpbbcfg['db_users']} "
."(`user_id`,`group_id`,`username`,`username_clean`,`user_password`,"
."`user_regdate`,`user_email`,`user_options`,`user_lang`,`user_timezone`) "
." VALUES({$edit['uid']},$gid,'{$edit['name']}','".utf8_clean_string($edit['name'])."','"
.md5($edit['pass']) ."',". time() .",'{$edit['mail']}','853','$language',$timezone)";
$res = db_query($query) or die('Query failed: ' . db_error() . " \n" . $query . "\n");
// Insert the user into the group_name = REGISTERED group
$query = "INSERT INTO {$phpbbcfg['db_user_group']} "
."(`group_id`,`user_id`,`group_leader`,`user_pending`)"
." VALUES( $gid, {$edit['uid']}, 0, 0)";
$res = db_query($query) or die('Query failed: ' . db_error() . " \n" . $query . "\n");
// Update newest user on the front of the forum
$query = "UPDATE {$phpbbcfg['db_config']} SET `config_value` = {$edit['uid']} WHERE `config_name` = 'newest_user_id'";
$res = db_query($query) or die('Query failed: ' . db_error() . " \n" . $query . "\n");
$query = "UPDATE {$phpbbcfg['db_config']} SET `config_value` = '{$edit['name']}' WHERE `config_name` = 'newest_username'";
$res = db_query($query) or die('Query failed: ' . db_error() . " \n" . $query . "\n");
// Increment total number of users
$query = "UPDATE {$phpbbcfg['db_config']} SET config_value = config_value + 1 WHERE `config_name` = 'num_users'";
$res = db_query($query) or die('Query failed: ' . db_error() . " \n" . $query . "\n");
break;
case 'form':
// Catches password resets, including the first one after registering.
if(! user_access('edit drupal users') ) {
if( strpos($_SERVER['HTTP_REFERER'], 'user/reset')) {
drupal_goto('phpbb/passwdreset');
} else {
header('Location: '.$phpbbcfg['path_abs'].'memberlist.php?mode=viewprofile&u='.$user->uid, TRUE, 301);
}
exit();
}
break;
case 'update':
// Unless the user has access to editing Drupal users, we redirect to the phpBB module
if(! user_access('edit drupal users') ) {
header('Location: '.$phpbbcfg['path_abs'].'memberlist.php?mode=viewprofile&u='.$user->uid, TRUE, 301);
exit();
}
break;
case 'delete':
// Code for deleting user from phpBB has been removed, difficult to mimic functionality of phpBB in Drupal
_phpbb_session_destroy();
break;
case 'login':
// If this is Drupals main admin we dont set cookies
if($edit['uid'] == 1 || $user->uid == 1) {
drupal_set_message('(The superuser is never logged into phpBB)', 'status');
return;
}
// Creates the cookies and session in phpBBs database
$phpbb_username = _phpbb_knows_user($user->uid);
// Check whether this user is known in phpBB
if(! $phpbb_username) {
watchdog('phpBB', 'Inserting previously unknown user '.$edit['uid'],WATCHDOG_NOTICE);
$new_edit = array();
$new_edit['uid'] = $user->uid;
$new_edit['mail'] = $user->mail;
$new_edit['name'] = $user->name;
phpbb_user('insert',$new_edit,$user);
// Check whether this user is in sync with phpBB
} else if($phpbb_username && $phpbb_username != $user->name) {
watchdog('phpBB', 'User with id '.$user->uid.' is '.$user->name.', but '.$phpbb_username.' in phpBB. Stopping login attempt.',WATCHDOG_ERROR);
drupal_set_message('There is a problem with the system. Ask the administrator to check the watchdog log.', 'status');
return;
}
// Everything ok, actually create the session
$session_key = _phpbb_random()._phpbb_random();
$session_key = substr($session_key,0,32); // Just in case
$phpbb_cookie_name = _phpbb_cookie_name();
_phpbb_insert_db_session($session_key);
// Fetch session_id and session_key here, so we can delete the correct sessions?
_phpbb_set_cookies($phpbb_cookie_name, $session_key);
// Don't worry about the lines below. $phpbbcfg['i1'] should be set to false.
if($phpbbcfg['i1']) {
$query = "SELECT user_primary_forum FROM {$phpbbcfg['db_users']} WHERE user_id = ".$user->uid;
$res = db_query($query) or die('Query failed: ' . db_error() . " \n" . $query . "\n");
$row = db_fetch_array($res);
if(! $row['user_primary_forum'] || $row['user_primary_forum'] == "") {
require_once('forum/includes/functions_i1.php');
$query = "UPDATE {$phpbbcfg['db_users']} SET user_primary_forum = '" .$short_conv[$_SERVER['SERVER_NAME']] . "'"
." WHERE `user_id` = ".$user->uid;
$res = db_query($query) or die('Query failed: ' . db_error() . " \n" . $query . "\n");
}
}
break;
case 'logout':
// Destroys the sessions in phpBBs database and unsets the cookies.
_phpbb_session_destroy();
break;
case 'view':
// Code removed, use phpBB's profile instead
if(! user_access('edit drupal users') ) {
header('Location: '.$phpbbcfg['path_abs'].'memberlist.php?mode=viewprofile&u='.$user->uid, TRUE, 301);
exit();
}
break;
}
return $output;
}
CUT
?>
Here's the group discussion and what we did: http://groups.drupal.org/node/6710.
bye!