Re: Wordpress integration plugin :)
User can change punBB profile settings but not login/logout/register or change password
You are not logged in. Please login or register.
PunBB Forums → PunBB 1.2 modifications, plugins and integrations → Wordpress integration plugin :)
User can change punBB profile settings but not login/logout/register or change password
OK Riklaunim.
When i tested it, i've got maybe a wrong direction link. I made surely a mistake.
If i understand, we are redirected to WP, only when we choose "Change password" link ? That's right ?
Ok. I'll remake your mod tomorrow. Thanks a lot !
Riklaunim, it works fine login/ register, but not to the Punbb profil access.
I can't change anything in my Punbb profil (avatar, location and so on), because i'm redirect to Worpress user panel.
I give the "profil.php" part concerned. Maybe you'll see the problem.
// Load the profile.php/register.php language file
require PUN_ROOT.'lang/'.$pun_user['language'].'/prof_reg.php';
// Load the profile.php language file
require PUN_ROOT.'lang/'.$pun_user['language'].'/profile.php';
header('Location: http://localhost/wdp/wp-admin/profile.php');
if ($action == 'change_pass')
{
if (isset($_GET['key']))
{
// If the user is already logged in we shouldn't be here :)
if (!$pun_user['is_guest'])
{
header('Location: index.php');
exit;
}
I tested RCMF (from your Website), this is a nice CMS php script with Punbb integrated.
I can't change anything in my Punbb profil (avatar, location and so on), because i'm redirect to Worpress user panel.
Did you put the redirect in the right place (for passwor changes) and are you logged in into punBB ?
Yes. I think so, before "if ($action == 'change_pass')" as you can see in my post before.
Yes, i'm logged in WP and Punbb.
Below add:
header('Location: http://www.url/do/wordpress/wp-admin/profile.php');
Yes. I think so, before "if ($action == 'change_pass')" as you can see in my post before.
Below, not before
(sorry for refreshing topic)
Just one line for one (big one) mistake.
I'm stupid. It could'nt follow the condition (if) while placing the code before.
Thank a lot Daris.
I updated to the new WordPress 2.5 and PunBB 1.2.17 this past weekend and I have been trying unsuccessfully to recreate the single login voodoo that I had before (WordPress 2.3 and PunBB 1.2.15).
Everything in the PunBB side points to the WordPress pages the same way but when I log into WordPress then try to visit PunBB it says that I'm not logged in. I am familiar with PHP but between these two systems there are too many variables to keep track of.
Does this plugin work with WordPress 2.5 and PunBB 1.2.17 (I know it was developed with previous versions) and if so can someone talk me through getting it working again? If not, is there anyone that can help me hack it so that it does? Thanks.
I'll look at this
So, I've been hacking on jl-punbb and poking around in the punbb and wordpress documentation and functions and here's what I've found so far:
First thing I did was replace all IF statements with if (changed case). Not sure if it's necessary, but it made me more comfortable.
On line 58 the code was:
$wpuser = $wpdb->get_row("SELECT user_pass FROM ".$wpdb->users." WHERE user_login = '".mysql_real_escape_string($user_login)."' LIMIT 1");
I changed it to:
$wpuser = $wpdb->get_row("SELECT id,user_pass FROM ".$wpdb->users." WHERE user_login = '".mysql_real_escape_string($user_login)."' LIMIT 1");
Wordpress changed the way they do authentication. On line 59 or so there is the line:
if(md5($user_pass) == $wpuser->user_pass)
I changed it to:
if(wp_check_password($user_pass, $wpuser->user_pass, $wpuser->id))
and that seems to work the way I want it to, using the new WordPress login credentials.
On line 68 there is the line:
IF($user->password == 'BRAK' OR sha1($user_pass) != $user->password)
PunBB also changed the way they do authentication so I changed it to:
if($user->password == 'BRAK' OR pun_hash($user_pass) != $user->password)
It told me that pun_hash function was undefined so I added:
define('PUN_TURN_OFF_MAINT', 1);
define('PUN_QUIET_VISIT', 1);
define('PUN_ROOT', '/path/forum/');
require PUN_ROOT.'include/common.php';
right before that line. Then I get this error:
Fatal error: Call to a member function query() on a non-object in /path/forum/include/functions.php on line 125
So, I pop open /include/functions.php and here is line 125:
// Fetch guest user
$result = $db->query('SELECT u.*, g.*, o.logged FROM '.$db->prefix.'users AS u INNER JOIN '.$db->prefix.'groups AS g ON u.group_id=g.g_id LEFT JOIN '.$db->prefix.'online AS o ON o.ident=\''.$remote_addr.'\' WHERE u.id=1') or error('Unable to fetch guest information', __FILE__, __LINE__, $db->error());
And I'm stuck. I'm not sure why the $db isn't an object.
After that my plan was to change line 71:
setcookie($cookie_name, serialize(array($user->id, md5($cookie_seed.sha1($user_pass)))), time() + 31536000, $cookie_path.'; HttpOnly', $cookie_domain, $cookie_secure);
to:
$user_id = $user->id;
$form_password_hash = pun_hash($form_password); // This could result in either an SHA-1 or an MD5 hash (depends on $sha1_available)
$expire = ($save_pass == '1') ? time() + 31536000 : 0;
pun_setcookie($user_id, $form_password_hash, $expire);
So, hopefully this will shortcut some of the troubleshooting for you. I'm anxious to get this plugin working again. Thanks for you help.
Edited because I remembered some other changes I made. I think that's all of them.
punBB integrating has one shit-point - it variables like $db has to be global in classes and functions you want to use - try globaling $db and other variables if it wants to - and that's the reason the jl-punbb is no-punbb-include
Where do I global it? In the include/functions.php or before the require line in jl-punbb?
I added this:
global $db;
right before:
require PUN_ROOT.'include/common.php';
and got this:
There is no valid language pack '' installed. Please reinstall a language of that name.
???
In the integration function that uses something from punBB code.
function foo()
{
global $db;
// the code
}
I edited at the same time as you posted, not sure if you caught my edit. It's telling me there is no valid language pack. I only have English installed (I guess... I didn't really "install" it).
There is no valid language pack '' installed. Please reinstall a language of that name.
the globals disaster is here. Add: $pun_config, $pun_user, $lang_common to global variables
After that my plan was to change line 71:
setcookie($cookie_name, serialize(array($user->id, md5($cookie_seed.sha1($user_pass)))), time() + 31536000, $cookie_path.'; HttpOnly', $cookie_domain, $cookie_secure);
to:
$user_id = $user->id; $form_password_hash = pun_hash($form_password); // This could result in either an SHA-1 or an MD5 hash (depends on $sha1_available) $expire = ($save_pass == '1') ? time() + 31536000 : 0; pun_setcookie($user_id, $form_password_hash, $expire);
My setcookie is taken form pun_setcookie function to avoid including punBB and playing with $variables globalisation
My setcookie is taken form pun_setcookie function to avoid including punBB and playing with $variables globalisation big_smile
Sounds like a good idea. My understanding from the documentation was that it would be easy to just include the file. Oh well.
So, I got the code to run through all the spots that it should, but the cookie doesn't seem to be setting in such a way that I'm being logged in. What file is the pun_setcookie function in?
I have to go to class right now but I'll be back in about four hours. I'm not sure what your schedule is like but I'll leave a note on the forum when I'm here again. Thanks again for all your help!
Warning: include(../forum/config.php) [function.include]: failed to open stream: No such file or directory in C:\wamp\www\wp\wp-content\plugins\jl-punbb.php on line 62
there is no ../forum/config.php so check all your paths from WP folder to punBB folder
All mine are hard-coded. I'm going to poke around in the functions and see if I can see how the cookie is set for login.
Got it working!
I redid my paths after I got it so that they were relative instead of hard-coded, which should make it work better (or at least with less modification) for other people. Working code is at the end of this post. I would like to massage it a little when I have some time to remove the pun includes so that it lives up to the previous ease of use (and will also make future changes easier).
I also fixed one other issue that always bugged me. When you click logout of the forums you still have to click logout on the blog. I like one-click functionality. To do this, you edit your punbb login.php slightly differently than explained before. Don't put the line in as previous instructions. Around line 39, find the line:
$action = isset($_GET['action']) ? $_GET['action'] : null;
After it, put:
if ($action == 'out')
header('Location: http://www.hugthecenterline.com/blog/wp-login.php?action=logout');
else
header('Location: http://www.hugthecenterline.com/blog/wp-login.php');
That's it! One-click shopping.
Thanks for all your help Riklaunim, and for making this excellent plugin in the first place!
Edit: I guess the version number should be changed. I don't know your numbering scheme so let me know what you want it changed to.
Here's my jl-punbb.php file to replace the stock one in the plugins folder after you do the install:
<?php
/*
Plugin Name: punBB integrator
Plugin URI: http://www.rkblog.rk.edu.pl
Description: Allows Wordpress to manager punBB users - login/logout/register/password change etc.
Version: 0.0.13.666
Author: Riklaunim
Author URI: http://www.rkblog.rk.edu.pl
*/
add_action('profile_update', 'punbb_profile_update');
add_action('wp_logout', 'punbb_wp_logout');
add_action('wp_authenticate', 'punbb_wp_authenticate', 1, 2);
add_action('user_register', 'punbb_user_register');
add_action('activate_jl-punbb/jl-punbb.php', 'punbb_sync_tables');
define('PUNPATH', '../forum/'); // path to punbb folder
define('PUNPREFIX', 'pun_'); // punBB table prefix
function punbb_sync_tables()
{
global $wpdb;
// copy users from WP to punBB that doesn't have account on punBB
$q = $wpdb->get_results("SELECT * FROM ".$wpdb->users." WHERE user_login NOT IN (SELECT username FROM ".PUNPREFIX."users)");
foreach($q as $u)
{
// give forum admin to the WP admin.
if($u->ID == 1)
{
$gid = 1;
}
else
{
$gid = 4;
}
$wpdb->query('INSERT INTO '.PUNPREFIX.'users (username, group_id, password, email, email_setting, save_pass, timezone, language, style, registered, registration_ip, last_visit) VALUES(\''.$u->user_login.'\', '.$gid.', \'BRAK\', \''.$u->user_email.'\', 1, 1, 1 , \'English\', \'Oxygen\', '.time().', \''.strip_tags($_SERVER['REMOTE_ADDR']).'\', '.time().')');
}
// turn off emails for "dectivated" accounts on forum
$wpdb->query('UPDATE '.PUNPREFIX.'users SET email_setting = 2 WHERE username NOT IN (SELECT user_login FROM '.$wpdb->users.') AND id > 1');
}
function punbb_profile_update($id)
{
global $wpdb;
$wpuser = $wpdb->get_row("SELECT user_login, user_email FROM ".$wpdb->users." WHERE ID = ".$id." LIMIT 1");
$wpdb->query("UPDATE ".PUNPREFIX."users SET email='".$wpuser->user_email."' WHERE username = '".$wpuser->user_login."'");
}
function punbb_wp_logout()
{
include PUNPATH.'/config.php';
setcookie($cookie_name, NULL, time()-3600, '/', '', '0');
}
function punbb_wp_authenticate($user_login, $user_pass)
{
global $wpdb;
// wywo?aj przy logowaniu jak masz dane
if($user_login and $user_pass and strlen($user_login) > 1 and strlen($user_pass) > 1)
{
$wpuser = $wpdb->get_row("SELECT id,user_pass FROM ".$wpdb->users." WHERE user_login = '".mysql_real_escape_string($user_login)."' LIMIT 1");
// AUTHENTICATION FOR WORDPRESS HAS CHANGED IN VERSION 2.5
// if(md5($user_pass) == $wpuser->user_pass)
if(wp_check_password($user_pass, $wpuser->user_pass, $wpuser->id))
{
$user = $wpdb->get_row("SELECT id, password FROM ".PUNPREFIX."users WHERE username = '".mysql_real_escape_string($user_login)."' LIMIT 1");
include PUNPATH.'/config.php';
/*
punBB uses sha1, wordpress md5. We have to cheat a bit. If the sha1 hash-password in punBB is "BRAK" (look at punbb_user_register)
or it doesn't match sha1(password from good authentication) then we update it :)
*/
//DEFINITIONS REQUIRED TO REQUIRE PUNS GLOBALS
define('PUN_TURN_OFF_MAINT', 1);
define('PUN_QUIET_VISIT', 1);
define('PUN_ROOT', '../forum/');
global $db, $pun_config, $pun_user, $lang_common;
require PUN_ROOT.'include/common.php';
//PUNS HASH METHOD HAS CHANGED... CALL THEIR FUNCTION
if($user->password == 'BRAK' OR pun_hash($user_pass) != $user->password)
{
//COMMENTED THIS OUT BECAUSE I DON'T WANT IT TO RUN. WILL NOT UPDATE PUN'S DB CORRECTLY
// $wpdb->query("UPDATE ".PUNPREFIX."users SET password='".sha1($user_pass)."' WHERE username = '".mysql_real_escape_string($user_login)."'");
}
//SETTINGS REQUIRED TO SET PUNS LOGIN COOKIE
$user_id = $user->id;
$form_password_hash = pun_hash($user_pass); // This could result in either an SHA-1 or an MD5 hash (depends on $sha1_available)
$expire = ($save_pass == '1') ? time() + 31536000 : 0;
$cookie_name="punbb_cookie";
$cookie_path="/";
$cookie_secure = 0;
$cookie_seed = "957942b8";
//SET THE COOKIE. THIS IS TAKEN FROM PUN'S include/functions.php FILE.
setcookie($cookie_name, serialize(array($user_id, md5($cookie_seed.$form_password_hash))), $expire, $cookie_path, $cookie_domain, $cookie_secure, true);
}
}
}
function punbb_user_register($id)
{
global $wpdb;
$wpuser = $wpdb->get_row("SELECT * FROM ".$wpdb->users." WHERE ID = ".$id." LIMIT 1");
$user = $wpdb->get_row("SELECT id FROM ".PUNPREFIX."users WHERE username = '".mysql_real_escape_string($wpuser->user_login)."' LIMIT 1");
// user already exists in punbb
if($user->id)
{
$wpdb->query("UPDATE ".PUNPREFIX."users SET password='BRAK' WHERE username = '".mysql_real_escape_string($wpuser->user_login)."'");
}
// user does not exists
else
{
$wpdb->query('INSERT INTO '.PUNPREFIX.'users (username, group_id, password, email, email_setting, save_pass, timezone, language, style, registered, registration_ip, last_visit) VALUES(\''.$wpuser->user_login.'\', 4, \'BRAK\', \''.$wpuser->user_email.'\', 1, 1, 1 , \'Polish\', \'Oxygen\', '.time().', \''.strip_tags($_SERVER['REMOTE_ADDR']).'\', '.time().')');
}
}
?>
This WP plugin work with punBB 1.3 ??
I haven't tested that, yet, because the stable 1.3 hasn't been released.
Okay i try this week end if i have time
PunBB Forums → PunBB 1.2 modifications, plugins and integrations → Wordpress integration plugin :)
Powered by PunBB, supported by Informer Technologies, Inc.