Monday, September 8, 2008

phpBB3 user database integration

One of my tasks this week was to hook up an already installed and configured phpBB to a site with it's own user database.

Fearing the worst from my previous phpBB2 experiences, I was pleasantly suprised to see that phpBB has an actual exposed API for this! :)

The "integration" still consists of mirroring user informaiton from your primary database into the phpBB database, but at least it's straightforward. In this case, I just wrapped the existing create_user() call with a new function to write to both systems:

function create_SITENAME_user($username, $password, $email, $initialthing) {
$group_id=2; // 'REGISTERED'
$user_style=5; // what all the regular users use
// get some functions from phpBB3
define('IN_PHPBB', true);
$phpbb_root_path = '../forum/'; // change this to phpBB3 dir
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);


$user_record = array(
'username' => $username,
'user_password' => phpbb_hash($password),
'user_email' => $email,
'group_id' => $group_id,
'user_timezone' => 0,
'user_dst' => 1,
'user_lang' => 'en',
'user_type' => 0,
'user_actkey' => '',
'user_dateformat' => 'D M d, Y g:i a',
'user_style' => $user_style,
'user_regdate' => time(),
);

$phpbb_user_id = user_add($user_record); // add the user to the phpBB system

// need to figure out a way to handle phpBB errors...

// Now call the main API
$r=create_user($username, $password, $email, $initialthing)()
return $r;
}

I'll create some housekeeping functions to keep things in sync later.

The pertinent functions are:

user_get_id_name() // converts userIDs to usernames and visa-versa
void user_get_id_name (array &$user_id_ary, array &$username_ary, [mixed $user_type = false])

* array &$user_id_ary: The user ids to check or empty if usernames used
* array &$username_ary: The usernames to check or empty if user ids used
* mixed $user_type: Array of user types to check, false if not restricting by user type

and


user_delete () //Remove User
void user_delete ( $mode, $user_id, [ $post_username = false])

* $mode
* $user_id
* $post_username
where mode = 'remove' in all the examples I've seen




Technorati Tags: , , ,

No comments:

Post a Comment

Please leave your comment here.