Authentication library for CodeIgnited vBulletin extensions
Inspired by Pat Andrew’s vBuser - vBulletin based Auth Library package
Author: MiklosK
Introduction
Vb_auth library is useful to create, maintain or utilize user sessions authenticated against pre-installed vBulletin installations in the same domain.
It can be used in situations like this:
http://example.com/ // domain root or your CodeIgniter Project
http://example.com/myci // optional place for your CodeIgniter project root
http://example.com/forums // your vBulletin installation
Features
Session cookie authorization
Recognizes valid vBulletin session cookies and picks up their corresponding user data from vBulletin’s user table.
Permanent cookie authorization
Recognizes valid vBulletin permanent cookies (‘remember me’) and creates a valid session for the corresponding user.
Session info push
In case of a logged in user, vb_auth sends user activity messages to vBulletin’s session table, allowing it to be visible in vB admin panel
Download source:
Installation:
Step 1.
Drop the project files to their respective folders in your CI project
Step 2.
Edit your config/vb_auth.php by adding the proper vBulletin license info and the location of your installed vBulletin forum:
$config['vb_auth']['vblicense'] = 'YOUR VB LINCESE KEY';
$config['vb_auth']['forum_url'] = 'http://example.com/forums/';
Step 3.
Edit your config/database.php by adding a secondary database definition like this:
$db['vbulletin']['hostname'] = "localhost";
$db['vbulletin']['username'] = "username";
$db['vbulletin']['password'] = "password";
$db['vbulletin']['database'] = "database";
$db['vbulletin']['dbdriver'] = "mysql";
$db['vbulletin']['dbprefix'] = "vb_";
$db['vbulletin']['pconnect'] = FALSE; // don't use persistent db connections
$db['vbulletin']['db_debug'] = TRUE;
$db['vbulletin']['cache_on'] = FALSE;
$db['vbulletin']['cachedir'] = "";
$db['vbulletin']['char_set'] = "utf8";
$db['vbulletin']['dbcollat'] = "utf8_general_ci";
Important! Make sure that you reconfigure your default database not to use persistent database connection otherwise CI will not be able to handle this dual DB solution.
Step 4.
Optional, but recommended to autoload vb_auth in your config/autoload.php like this:
$autoload['libraries'] = array('database','vb_auth');
How to use
Once you installed and properly configured vb_auth, you can simply use it anywhere in your application.
vb_auth->is_logged_in() returns true if a valid vB session is detected
vb_auth->info contains the data of the current user
vb_auth->is_admin() returns true if the current user is a vB admin
Examples
In a controller
if( $this->vb_auth->is_logged_in()){
$data['user']$this->vb_auth->username;
$this->load->view('logged_in_as',$data);
} else {
$this->load->view('not_logged_in');
}
In a view
<?php
$CI =& get_instance();
if ( ! $CI->vb_auth->is_logged_in()) {
$this->load->view('blocks/vb_login_box');
} else {
$data['username'] = $CI->vb_auth->info['username'];
$this->load->view('blocks/vb_logout_box',$data);
}
?>
Category:Contributions -> Libraries -> Authentication
