FrostByte Posted December 5, 2010 Share Posted December 5, 2010 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 0 Quote Link to comment Share on other sites More sharing options...
FrostByte Posted December 7, 2010 Author Share Posted December 7, 2010 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"); ?> 0 Quote Link to comment Share on other sites More sharing options...
thebizbuilder Posted December 7, 2010 Share Posted December 7, 2010 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. 0 Quote Link to comment Share on other sites More sharing options...
thebizbuilder Posted December 7, 2010 Share Posted December 7, 2010 just a note....the Get_Clients_Password API actually returns the MD5 hash, so couldn't you just use this straight away instead of decrypting and re-encrypting the password? I dunno just a thought, might not work 0 Quote Link to comment Share on other sites More sharing options...
thebizbuilder Posted December 7, 2010 Share Posted December 7, 2010 WOAH I did post another message before that but it never showed up!, Basically I said that in the API documentation it say you cannot use decryptpassword API call to get the clients password. So maybe that supposed to be used for the hosting password or something? http://wiki.whmcs.com/API:Decrypt_Password 0 Quote Link to comment Share on other sites More sharing options...
FrostByte Posted December 7, 2010 Author Share Posted December 7, 2010 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 0 Quote Link to comment Share on other sites More sharing options...
FrostByte Posted December 7, 2010 Author Share Posted December 7, 2010 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 0 Quote Link to comment Share on other sites More sharing options...
thebizbuilder Posted December 8, 2010 Share Posted December 8, 2010 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! 0 Quote Link to comment Share on other sites More sharing options...
FrostByte Posted December 9, 2010 Author Share Posted December 9, 2010 I might even develop it further to add the ClientEdit hook, so that clients can edit their forum password from WHMCS. Will see if i get the time (and patience) lol 0 Quote Link to comment Share on other sites More sharing options...
TinTin Posted July 7, 2012 Share Posted July 7, 2012 Did you have any avail on this?? 0 Quote Link to comment Share on other sites More sharing options...
afrotate Posted September 21, 2013 Share Posted September 21, 2013 Hi, is this hook still working correctly? 0 Quote Link to comment Share on other sites More sharing options...
LAZer414 Posted September 30, 2013 Share Posted September 30, 2013 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 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.