Jump to content

Action Hook - phpBB3 User Registration


FrostByte

Recommended Posts

Hello all!

 

I've searched the forums and found a few posts regarding the subject but no REAL answers or solutions.

 

I'm new to the system and the Wiki document on Hooks doesn't really explain exactly HOW to use the example code.

 

What i want:

An Action Hook that will insert the customer's details (email name password) into a seperate phpBB3 database on the same server.

 

I am not looking for a bridge, so to speak. I am not bothered with loginshare, i just want a user account created in phpBB3 when a customer signs up in WHMCS.

 

Any help would be greatly appreciated! Thanks alot :)

Link to comment
Share on other sites

Ok i've developed a hook of my own, it creates a user account in phpBB when a client signs up in WHMCS, but the password is incorrect.

 

Here's the code, could anybody help me out please??

 

<?php

/*

******************************************************

** Create phpBB3 account on registration **

******************************************************

*/

 

function create_forum_account($vars) {

 

$userid = $vars['userid'];

$user = getusername($userid);

$pass = getuserpass($userid);

$email = $vars['email'];

 

define('IN_PHPBB', true);

global $phpbb_root_path;

global $phpEx;

global $db;

global $config;

global $user;

global $auth;

global $cache;

global $template;

$phpEx = substr(strrchr(__FILE__, '.'), 1);

$phpbb_root_path = '/home/****/public_html/forums/';

include($phpbb_root_path."common_bridge.php");

$user->session_begin();

$auth->acl($user->data);

include$phpbb_root_path.("includes/functions_user.php");

$link = mysql_connect('localhost', '****', '****');

if (!$link) {

die('Not connected to forum: ' . mysql_error());

}

$db_selected = mysql_select_db('phpbb', $link);

if (!$db_selected) {

die ('Can\'t use forum db : ' . mysql_error());

} else {

$user_row = array(

'username' => $user,

'user_password' => md5($pass),

'user_email' => $email,

'group_id' => '2',

'user_timezone' => '1.00',

'user_dst' => 0,

'user_lang' => 'en',

'user_type' => '0',

'user_actkey' => '',

'user_style' => '1',

'user_dateformat' => 'd M Y H:i',

'user_regdate' => time(),

);

$phpbb_user_id = user_add($user_row);

}

 

}

 

function getusername($userid) {

 

$fieldid = "31";

$sqlcmd = "select value from tblcustomfieldsvalues where fieldid=$fieldid and relid=$userid";

$result = mysql_query($sqlcmd) or die("Mysql Error in getting Username :".mysql_error());

while ($row = mysql_fetch_object($result)) {

return $row->value;

}

 

}

 

function getuserpass($userid) {

 

$url = "http:/****/includes/api.php"; # URL to WHMCS API file

$username = "****"; # Admin username goes here

$password = "****"; # Admin password goes here

 

$postfields["username"] = $username;

$postfields["password"] = md5($password);

$postfields["action"] = "getclientpassword";

$postfields["userid"] = "1";

 

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $url);

curl_setopt($ch, CURLOPT_POST, 1);

curl_setopt($ch, CURLOPT_TIMEOUT, 100);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);

$data = curl_exec($ch);

curl_close($ch);

 

$data = explode(";",$data);

foreach ($data AS $temp) {

$temp = explode("=",$temp);

$results[$temp[0]] = $temp[1];

}

 

if ($results["password"] != $null) {

$url = "http:/****/includes/api.php"; # URL to WHMCS API file

$username = "****"; # Admin username goes here

$password = "****"; # Admin password goes here

 

$postfields["username"] = $username;

$postfields["password"] = md5($password);

$postfields["action"] = "decryptpassword";

$postfields["password2"] = $result['password'];

 

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $url);

curl_setopt($ch, CURLOPT_POST, 1);

curl_setopt($ch, CURLOPT_TIMEOUT, 100);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);

$data = curl_exec($ch);

curl_close($ch);

 

$data = explode(";",$data);

foreach ($data AS $temp) {

$temp = explode("=",$temp);

$results[$temp[0]] = $temp[1];

}

return $results['password'];

} else {

echo "The following error occured: ".$results["message"];

}

 

}

 

add_hook("ClientAdd",1,"create_forum_account");

 

?>

Link to comment
Share on other sites

Hey i just reviewed the documentation and the API call you are using to decrypt the users password doesn'tactually decrypt the clients password from whmcs. I'm guessing its used to decrypt the password stored for the server password, that your client would use to log-in to plesk or c-panel for example.

 

http://wiki.whmcs.com/API:Decrypt_Password

 

However I am new to this also and am not very experienced! Just a hunch.

Link to comment
Share on other sites

The hook uses a custom field (forum username) to insert the username into the phpBB database, perhaps it would be better to add another custom field (forum password) to create the password then.

 

I'm doing some more work on the hook now as it doesnt seem to be adding the user in phpBB no more, but thanks alot for your replies :)

Link to comment
Share on other sites

Ok i've got the hook working. Here's how it works:

 

You create 2 custom profile fields in WHMCS - forum username and forum password.

When a client registers in WHMCS, the hook adds a phpBB3 user using the 2 custom profile fields.

The client can now login to the phpBB3 forums using the specified custom profile fields.

 

Here's the hook:

createphpbbuser.zip

Link to comment
Share on other sites

great to hear that you got it working :). Yes that is a good suggestion, another option would have been to use the same username and password that are generated for your hosting creation(if you have one)

 

But well done! its a challenge at times especially if you are not getting any error messages which is the issue I am having at the moment. I have a script that is being called using the hooks, its running fine but not doing what I want it to!!! GRRR

 

I'm getting close to posing it on the forum here for advice!

Link to comment
Share on other sites

  • 1 year later...
  • 1 year later...
  • 2 weeks later...

this is a nice plugin/idea but it doesnt work , i have tested it with whmcs 5.2.7 and phpBB 3.0.12 on a test installation.

i got different errors like these :

i used the attachment from the post #7 :12-07-10, 11:55 PM

 

 

PHP Fatal error: Call to a member function session_begin() on a non-object in

/home/USERDIR/public_html/includes/hooks/createphpbbuser.php on line 72

 

 

after commenting the line below

$user->session_begin();

 

i get this error :

 

PHP Fatal error: SQL ERROR [ mysql4 ]<br /><br />You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 3 [1064]<br /><br />An sql error occurred while fetching thi s page. Please contact an administrator if this problem persists. in /home/userdir/public_html/forums/includes/db/dbal.php on line 757

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated