Topic: Viability of my integration

Hi,

currently my test PunBB forum has no login integration with the rest of my custom site. I added my site's header to it for visual integration. That might be the easiest way to keep it.

However, what's the viability in my customising PunBB as follow?

My site currently requires an email address to log in rather than a username, and there are non-unique display names.

What do you think is the viability for me to change PunBB to this degree:

* To modify PunBB to have a display name field. Use that display name beside people's posts, along with a gravatar identicon as their avatar.
* To automatically register a user in PunBB when they register under my site. Their forum username is actually their email.
* Integrate logins so that if a user is logged into my main site, they are also logged in to PunBB.
* Hide PunBB's login pages and get them to log in directly through my site.

Even if I managed to implement that, there would be difficulty in keeping PunBB up to date with official releases if the inner code was modified.

Thanks for opinions.

Re: Viability of my integration

nice how you do it?

Re: Viability of my integration

Well, I haven't done it smile

I was wondering if people more familiar with PunBB thought such an integration would be viable?

Re: Viability of my integration

Some thoughts:

  • Registration, I think, should be available only on the main site as a login form.

  • For common authorization and correspondence between a forum profile and a profile on your site, you can add the "external_id" (or something like that) column to the forum users table. It will be list the id of a user on the main site.

  • The user authentication happens in the "cookie_login" function in the "<FORUM_ROOT>/include/functions.php" file. Add the code you used on the main site to this function and init the $forum_user variable.

  • When a user visits forum for first time, add him to the forum users table.

  • Add redirection from the login/logout/registrations page to corresponding pages on your main stie.

  • You can implement the integration extension-wise, this will solve the problem of forum updating.

Re: Viability of my integration

Great, it sounds like I have some research to do during the weekend then smile

6 (edited by eoinoc333 2010-02-14 16:30)

Re: Viability of my integration

I'm very happy to report back that my simple (not complete) integration hook is working. It uses my own custom script to check if the user is logged in. If they are logged in through my site, I authenticate them directly.

<hook id="fn_cookie_login_start"><![CDATA[
    require_once($_SERVER['DOCUMENT_ROOT'].'/scripts/smarty.php');
    global $forum_config;
    if ($smarty->user->isLoggedIn()) // My login check.
    {
        global $forum_db, $forum_user;
        
        $query = array(
            'SELECT'    => 'u.*, g.*, o.logged, o.idle, o.csrf_token, o.prev_url',
            'FROM'        => 'users AS u',
            'JOINS'        => array(
                array(
                    'INNER JOIN'    => 'groups AS g',
                    'ON'            => 'g.g_id=u.group_id'
                ),
                array(
                    'LEFT JOIN'        => 'online AS o',
                    'ON'            => 'o.user_id=u.id'
                )
            )
        );

        // Get the user. I have their foreign_id which is their ID in
        // my main site. In the forum users database table, I have stored their site ID as foreign_id.
        $query['WHERE'] = 'u.foreign_id='.$forum_db->escape($smarty->user->getUserID());

        $result = $forum_db->query_build($query) or error(__FILE__, __LINE__);
        $forum_user = $forum_db->fetch_assoc($result);
        
        // Send a new, updated cookie with a new expiration timestamp
        $expire = (intval($cookie['expiration_time']) > $now + $forum_config['o_timeout_visit']) ? $now + 1209600 : $now + $forum_config['o_timeout_visit'];
        forum_setcookie($cookie_name, base64_encode($forum_user['id'].'|'.$forum_user['password'].'|'.$expire.'|'.sha1($forum_user['salt'].$forum_user['password'].forum_hash($expire, $forum_user['salt']))), $expire);

        $forum_user['is_guest'] = false;
        $forum_user['is_admmod'] = $forum_user['g_id'] == FORUM_ADMIN || $forum_user['g_moderator'] == '1';
    
        // From functions.php
        // Set a default language if the user selected language no longer exists
        if (!file_exists(FORUM_ROOT.'lang/'.$forum_user['language'].'/common.php'))
            $forum_user['language'] = $forum_config['o_default_lang'];

        // Set a default style if the user selected style no longer exists
        if (!file_exists(FORUM_ROOT.'style/'.$forum_user['style'].'/'.$forum_user['style'].'.php'))
            $forum_user['style'] = $forum_config['o_default_style'];

        if (!$forum_user['disp_topics'])
            $forum_user['disp_topics'] = $forum_config['o_disp_topics_default'];
        if (!$forum_user['disp_posts'])
            $forum_user['disp_posts'] = $forum_config['o_disp_posts_default'];

        // Check user has a valid date and time format
        if (!isset($forum_time_formats[$forum_user['time_format']]))
            $forum_user['time_format'] = 0;
        if (!isset($forum_date_formats[$forum_user['date_format']]))
            $forum_user['date_format'] = 0;
    }
    else
    {
        set_default_user();
    }
    return true;

    // TODOs
    // * If password, email, display name changed on my site then must update forum.
    // * If logout from forum, logout from main page: http://punbb.informer.com/forums/post/114252/#p114252
    // * Not sure about cookie expiration matching my site and the forum account.
]]></hook>