Skip to content
World Wide Web Server edited this page Jul 4, 2012 · 6 revisions

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]

[h3]Introduction[/h3]

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:

[code] 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 [/code]

[h3]Features[/h3] [h4]Session cookie authorization[/h4] Recognizes valid vBulletin session cookies and picks up their corresponding user data from vBulletin's user table. [h4]Permanent cookie authorization[/h4] Recognizes valid vBulletin permanent cookies ('remember me') and creates a valid session for the corresponding user. [h4]Session info push[/h4] 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

[h3]Download source:[/h3]

[url=http://github.com/MiklosK/Vb_auth]Vb_auth on github[/url]

[h3]Installation:[/h3]

[h4]Step 1.[/h4] Drop the project files to their respective folders in your CI project

[h4]Step 2.[/h4] Edit your config/vb_auth.php by adding the proper vBulletin license info and the location of your installed vBulletin forum: [code] $config['vb_auth']['vblicense'] = 'YOUR VB LINCESE KEY'; $config['vb_auth']['forum_url'] = 'http://example.com/forums/'; [/code]

[h4]Step 3.[/h4] Edit your config/database.php by adding a secondary database definition like this: [code] $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"; [/code]

[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.

[h4]Step 4.[/h4] Optional, but recommended to autoload vb_auth in your config/autoload.php like this: [code] $autoload['libraries'] = array('database','vb_auth'); [/code] [h3]How to use[/h3] 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

[h3]Examples[/h3] [h4]In a controller[/h4] [code] 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'); }
[/code] [h4]In a view[/h4] [code] <?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); } ?> [/code]

Category:Contributions::Libraries::Authentication

Clone this wiki locally