Not logged in. · Lost password · Register
Forum: General Discussion Installation and Configuration RSS
Dokuwiki and MyBB
spyto #1
Member since Jul 2007 · 2 posts
Group memberships: Members
Show profile · Link to this post
Subject: Dokuwiki and MyBB
Hello,

First, excuse my poor english.

Does anyone has written a Dokuwiki authentication Backend class working with MyBB forums ?
Or do you know a link to any info about this ?

Below, the code that I wrote but I don't succeeded !
Can anyone help me ?

The errors:
1 - It's necessary to repeat the login twice !? Why?
2 - After logging, Dokuwiki doesn't display correctly. There are no "Connect" and/or "Disconnect" links or buttons !
I'm using monobook template: the left-side menu don't show and there are errors in displaying tabs...
3 - I don't know how to manage groups (admin is not recognized...)
Note: In MyBB the "users" table contains a numeric field 'gid' reflecting the group user id stored in the "usergroups" table in witch the field "title" contains the corresponding group name with the 'gid'.

Does anyone has worked with MyBB integrration ?
Thanks for your help.

my inc/local.php: 

$conf['title'] = 'Mon Wiki';
$conf['lang'] = 'fr';
$conf['template'] = 'monobook';
$conf['dformat'] = 'd/m/Y H:i';
$conf['useacl'] = 1;
$conf['authtype'] = 'mybb';
$conf['superuser'] = '@admin';
$conf['htmlok'] = 1;
$conf['phpok'] = 1;
$conf['tpl']['monobook']['mb_bc_loc'] = 'top';
$conf['tpl']['monobook']['mb_hbc_loc'] = 'top';

----------------------------
and my dokuwiki/inc/auth/mybb.class.php file 
(based on auth_basic)                      
<?php
/**
 * MyBB auth backend
 *
 * Uses external Trust mechanism to check against MyBB's
 * user cookie.
 *
 */

// necessary to access MyBB vars & functions
define("IN_MYBB", 1);
// get (and save) current dir
$cwd = getcwd();

// change dir to MyBB forum to init vars & functions
// modify below to point to MyBB forum folder:
chdir('../MyBB'); // path to MyBB

// required MyBB includes
require_once 'global.php';
require_once 'inc/config.php';
require_once "inc/functions_user.php";

// back to to current dir
chdir($cwd);

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

#dbg($GLOBALS);
#dbg($mybb->user);

class auth_mybb extends auth_basic {

  /**
   * Constructor.
   *
   * Sets additional capabilities and config strings
   */
  function auth_mybb(){
   
    // to use trustExternal and Logoff
    $this->cando['external'] = true;
    $this->cando['logoff']   = true;
   
  }

  /**
   * Just checks against the $mybb->user variable
   */
  function trustExternal($user,$pass,$sticky=false){
    global $USERINFO, $conf; // docuwiki
    global $mybb, $db, $config; // MyBB

    $sticky ? $sticky = true : $sticky = false; //sanity check

          // someone used the login form
          if(!empty($user)){
                // use of MyBB internal function to validate password
          $user = validate_password_from_username($user,$pass);
        if(!$user['uid']){
               //invalid credentials - log off
               auth_logoff();
               return false;
               }
        // password is OK, setting cookie...
        my_setcookie('loginattempts', 1);
          $db->delete_query(TABLE_PREFIX."sessions", "ip='".$db->escape_string($session->ipaddress)."' AND sid != '".$session->sid."'");
          $newsession = array(
                "uid" => $user['uid'],
                  "loginattempts" => 1,
                  );
          $db->update_query(TABLE_PREFIX."sessions", $newsession, "sid='".$session->sid."'");
          // Temporarily set the cookie remember option for the login cookies
          $mybb->user['remember'] = $user['remember'];
          my_setcookie("mybbuser", $user['uid']."_".$user['loginkey'], null, true);
          my_setcookie("sid", $session->sid, -1, true);
          }

          if(isset($mybb->user['uid'])){
            // okay we're logged in - set the globals
          $USERINFO['pass'] = $mybb->user['password'];
          $USERINFO['name'] = $mybb->user['username'];
          $USERINFO['mail'] = $mybb->user['email'];
          $USERINFO['grps'] = array('@user', '@admin'); // here I don't know how... (just for testing)
         
          $_SERVER['REMOTE_USER'] = $mybb->user['username'];
          $_SESSION[DOKU_COOKIE]['auth']['user'] = $mybb->user['username'];
          $_SESSION[DOKU_COOKIE]['auth']['info'] = $USERINFO;
          return true;
          }
    // to be sure
    auth_logoff();
    return false;
}

  /**
   * remove cookie on logout
   */
  function logOff(){
    global $mybb;
    my_unsetcookie("mybbuser");
    my_unsetcookie("sid");
  }
}
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, 1.6.4, © 2003-7 by Yves Goergen
Current time: 2009-07-03, 02:36:35 (UTC +02:00)
WikiForumIRCBugsDarcsXRefTranslate