Not logged in. · Lost password · Register
Forum: General Help and Support Plugins RSS
DokuMyBB
integrate MyBB user table in DokuWiki
Avatar
flash.tato #1
Member since Oct 2007 · 7 posts
Group memberships: Members
Show profile · Link to this post
Subject: DokuMyBB
Hi,

this is an auth backend for bridging MyBB's user table in DokuWiki :-), all instructions are available in the readme file.

Also the usergroup conversion is highly customisable infact you have to edit only this line:
var $rules = array("4" => array("admin", "user"), "default" => array("user"));

The function mybb_2_dw_usergroups will handle the conversion in according with data present in it.

ToDo
- Share sessions
The author has attached one file to this post:
DokuMyBB.zip 27.7 kBytes
You have no permission to open this file.
Avatar
chuyskywalker #2
Member since Nov 2008 · 1 post
Group memberships: Members
Show profile · Link to this post
This script made some assumptions that were incorrect:

1) The script assumes that column values come out in the same order always when selecting on *. This is not always so.
2) The script only gives out doku permissions for the mybb user's primary group -- however, mybb users can be part of multiple groups.

I have fixed both issues.

I didn't do a very thorough fix though, you could further clean up the SQL queries to be ultra specific, but I wasn't bothered by that for now.

<?php
/**
 * MyBB auth backend
 *
 * Bridges user login with MyBB database.
 *
 */
 
define('TABLE_PREFIX', '');
define('DB_HOST', 'localhost');
define('DB_USER', '');
define('DB_PWD', '');
define('DB_NAME', '');

define('DOKU_AUTH', dirname(__FILE__));
require_once(DOKU_AUTH.'/basic.class.php');

class auth_mybb extends auth_basic
{
    //Link to database's resource connection
    var $link;
   
    //Usergroup conversion rules
    var $rules = array(
        "4" => array("admin", "user"),
        "default" => array("user")
    );
   
    //The constructor
    function auth_mybb()
    {
        $this->link = mysql_connect(DB_HOST, DB_USER, DB_PWD) or die('Connection to MySQL Server failed');
        mysql_select_db(DB_NAME, $this->link) or die('Select Database failed');
        $this->success = true;
    }
   
    //Check if an user exists and if a password is exact [OVERRIDEN]
    function checkPass($user, $pass)
    {
        $q = mysql_query("SELECT * FROM ".TABLE_PREFIX."users WHERE username='$user' LIMIT 0,1", $this->link);
        $r = mysql_fetch_assoc($q);
        if($r['password'] == $this->mybb_psw($pass, $r['salt'])) return true;
        return false;
    }
   
    //Generate MyBB's Password Hash
    function mybb_psw($password, $salt)
    {
        $password = md5($password);
        return md5(md5($salt).$password);
    }
   
    //Get user data [OVERRIDEN]
    function getUserData($user)
    {
        $q = mysql_query("SELECT * FROM ".TABLE_PREFIX."users WHERE username='$user' LIMIT 0,1", $this->link);
        $r = mysql_fetch_assoc($q);
        $retn = array('name' => $r['username'], 'mail' => $r['email'], 'grps' => $this->mybb_2_dw_usergroups($r['usergroup'],$r['additionalgroups']));
        return $retn;
    }
   
    //Function for converting mybb usergroups to DokuWiki usergroups
    function mybb_2_dw_usergroups($usergroup, $additional_groups)
    {
        // a user could have multiple groups which could end up mappig to multiple doku permission sets
        if( ! empty($additional_groups) )
        {
            $groups = explode(',', $usergroup .','. $additional_groups);
        }
        else
        {
            $groups = array($usergroup);
        }       
        $doku_groups = array();
        foreach( $groups as $mybb_group_id )
        {
            if(isset($this->rules[$mybb_group_id]))
            {
                foreach($this->rules[$mybb_group_id] as $target_group)
                {
                    $doku_groups[] = $target_group;
                }
            }
        }       
        // return the unique set of groups or the default values
        if(count($doku_groups))
        {
            return array_unique($doku_groups);
        }
        else
        {
            return $this->rules["default"];
        }       
    }
}

?>
Close Smaller – Larger + Reply to this post:
Verification code: VeriCode Please note the verification code from the picture into the text field next to it.
Smileys: :-) ;-) :-D :-p :blush: :cool: :rolleyes: :huh: :-/ <_< :-( :'( :#: :scared: 8-( :nuts: :-O
Special characters:
Go to forum
Imprint
This board is powered by the Unclassified NewsBoard software, 20090606-dev, © 2003-8 by Yves Goergen
Current time: 2010-03-22, 11:55:02 (UTC +01:00)
WikiForumIRCBugsGitXRefTranslate