Cookbook/Support Center logins using vBulletin accounts

From Cerberus Helpdesk Wiki

Jump to: navigation, search
Cookbook Guides


Contents

[edit] Support Center logins using vBulletin accounts

In this Cookbook recipe we'll create a new extension to allow customers to log in to the Support Center using their vBulletin forum account. This is useful if you want to provide a single sign on (SSO) to your customers for the various resources you provide.

[edit] Create the plugin directory

First, we need to create a new plugin for our usermeet.login.authenticator extension. It's a good practice to have a single plugin for your company's extensions that implement custom business logic and workflow; but this example will create a new plugin for clarity. If you know what you're doing, feel free to add the required manifests and source code to an existing plugin instead.

  • Create the plugins/example.bizlogic directory.
  • Inside the new directory, create a templates subdirectory and two files: plugin.php and plugin.xml
    The directory structure for our new plugin.
    The directory structure for our new plugin.

[edit] Create the plugin manifest

plugin.xml:

<!DOCTYPE plugin SYSTEM "../../libs/devblocks/plugin.dtd">
<plugin>
	<id>example.bizlogic</id>
	<name>[Example] Custom Biz Logic</name>
	<description>The workflow for Example, Inc.</description>
	<author>You</author>
	<revision>1</revision>
	<link>http://www.cerb4.com/</link>
 
	<extensions>
 
		<!-- Login Authenticator -->
 
		<extension point="usermeet.login.authenticator">
			<id>example.sc.login.vbulletin</id>
			<name>vBulletin Login Handler</name>
			<class>
				<file>plugin.php</file>
				<name>ExampleVbulletinLoginAuthenticator</name>
			</class>
			<params/>
		</extension>
 
    </extensions> 
</plugin>

[edit] Create the plugin implementation

plugin.php:

<?php
class ExampleVbulletinLoginAuthenticator extends Extension_ScLoginAuthenticator {
	function __construct($manifest) {
		$this->DevblocksExtension($manifest, 1);
	}
 
	/**
	 * draws HTML form of controls needed for login information
	 */
	function renderLoginForm() {
		$tpl = DevblocksPlatform::getTemplateService();
		$path = dirname(__FILE__) . '/templates/';
 
		$tpl->display($path . 'sc/vbulletin/login.tpl');
	}
 
	/**
	 * pull auth info out of $_POST, check it, return user_id or false
	 * 
	 * @return boolean whether login succeeded
	 */
	function authenticate() {
		$umsession = UmPortalHelper::getSession();
 
		@$forum_login = DevblocksPlatform::importGPC($_REQUEST['forum_login']);
		@$forum_pass = DevblocksPlatform::importGPC($_REQUEST['forum_pass']);
		$valid = false;
 
		if($db = mysql_connect('localhost','root','')) {
			mysql_select_db('cerb4_forums', $db);
 
			$sql = sprintf("SELECT email FROM user WHERE username='%s' AND password=MD5(CONCAT(MD5('%s'),salt));",
				mysql_real_escape_string($forum_login),
				mysql_real_escape_string($forum_pass)
			);
 
			$res = mysql_query($sql, $db);
			if(mysql_num_rows($res)) {
				$row = mysql_fetch_assoc($res);
				if(isset($row['email']) && !empty($row['email'])) {
					if(null != ($addy = DAO_Address::lookupAddress($row['email'], true))) {
						$valid = true;
						$umsession->setProperty('sc_login',$addy);
					}
				}
			}
		}
 
		if($valid)
			return true;
 
		$umsession->setProperty('sc_login',null);
		return false;
	}
};
* Notes: You need to customize the mysql_connect() and mysql_select_db() calls inside authenticate() to use the appropriate database information for your vBulletin installation. If the vBulletin database is hosted on a different machine than your helpdesk then you may need to create a remote database user.

[edit] Create the login form template

templates/sc/vbulletin/login.tpl:

<table cellpadding="0" cellspacing="0" border="0" class="sidebar">
	<tr>
		<th width="100%" colspan="2">{$translate->_('portal.sc.public.themes.log_in')}</th>
	</tr>
	<tr>
		<td width="100%">
			Forum Login:<br>
			<input type="text" name="forum_login" style="width:98%;border:1px solid rgb(153,153,153);">
		</td>
	</tr>
	<tr>
		<td width="100%">
			{$translate->_('common.password')|capitalize}:<br>
			<input type="password" name="forum_pass" style="width:98%;border:1px solid rgb(153,153,153);">
		</td>
	</tr>
	<tr>
		<td width="100%" colspan="2"><button type="submit">{$translate->_('portal.sc.public.themes.click_to_log_in')}</button></td>
	</tr>
</table>

[edit] Activate the plugin

  • Log in to your helpdesk as an administrator.
  • In Helpdesk Setup->Plugins & Features, check the box next to your new plugin and click the Save Changes button at the bottom of the page.

[edit] Configure your Support Center

  • In Helpdesk Setup->Community Portals, select the desired Support Center portal from the left menu.
  • Under the Authenticate Logins: setting, change the dropdown to vBulletin Login Handler and click the Save Changes button at the bottom of the form.

[edit] Finishing up

  • Visit the appropriate Support Center in your web browser. The login form should now be asking for a forum login and password rather than e-mail address.


Cookbook Guides
Personal tools