-
Notifications
You must be signed in to change notification settings - Fork 0
Vb auth
Authentication library for CodeIgnited vBulletin extensions
Inspired by Pat Andrew's vBuser_-_vBulletin_based_Auth_Library package
Author: [url=http://codeigniter.com/forums/member/155463/]MiklosK[/url]
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
Recognizes valid vBulletin session cookies and picks up their corresponding user data from vBulletin's user table.
Recognizes valid vBulletin permanent cookies ('remember me') and creates a valid session for the corresponding user.
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
[url=http://github.com/MiklosK/Vb_auth]Vb_auth on github[/url]
Drop the project files to their respective folders in your CI project
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/';
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";
[b]Important![/b] Make sure that you reconfigure your default database [b]not to use persistent database connection[/b] otherwise CI will not be able to handle this dual DB solution.
Optional, but recommended to autoload vb_auth in your config/autoload.php like this:
$autoload['libraries'] = array('database','vb_auth');
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
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');
}
<?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);
}
?>