Latest News: (loading..)
Sign in to follow this  
Followers 0
anderskiel

pbpBB2 and osC shared account creation

214 posts in this topic

I have uploaded an attempt at integrating phpBB2.21 (or any other with same database stucture) in the osC2.2 cart.

 

http://www.oscommerce.com/community/contributions,4501

 

My knowledge of php is very limited, but i have managed to get a shared login and password for the two. The contrib forces phpbb2 registration through the cart. chaveiro's PHPBB 2.0.8a implementation is used to create the shared login for the cart and forum.

 

How ever i do need some help getting the login sessions working. I imagine it would be a cartlogin with simultanious forum login (as in chaveiro's) and then a forced forum login through the cart. The forum template needs to be adjusted to look like the main cart, so customers won't realise how they are getting bounced about the site :D

 

A testing site is available at http://playground.mekini-graphics.dk/catalog

 

The cart is in danish, but you should be able to work it out if you are familiar with the system.

Share this post


Link to post
Share on other sites

The 0.2 version has been uploaded. :D

 

It is available from here:

 

phpbb2 and osC shared account creation v. 0.2

 

1. I have fixed the problems with the login name for the forum, by creating a seperate forum

username field on the create_account.php page.

 

2. Forum registration is now obtional when registering for the cart. if a user later desides to use

the forum a link to the forum registration page is provided at the top of create_account.php

 

3. The 'add old users to forum on login to cart' has been removed as forum registration is now obtional

 

4. Other bits of unnessesary code has been removed.

Share this post


Link to post
Share on other sites

I think this is the support thread of this contrib.

 

Thank you for the efforts. I just installed both phpbb 2.0.21 with your contrib v0.2. I didn't test every thing thotoughly, but I have some questions.

 

1. How to pass the existing user accounts to the phpbb fields? As mentioned in the History.txt, the 'add old users to forum on login to cart' has been removed, and I can't find any way to login to the forum with existing osC user accounts.

 

2. Is it possible to allow users to change their forum user name in the osC account info page? By adding this contribs, new accounts are create in the osC, so I think it's necessary to let users modify their basic info including username from the osC account info page.

 

Any advise?

Share this post


Link to post
Share on other sites

OK, I figured out how to pass existing customers to the phpbb users. The original codes to 'add old users to forum on login to cart' still work, so I put them back in. The original codes came from PHPBB 2.0.8a implementation

 

in the file catalog/login.php find:

// Check if email exists
$check_customer_query = tep_db_query("select customers_id, customers_firstname, customers_password, customers_email_address, customers_default_address_id from " . TABLE_CUSTOMERS . " where customers_email_address = '" . tep_db_input($email_address) . "'");

change to:

// Check if email exists
$check_customer_query = tep_db_query("select customers_id, customers_firstname, customers_lastname, customers_password, customers_email_address, customers_default_address_id from " . TABLE_CUSTOMERS . " where customers_email_address = '" . tep_db_input($email_address) . "'");

and find:

tep_db_query("update " . TABLE_CUSTOMERS_INFO . " set customers_info_date_of_last_logon = now(), customers_info_number_of_logons = customers_info_number_of_logons+1 where customers_info_id = '" . (int)$customer_id . "'");

add below:

// #CHAVEIRO16# BEGIN PHPBB2 
	$last_visit = 0;
	$current_time = time();
	$check_bbusers_query = tep_db_query("select *  from " . TABLE_PHPBB_USERS . " where user_id = '" . $check_customer['customers_id'] . "'");

	if (!tep_db_num_rows($check_bbusers_query)) {
		// Creates forum account if does't exists already
		$sql_data_array = array('user_id' => $customer_id,
						'user_active' =>1,
						'username' => strtoupper(substr($check_customer['customers_firstname'],0,1)) . ucwords(strtolower($check_customer['customers_lastname'])),
						'user_password' => md5($password),
						'user_session_time' => time(),
						'user_session_page' => 0,
						'user_lastvisit' => '',
						'user_regdate' => time(),
		 				'user_level' => 0,						
						'user_posts' => 0,
						'user_timezone' => 0.00,
						'user_style' => 1,
						'user_lang' => 'english', 
						'user_dateformat' => 'D M d, Y g:i a',
						'user_new_privmsg' => 0,
						'user_unread_privmsg' => 0,
						'user_last_privmsg' => 0,
						'user_emailtime' => '',
						'user_viewemail' => 0,
						'user_attachsig' => 1,
						'user_allowhtml' => 0, 
						'user_allowbbcode' => 1,
						'user_allowsmile' => 1,
						'user_allowavatar' => 1,
						'user_allow_pm' => 1,
						'user_allow_viewonline' => 1,
						'user_notify' => 0,
						'user_notify_pm' => 1,
						'user_popup_pm' => 1,  
						'user_rank' => 0,   
						'user_avatar' => '',   
						'user_avatar_type' => 0,
						'user_email' => $check_customer['customers_email_address'],
						'user_icq' => '',
						'user_website' => '',
// remove to avoid error	'user_from' => tep_get_zone_name((int)($check_country['entry_country_id']),(int)($check_country['entry_zone_id'])), 
						'user_sig' => '',
						'user_sig_bbcode_uid' => '',
						'user_aim' => '',
						'user_yim' => '',  
						'user_msnm' => '', 
						'user_occ' => '',
						'user_interests' => '',
						'user_actkey' => '',
						'user_newpasswd' => '');						 
		tep_db_perform(TABLE_PHPBB_USERS, $sql_data_array);
		tep_db_query("insert into " . TABLE_PHPBB_GROUPS . " (group_name, group_description, group_single_user, group_moderator) VALUES ('', 'Personal User', 1, 0)");
		tep_db_query("insert into " . TABLE_PHPBB_USER_GROUPS . " (group_id, user_id, user_pending)VALUES ('".tep_db_insert_id()."', $customer_id, 0)");
	} else {
		$userdata = tep_db_fetch_array($check_bbusers_query);
		$last_visit = ( $userdata['user_session_time'] > 0 ) ? $userdata['user_session_time'] : $current_time; 
		tep_db_query("UPDATE " . TABLE_PHPBB_USERS . " SET user_session_time = '".$current_time."', user_session_page = '0', user_lastvisit = '".$last_visit."' WHERE user_id ='" . $check_customer['customers_id'] . "'");
		$userdata['user_lastvisit'] = $last_visit;
	}
// #CHAVEIRO16# END PHPBB2

and in the file catalog/logoff.php find:

  require(DIR_WS_LANGUAGES . $language . '/' . FILENAME_LOGOFF);

 $breadcrumb->add(NAVBAR_TITLE);

add below:

// #CHAVEIRO16# BEGIN PHPBB2 
 $session_id = tep_session_id();
 tep_db_query("delete from " . TABLE_PHPBB_SESSIONS . " where session_id = '$session_id'");
// #CHAVEIRO16# END PHPBB2

That's it!

 

While the old customers login to the store, these codes will pass their customer data to phpbb_user. They will have their first name initial + last name as their username in the forum.

Share this post


Link to post
Share on other sites

There is another issue when the customers forget their password, and ask for a new password, they will have different passwords for either side. The original codes to sync password on both side still work. However, this only work if the customers change their password in the store.

 

in the file catalog/account_password.php find:

	  if (tep_validate_password($password_current, $check_customer['customers_password'])) {
	tep_db_query("update " . TABLE_CUSTOMERS . " set customers_password = '" . tep_encrypt_password($password_new) . "' where customers_id = '" . (int)$customer_id . "'");

	tep_db_query("update " . TABLE_CUSTOMERS_INFO . " set customers_info_date_account_last_modified = now() where customers_info_id = '" . (int)$customer_id . "'");

add below:

// #CHAVEIRO16# BEGIN PHPBB2 
  $sql_data_array = array('user_password' =>  md5($password_new),
						  'user_session_time' => time());							  
  tep_db_perform(TABLE_PHPBB_USERS, $sql_data_array,'update', "user_id = '" . tep_db_input($customer_id) . "'");
// #CHAVEIRO16# END PHPBB2

That's it!

 

It would be a good idea to add some text in this file, telling the customers when they change the password here will affect both side.

Edited by AlexStudio

Share this post


Link to post
Share on other sites
1. How to pass the existing user accounts to the phpbb fields? As mentioned in the History.txt, the 'add old users to forum on login to cart' has been removed, and I can't find any way to login to the forum with existing osC user accounts.

 

Because i made using the forum optional i removede the pasing from the login page. If you add it again all you previous customers will not have a choice on their next login. Existing cart users can register for the forum via the link on top of the create_account.php page. Code for this is in the language file from step 2.8 in the instal.txt. You can edit the link as you wish. Maybe it needs to be more obvious - but i didn't want it to be intrusive for customers who only want to use the cart.

 

2. Is it possible to allow users to change their forum user name in the osC account info page? By adding this contribs, new accounts are create in the osC, so I think it's necessary to let users modify their basic info including username from the osC account info page.

 

I have thought about this, and it would probably just be a case of adding an extra field and simiilar code to that on registration page to the account_edit page.

 

I'll try to look into it :)

Share this post


Link to post
Share on other sites
There is another issue when the customers forget their password, and ask for a new password, they will have different passwords for either side. The original codes to sync password on both side still work. However, this only work if the customers change their password in the store.

 

in the file catalog/account_password.php find:

	  if (tep_validate_password($password_current, $check_customer['customers_password'])) {
	tep_db_query("update " . TABLE_CUSTOMERS . " set customers_password = '" . tep_encrypt_password($password_new) . "' where customers_id = '" . (int)$customer_id . "'");

	tep_db_query("update " . TABLE_CUSTOMERS_INFO . " set customers_info_date_account_last_modified = now() where customers_info_id = '" . (int)$customer_id . "'");

add below:

// #CHAVEIRO16# BEGIN PHPBB2 
  $sql_data_array = array('user_password' =>  md5($password_new),
						  'user_session_time' => time());							  
  tep_db_perform(TABLE_PHPBB_USERS, $sql_data_array,'update', "user_id = '" . tep_db_input($customer_id) . "'");
// #CHAVEIRO16# END PHPBB2

That's it!

 

It would be a good idea to add some text in this file, telling the customers when they change the password here will affect both side.

 

 

Oops that wasn't ment to have been removed in the v 0,2 thanks for picking up on that. Guess if a similar code was placed on the forum side it wouldn't matter where you ask for a new password.

 

:thumbsup:

Share this post


Link to post
Share on other sites

Thank you Anders. There is a mistake in the install.txt

 

Section 1.4 and 1.5 seems to be redundant, since those are done in the section 1.2

 

In section 1.4, the FIND part seems to be identical to the REPLACE WITH part. This line:

<td width="45%" align="right"><span class="gen">{L_USERNAME}:</span></td>

should be:

<td width="45%" align="right"><span class="gen">{L_USERNAME_EMAIL}:</span></td>

Share this post


Link to post
Share on other sites

When customers forgot their password and generated a new one sent by email, the forum password is not updated. Customers have to change password again to sync passwords on both side, otherwise they can't login to the forum. This is not covered in the original codes, so I add some modified codes into it. With these modified codes, now password_forgotten.php will update the new password in both customer and phpbb_user tables. So users can use the new password to login both osc and phpbb. Here is the codes:

 

in catalog/password_forgotten.php find:

	  tep_db_query("update " . TABLE_CUSTOMERS . " set customers_password = '" . tep_db_input($crypted_password) . "' where customers_id = '" . (int)$check_customer['customers_id'] . "'");

add below:

// BOF PHPBB2  
  $sql_data_array = array('user_password' =>  md5($new_password),
						  'user_session_time' => time());							  
  tep_db_perform(TABLE_PHPBB_USERS, $sql_data_array,'update', "user_id = '" . tep_db_input($check_customer['customers_id']) . "'");
// EOF PHPBB2

That's it!

Edited by AlexStudio

Share this post


Link to post
Share on other sites

I agree with you. 1.4 and 1.5 should be redundant, but somehow i had to move thigs around a little to make it look right - maybe because i used the easy mods for the phpbb changes. But Text for password and username wasn't in alignment >_< I'll try a clean install again and se if I can reproduce the fumble :-"

 

Thanks for the correction of L_USERNAME_EMAIL

 

I'll add the catalog/password_forgotten.php code to the instal.txt when updating. I guess if a similar code was placed in the forum forgotten password it wouldn't matter if users asked for new password in forum or cart. Will look into it when I get a little time :blink:

Share this post


Link to post
Share on other sites

I felt this had relevance to this thread although it is mainly about phpbb2 coding!

 

Ok i have tried playing a little bit around with the usercp_sendpasswd.php in phpbb2, but I'm not really winning. Not sure if i have naffed it up or it never worked, but it sure can't give me a new password that works now.

 

I have made some changes, tried with them and without them, but still not a working password. It changes the password, sends me the email with the new password, but it just doesn't work.

 

Anyway here is the code i'm trying to get to change cart password.

 

   
$sql = "SELECT customers_firstname, customers_lastname, customers_password, customers_id 
	FROM customers 
	WHERE customers_email_address = '" . str_replace("\'", "''", $email) . "'"; 

$sql = "UPDATE " . customers . " 
	  SET customers_password = '" . md5($user_password) . "'
	WHERE customers_email_address = '" . str_replace("\'", "''", $email) . "'";

 

This is an attempt to copy the code that changes the password in phpbb and make it put the new password into the table customers in osC. This is the code it sits in :(

 

if ( !defined('IN_PHPBB') )
{
die('Hacking attempt');
exit;
}

if ( isset($HTTP_POST_VARS['submit']) )
{
$username = ( !empty($HTTP_POST_VARS['username']) ) ? phpbb_clean_username($HTTP_POST_VARS['username']) : '';
$email = ( !empty($HTTP_POST_VARS['email']) ) ? trim(strip_tags(htmlspecialchars($HTTP_POST_VARS['email']))) : '';

$sql = "SELECT user_id, username, user_email, user_active, user_lang 
	FROM " . USERS_TABLE . " 
	WHERE user_email = '" . str_replace("\'", "''", $email) . "' 
		AND username = '" . str_replace("\'", "''", $username) . "'";
if ( $result = $db->sql_query($sql) )
{
	if ( $row = $db->sql_fetchrow($result) )
	{
		if ( !$row['user_active'] )
		{
			message_die(GENERAL_MESSAGE, $lang['No_send_account_inactive']);
		}

		$username = $row['username'];
		$user_id = $row['user_id'];

		$user_actkey = gen_rand_string(true);
		$key_len = 54 - strlen($server_url);
		$key_len = ($key_len > 6) ? $key_len : 6;
		$user_actkey = substr($user_actkey, 0, $key_len);
		$user_password = gen_rand_string(false);

		$sql = "UPDATE " . USERS_TABLE . " 
			SET user_newpasswd = '" . md5($user_password) . "', user_actkey = '$user_actkey'  
			WHERE user_id = " . $row['user_id'];

// shared account creation by slackbro'
$sql = "SELECT customers_firstname, customers_lastname, customers_password, customers_id 
	FROM customers 
	WHERE customers_email_address = '" . str_replace("\'", "''", $email) . "'"; 

$sql = "UPDATE " . customers . " 
	  SET customers_password = '" . md5($user_password) . "'
	WHERE customers_email_address = '" . str_replace("\'", "''", $email) . "'";


// shared account creation by slackbro'				

		if ( !$db->sql_query($sql) )
		{
			message_die(GENERAL_ERROR, 'Could not update new password information', '', __LINE__, __FILE__, $sql);
		}



		include($phpbb_root_path . 'includes/emailer.'.$phpEx);
		$emailer = new emailer($board_config['smtp_delivery']);

		$emailer->from($board_config['board_email']);
		$emailer->replyto($board_config['board_email']);

		$emailer->use_template('user_activate_passwd', $row['user_lang']);
		$emailer->email_address($row['user_email']);
		$emailer->set_subject($lang['New_password_activation']);

		$emailer->assign_vars(array(
			'SITENAME' => $board_config['sitename'], 
			'USERNAME' => $username,
			'PASSWORD' => $user_password,
			'EMAIL_SIG' => (!empty($board_config['board_email_sig'])) ? str_replace('<br />', "\n", "-- \n" . $board_config['board_email_sig']) : '', 

			'U_ACTIVATE' => $server_url . '?mode=activate&' . POST_USERS_URL . '=' . $user_id . '&act_key=' . $user_actkey)
		);
		$emailer->send();
		$emailer->reset();

		$template->assign_vars(array(
			'META' => '<meta http-equiv="refresh" content="15;url=' . append_sid("index.$phpEx") . '">')
		);

		$message = $lang['Password_updated'] . '<br /><br />' . sprintf($lang['Click_return_index'],  '<a href="' . append_sid("index.$phpEx") . '">', '</a>');

		message_die(GENERAL_MESSAGE, $message);
	}
	else
	{
		message_die(GENERAL_MESSAGE, $lang['No_email_match']);
	}
}
else
{
	message_die(GENERAL_ERROR, 'Could not obtain user information for sendpassword', '', __LINE__, __FILE__, $sql);
}
}
else
{
$username = '';
$email = '';
}

Share this post


Link to post
Share on other sites
:

:

Ok i have tried playing a little bit around with the usercp_sendpasswd.php in phpbb2, but I'm not really winning. Not sure if i have naffed it up or it never worked, but it sure can't give me a new password that works now.

 

I have made some changes, tried with them and without them, but still not a working password. It changes the password, sends me the email with the new password, but it just doesn't work.

:

:

:
:
// shared account creation by slackbro'
$sql = "SELECT customers_firstname, customers_lastname, customers_password, customers_id 
	FROM customers 
	WHERE customers_email_address = '" . str_replace("\'", "''", $email) . "'"; 

$sql = "UPDATE " . customers . " 
	  SET customers_password = '" . md5($user_password) . "'
	WHERE customers_email_address = '" . str_replace("\'", "''", $email) . "'";
// shared account creation by slackbro'				
:
:

I think the password will not work with osC, but it should work with phpBB. Try this:

// shared account creation by slackbro'
$check_customer_query = tep_db_query("select customers_firstname, customers_lastname, customers_password, customers_id from " . customers . " where customers_email_address = '" . tep_db_input($email) . "'");
			  if (tep_db_num_rows($check_customer_query)) {
				$check_customer = tep_db_fetch_array($check_customer_query);

				$crypted_password = tep_encrypt_password($user_password);

				tep_db_query("update " . customers . " set customers_password = '" . tep_db_input($crypted_password) . "' where customers_id = '" . (int)$check_customer['customers_id'] . "'");
			  }
// shared account creation by slackbro'

you need to include those tep_db functions and let me know what it ends up with.

Edited by AlexStudio

Share this post


Link to post
Share on other sites

Skip the osC tep_db functions. Here is the codes using phpbb sql_ functions. Move these codes to the new place in:

:
:
$sql = "UPDATE " . USERS_TABLE . " 
			SET user_newpasswd = '" . md5($user_password) . "', user_actkey = '$user_actkey'  
			WHERE user_id = " . $row['user_id'];

		if ( !$db->sql_query($sql) )
		{
			message_die(GENERAL_ERROR, 'Could not update new password information', '', __LINE__, __FILE__, $sql);
		}

Add below:

// shared account creation by slackbro'
$sql = "SELECT customers_firstname, customers_lastname, customers_password, customers_id 
	FROM customers 
	WHERE customers_email_address = '" . str_replace("\'", "''", $email) . "'"; 

		if ( !$db->sql_query($sql) )
		{
			message_die(GENERAL_ERROR, 'Could not update new password information', '', __LINE__, __FILE__, $sql);
		}

// start encrypt new password
$osC_password = ' ';
static $seeded;

if (!isset($seeded)) {
  mt_srand((double)microtime()*1000000);
  $seeded = true;
}

for ($i=0; $i<10; $i++){
  $osC_password .= mt_rand();

}
$salt = substr(md5($osC_password), 0, 2);
$osC_password = md5($salt . $user_password) . ':' . $salt;

$sql = "UPDATE " . customers . " 
	  SET customers_password = '" . $osC_password . "'
	WHERE customers_email_address = '" . str_replace("\'", "''", $email) . "'";

		if ( !$db->sql_query($sql) )
		{
			message_die(GENERAL_ERROR, 'Could not update new password information', '', __LINE__, __FILE__, $sql);
		}

// shared account creation by slackbro'

Share this post


Link to post
Share on other sites

Anders, please test the above codes and tell me the result. I don't know which file to put those codes in.

Share this post


Link to post
Share on other sites

AlexStudio ... Thanks!! The second piece of code Works Perfect. I never even bothered to try the other first code.

 

I was playing around with this section a while back and got close but no cigar .. so this is awesome!

 

 

And the file you want to put the code in Anderskiel is usercp_sendpasswrd.php in the phpbb2/includes/ directory.

 

Anders, please test the above codes and tell me the result. I don't know which file to put those codes in.
Edited by insomniac2

Share this post


Link to post
Share on other sites

I have successfuly made both osC and phpBB to sync user email/password, including create account (always create in osC), change email/password on either side, and forgot password on either side. Now I'm working on how to make users login/logoff on both sides at the same time, so users don't need to login again when moving back and forth. To achieve this, forcing customers to register on both sides becomes a much better idea.

Share this post


Link to post
Share on other sites

Excellent job AlexStudio!

 

I do however still have problems with the activation of the new password in phpbb2. I get the message "The activation key you supplied does not match any in the database". But the password works in the cart. I'll keep trying.

 

I'm looking forward to see the login sync.

 

I'm looking you over the sholder and learning :thumbsup:

Share this post


Link to post
Share on other sites

Anders, you probably put my code in the wrong place. You must put it after:

			$sql = "UPDATE " . USERS_TABLE . " 
			SET user_newpasswd = '" . md5($user_password) . "', user_actkey = '$user_actkey'  
			WHERE user_id = " . $row['user_id'];

		if ( !$db->sql_query($sql) )
		{
			message_die(GENERAL_ERROR, 'Could not update new password information', '', __LINE__, __FILE__, $sql);
		}

Otherwise no data would be stored in the phpbb_users table.

 

I got a big project today, and no time for coding right now. I'll be back in about 20 days.

Share this post


Link to post
Share on other sites

OK, I have make the login/logoff to work.

  • Login/logoff from phpbb redirected to osC login.php/logout.php, if the email/password is valid, send users back to phpbb without noticing a thing.

  • Modified osC login.php to log session data in database.
    Modified osC logoff.php to end sessions on both sides, and then redirect users back seamlessly to where they logoff from.

  • A trans_phpbb.php was created to carry the session id for users logged in, and no session id for anonymous users.

  • A trans_phpbb table added to databse to store session data for both sides.

  • phpbb2 files modified including common.php login.php in phpbb2 folder, page_header.php sessions.php in phpbb2/includes folder, index_body.tpl login_body.tpl overall_header.tpl in templates/subSilver folder

Share this post


Link to post
Share on other sites

Login/Logoff from either osC or phpbb

 

This is still in beta, testing in live store not recommended. V0.2 contribution must be installed first, and bug fixes in this thread. Make sure both osC and phpbb2 are working. There are some other things need to be done before applying these codes.

1. Customers must register in both osc and phpbb

2. Turn off auto login in phpbb admin

3. Create a .htaccess file to password protect phpbb/admin folder, and chmod to 777

4. Turn on Check IP Address and Recreate Session in admin->configuration->sessions

 

STEP-1 mySQL table

Run this script to add one new table in phpMyAdmin:

create table trans_phpbb ( osCsid char(32) default '' not null, sess_uid int(11) default 0 not null, sess_uip char(8) default '' not null, sess_logged int(1) default 0 not null, sess_trans char(32) default '' not null, primary key (osCsid))

 

STEP-2 osC files

 

STEP-2.1

Put this code into a new file - trans_phpbb.php - in catalog folder

<?php
/*
$id: trans_phpbb.php v.01 (beta) 2006/10/04 9:41:30 alexstudio
*/

 require('includes/application_top.php');

 $page_phpbb = HTTP_SERVER . '/phpBB2/index.php';

 if (tep_session_is_registered('customer_id')) {
$_sid = 'trid=' . tep_session_id();
$page_phpbb .= '?' . tep_output_string($_sid);
tep_redirect($page_phpbb, '', 'NONSSL');
 } else {
tep_redirect($page_phpbb, '', 'NONSSL');
 }
?>

 

STEP-2.2 catalog/login.php

find:

		tep_session_register('customer_first_name');
	tep_session_register('customer_country_id');
	tep_session_register('customer_zone_id');

	tep_db_query("update " . TABLE_CUSTOMERS_INFO . " set customers_info_date_of_last_logon = now(), customers_info_number_of_logons = customers_info_number_of_logons+1 where customers_info_id = '" . (int)$customer_id . "'");

Add after:

// #CHAVEIRO16# BEGIN PHPBB2 
	$last_visit = 0;
	$current_time = time();
	$check_bbusers_query = tep_db_query("select *  from " . TABLE_PHPBB_USERS . " where user_id = '" . $check_customer['customers_id'] . "'");

	if (!tep_db_num_rows($check_bbusers_query)) {
		// Creates forum account if does't exists already
		$sql_data_array = array('user_id' => $customer_id,
						'user_active' =>1,
						'username' => strtoupper(substr($check_customer['customers_firstname'],0,1)) . ucwords(strtolower($check_customer['customers_lastname'])),
						'user_password' => md5($password),
						'user_session_time' => time(),
						'user_session_page' => 0,
						'user_lastvisit' => '',
						'user_regdate' => time(),
		 				'user_level' => 0,						
						'user_posts' => 0,
						'user_timezone' => 0.00,
						'user_style' => 1,
						'user_lang' => 'english', 
						'user_dateformat' => 'D M d, Y g:i a',
						'user_new_privmsg' => 0,
						'user_unread_privmsg' => 0,
						'user_last_privmsg' => 0,
						'user_emailtime' => '',
						'user_viewemail' => 0,
						'user_attachsig' => 1,
						'user_allowhtml' => 0, 
						'user_allowbbcode' => 1,
						'user_allowsmile' => 1,
						'user_allowavatar' => 1,
						'user_allow_pm' => 1,
						'user_allow_viewonline' => 1,
						'user_notify' => 0,
						'user_notify_pm' => 1,
						'user_popup_pm' => 1,  
						'user_rank' => 0,   
						'user_avatar' => '',   
						'user_avatar_type' => 0,
						'user_email' => $check_customer['customers_email_address'],
						'user_icq' => '',
						'user_website' => '',
// removed to avoid error   'user_from' => tep_get_zone_name((int)($check_country['entry_country_id']),(int)($check_country['entry_zone_id'])), 
						'user_sig' => '',
						'user_sig_bbcode_uid' => '',
						'user_aim' => '',
						'user_yim' => '',  
						'user_msnm' => '', 
						'user_occ' => '',
						'user_interests' => '',
						'user_actkey' => '',
						'user_newpasswd' => '');						 
		tep_db_perform(TABLE_PHPBB_USERS, $sql_data_array);
		tep_db_query("insert into " . TABLE_PHPBB_GROUPS . " (group_name, group_description, group_single_user, group_moderator) VALUES ('', 'Personal User', 1, 0)");
		tep_db_query("insert into " . TABLE_PHPBB_USER_GROUPS . " (group_id, user_id, user_pending)VALUES ('".tep_db_insert_id()."', $customer_id, 0)");
	} else {
		$userdata = tep_db_fetch_array($check_bbusers_query);
		$last_visit = ( $userdata['user_session_time'] > 0 ) ? $userdata['user_session_time'] : $current_time; 
		tep_db_query("UPDATE " . TABLE_PHPBB_USERS . " SET user_session_time = '".$current_time."', user_session_page = '0', user_lastvisit = '".$last_visit."' WHERE user_id ='" . $check_customer['customers_id'] . "'");
//			$userdata['user_lastvisit'] = $last_visit;   <------------ Not used, Removed by AlexStudio
// BOF phpBB2 login from osc by AlexStudio
// encode ip for phpbb2
		$uip = ( !empty($HTTP_SERVER_VARS['REMOTE_ADDR']) ) ? $HTTP_SERVER_VARS['REMOTE_ADDR'] : ( ( !empty($HTTP_ENV_VARS['REMOTE_ADDR']) ) ? $HTTP_ENV_VARS['REMOTE_ADDR'] : getenv('REMOTE_ADDR') );
		$ip_sep = explode('.', $uip);
		$phpbb_ip = sprintf('%02x%02x%02x%02x', $ip_sep[0], $ip_sep[1], $ip_sep[2], $ip_sep[3]);

		$sql_trans_phpbb = array( 'osCsid' => tep_session_id(),
						   'sess_uid' => $customer_id,
						   'sess_uip' => $phpbb_ip,
						   'sess_logged' => 1);
		$check_trans_phpbb = tep_db_query("select osCsid, sess_uid, sess_uip, sess_logged from trans_phpbb where sess_uid = '" . $customer_id . "'");
		if (!tep_db_num_rows( $check_trans_phpbb ))
		{
		  tep_db_perform( trans_phpbb, $sql_trans_phpbb);
		} else {
		  tep_db_query("update trans_phpbb set osCsid = '" . tep_session_id() . "', sess_uip = '" . $phpbb_ip . "', sess_logged = 1, sess_trans ='' where sess_uid = '" . $customer_id . "'" );
		}
	}
//// EOF phpBB2 login from osC by AlexStudio
// #CHAVEIRO16# END PHPBB2

 

Find:

// restore cart contents
	$cart->restore_contents();

	if (sizeof($navigation->snapshot) > 0) {
	  $origin_href = tep_href_link($navigation->snapshot['page'], tep_array_to_string($navigation->snapshot['get'], array(tep_session_name())), $navigation->snapshot['mode']);

Replace with:

// restore cart contents
	$cart->restore_contents();
//// BOF phpbb2 by AlexStudio
	if ( isset( $HTTP_GET_VARS[ 'trans' ] ) && ( $HTTP_GET_VARS[ 'trans' ] == 'yes' )) {
	  tep_redirect( 'trans_phpbb.php' );
	} elseif (sizeof($navigation->snapshot) > 0 && $navigation->snapshot['page'] != FILENAME_PASSWORD_FORGOTTEN) {
	  $origin_href = tep_href_link($navigation->snapshot['page'], tep_array_to_string($navigation->snapshot['get'], array(tep_session_name())), 'SSL');
//// EOF AlexStudio

 

 

STEP-2.3 catalog/logoff.php

Find:

  require(DIR_WS_LANGUAGES . $language . '/' . FILENAME_LOGOFF);

 $breadcrumb->add(NAVBAR_TITLE);

Add after:

//// BOF phpBB2 Logoff from both side by AlexStudio
 $check_trans = tep_db_query( "select sess_uid, sess_logged, sess_trans from trans_phpbb where sess_uid = '" . (int)$customer_id . "'" );
$sess_phpbb = tep_db_fetch_array( $check_trans );
if ( empty( $sess_phpbb ) ) die('sess_phpbb empty !');
$trid=$sess_phpbb[ 'sess_trans' ];
if ( empty( $trid ) ) die('trid empty !');
tep_db_query("update trans_phpbb set sess_logged = 0 where sess_uid = '" . (int)$customer_id . "'");
//// EOF phpBB2 Logoff from both side by AlexStudio

 

Find:

  tep_session_unregister('customer_id');
 tep_session_unregister('customer_default_address_id');
 tep_session_unregister('customer_first_name');
 tep_session_unregister('customer_country_id');
 tep_session_unregister('customer_zone_id');
 tep_session_unregister('comments');

 $cart->reset();

Add after:

  if (sizeof($navigation->snapshot) > 0) {
$origin_href = tep_href_link($navigation->snapshot['page'], tep_array_to_string($navigation->snapshot['get'], array(tep_session_name())), $navigation->snapshot['mode']);
$navigation->clear_snapshot();
$link = $origin_href;	
 } else {  
$link = tep_href_link(FILENAME_DEFAULT);  
 }

// BOF Logoff from phpBB2 by AlexStudio
 if ( isset( $HTTP_GET_VARS[ 'trans' ] ) && $HTTP_GET_VARS[ 'yes' ] )
 {
tep_redirect( 'trans_phpbb.php' );
 } else {
$page_phpbb = HTTP_SERVER . '/phpBB2/login.php?logout=true&trans=yes&sid=' . tep_output_string($trid);
tep_redirect($page_phpbb, '', 'NONSSL');
 }
// EOF Logoff from phpBB2 by AlexStudio

Share this post


Link to post
Share on other sites

STEP-3 phpBB2 files

 

STEP-3.1 phpBB2/common.php

Find:

// Protect against HTTP_SESSION_VARS tricks
if (isset($HTTP_SESSION_VARS) && !is_array($HTTP_SESSION_VARS))
{
die("Hacking attempt");
}

if (@ini_get('register_globals') == '1' || strtolower(@ini_get('register_globals')) == 'on')
{

Add after:

// BOF phpBB2 login in osC by AlexStudio
if ( isset( $HTTP_GET_VARS[ 'trid' ] ))
{
 $osc_sid = $HTTP_GET_VARS[ 'trid' ];
}
// EOF phpBB2 login in osC by AlexStudio

 

Find at the bottom:

?>

Add before:

// BOF AlexStudio
if ( isset( $osc_sid ))
{
 $sql = "select osCsid, sess_uid, sess_uip, sess_logged from trans_phpbb where osCsid = '" . $osc_sid . "'";
 if( !($result = $db->sql_query($sql)) )
 {
 message_die(CRITICAL_ERROR, "Could not query trans_php sess_trans", "", __LINE__, __FILE__, $sql);
 }
 global $oscdata;
 $oscdata = $db->sql_fetchrow($result);
 $db->sql_freeresult($result);
 $osc_uid = $oscdata[ 'sess_uid' ];
}
// EOF AlexStudio

 

STEP-3.2 phpBB2/login.php

Find:

		// session id check
	if ($sid == '' || $sid != $userdata['session_id'])
	{
		message_die(GENERAL_ERROR, 'Invalid_session');
	}

	if( $userdata['session_logged_in'] )
	{

Add after:

//// BOF AlexStudio phpbb2 logoff
		$sql = "select osCsid, sess_uid, sess_uip, sess_logged, sess_trans from trans_phpbb where sess_uid = '" . $userdata[ 'user_id' ] ."'";
		if ( !($result = $db->sql_query($sql)) )
		{
			message_die(GENERAL_ERROR, 'Error in obtaining transata', '', __LINE__, __FILE__, $sql);
		}
		if( $row = $db->sql_fetchrow($result) )
		{
			$osCsid = $row[ 'osCsid' ];
		}
//// EOF AlexStudio phpbb2 logoff

 

Find:

		if (!empty($HTTP_POST_VARS['redirect']) || !empty($HTTP_GET_VARS['redirect']))
	{
		$url = (!empty($HTTP_POST_VARS['redirect'])) ? htmlspecialchars($HTTP_POST_VARS['redirect']) : htmlspecialchars($HTTP_GET_VARS['redirect']);
		$url = str_replace('&', '&', $url);
		redirect(append_sid($url, true));
	}
	else
	{
		redirect(append_sid("index.$phpEx", true));

replace with:

		if (!empty($HTTP_POST_VARS['redirect']) || !empty($HTTP_GET_VARS['redirect']))
	{
		$url = (!empty($HTTP_POST_VARS['redirect'])) ? htmlspecialchars($HTTP_POST_VARS['redirect']) : htmlspecialchars($HTTP_GET_VARS['redirect']);
		$url = str_replace('&', '&', $url);
		redirect(append_sid($url, true));
	}
//// BOF AlexStudio logoff in phpbb
	else if( isset( $HTTP_GET_VARS[ 'trans' ]) && $HTTP_GET_VARS[ 'trans' ] == 'yes' )
	{
		header('Location: http://yourdomain.com/catalog/index.php');
		session_write_close();
		exit();
	}
	else
	{
		header('Location: http://yourdomain.com/catalog/logoff.php?trans=yes&osCsid=' . $osCsid);
		session_write_close();
		exit();
//			redirect(append_sid("index.$phpEx", true));
//// EOF AlexStudio logoff in phpbb

Don't forget to put your osC URL in this code, 2 places

 

Find:

		$template->assign_vars(array(
		'USERNAME' => $username,

		'L_ENTER_PASSWORD' => (isset($HTTP_GET_VARS['admin'])) ? $lang['Admin_reauthenticate'] : $lang['Enter_password'],
		'L_SEND_PASSWORD' => $lang['Forgotten_password'],

		'U_SEND_PASSWORD' => append_sid("profile.$phpEx?mode=sendpassword"),

Replace with:

		$template->assign_vars(array(
		'USERNAME' => $username,

		'L_ENTER_PASSWORD' => (isset($HTTP_GET_VARS['admin'])) ? $lang['Admin_reauthenticate'] : $lang['Enter_password'],
		'L_SEND_PASSWORD' => $lang['Forgotten_password'],

//			'U_SEND_PASSWORD' => append_sid("profile.$phpEx?mode=sendpassword"),
		'U_SEND_PASSWORD' => 'http://yourdoamin.com/catalog/password_forgotten.php',

Actually replace the last line only, put your osC URL in it.

 

STEP-3.3 phpBB2/admin/pagestart.php

Find:

if (!$userdata['session_admin'])
{
redirect(append_sid("login.$phpEx?redirect=admin/index.$phpEx&admin=1", true));
}

Replace with:

/*
if (!$userdata['session_admin'])
{
redirect(append_sid("login.$phpEx?redirect=admin/index.$phpEx&admin=1", true));
}
*/

 

STEP-3.4 phpBB2/includes/page_header.php

Find:

	'S_LOGIN_ACTION' => append_sid('login.'.$phpEx),

Replace with:

//// BOF phpBB2 login osC in phpbb2 AlexStudio 
'S_LOGIN_ACTION' => append_sid('http://yourdomain.com/catalog/login.php?action=process&trans=yes'),
//// EOF phpBB2 login osC in phpbb2 AlexStudio

put your osC URL here, too

 

STEP-3.5 phpBB2/includes/sessions.php

Find:

function session_begin($user_id, $user_ip, $page_id, $auto_create = 0, $enable_autologin = 0, $admin = 0)
{
global $db, $board_config;
global $HTTP_COOKIE_VARS, $HTTP_GET_VARS, $SID;

Add after:

	global $oscdata;

 

Find:

if (isset($sessiondata['autologinid']) && (string) $sessiondata['autologinid'] != '' && $user_id)
	{
		$sql = 'SELECT u.* 
			FROM ' . USERS_TABLE . ' u, ' . SESSIONS_KEYS_TABLE . ' k
			WHERE u.user_id = ' . (int) $user_id . "
				AND u.user_active = 1
				AND k.user_id = u.user_id
				AND k.key_id = '" . md5($sessiondata['autologinid']) . "'";
		if (!($result = $db->sql_query($sql)))
		{
			message_die(CRITICAL_ERROR, 'Error doing DB query userdata row fetch', '', __LINE__, __FILE__, $sql);
		}

		$userdata = $db->sql_fetchrow($result);
		$db->sql_freeresult($result);

		$enable_autologin = $login = 1;
	}

Add after:

// BOF add osCsid trans login check by AlexStudio
	else if ( isset( $oscdata ) && $oscdata[ 'sess_logged' ] == 1 && $oscdata[ 'sess_uip' ] == $user_ip )
	{
	  $sql = "update trans_phpbb set sess_trans = '2' where sess_uid = '" . $oscdata[ 'sess_uid' ] . "'";
	  if ( !( $result = $db->sql_query($sql) ) )
	  {
		message_die(CRITICAL_ERROR, 'Error update trans_phpbb sess_trans', '', __LINE__, __FILE__, $sql);
	  }
		$sessiondata['autologinid'] = '';
		$sessiondata['userid'] = $user_id;

		$sql = 'SELECT *
			FROM ' . USERS_TABLE . '
			WHERE user_id = ' . (int) $user_id . '
				AND user_active = 1';
		if (!($result = $db->sql_query($sql)))
		{
			message_die(CRITICAL_ERROR, 'Error doing DB query userdata row fetch', '', __LINE__, __FILE__, $sql);
		}

		$userdata = $db->sql_fetchrow($result);
		$db->sql_freeresult($result);

		$enable_autologin = 0;
		$login = 1;
	}
// EOF add osCsid trans login check by AlexStudio

 

Find:

	setcookie($cookiename . '_data', serialize($sessiondata), $current_time + 31536000, $cookiepath, $cookiedomain, $cookiesecure);
setcookie($cookiename . '_sid', $session_id, 0, $cookiepath, $cookiedomain, $cookiesecure);

$SID = 'sid=' . $session_id;

Add after:

//// BOF AlexStudio add sess_trans
if ( isset( $oscdata ) && $oscdata[ 'sess_uip' ] == $user_ip )
{
  $sql = "update trans_phpbb set sess_trans = '" . $session_id . "' where sess_uid = '" . $oscdata[ 'sess_uid' ] . "'";
  if ( !( $result = $db->sql_query($sql) ) )
  {
	message_die(CRITICAL_ERROR, 'Error update trans_phpbb sess_trans', '', __LINE__, __FILE__, $sql);
  }
}
//// EOF AlexStudio add sess_trans

 

Find:

function session_pagestart($user_ip, $thispage_id)
{
global $db, $lang, $board_config;
global $HTTP_COOKIE_VARS, $HTTP_GET_VARS, $SID;

Add after:

	global $oscdata;

 

Find:

		//
	// Did the session exist in the DB?
	//
	if ( isset($userdata['user_id']) )

Replace with:

		//
	// Did the session exist in the DB?
	//
	if ( isset($userdata['user_id']) && !isset( $oscdata) )

 

Find:

	//
// If we reach here then no (valid) session exists. So we'll create a new one,
// using the cookie user_id if available to pull basic user prefs.
//
$user_id = ( isset($sessiondata['userid']) ) ? intval($sessiondata['userid']) : ANONYMOUS;

Replace with:

// BOF osCsid trans check by AlexStudio
if( isset( $oscdata ) )
{
  $user_id = $oscdata[ 'sess_uid' ];
  $sql = "update trans_phpbb set sess_trans = '1' where sess_uid = '" . $oscdata[ 'sess_uid' ] . "'";
  if( !($result = $db->sql_query($sql)) )
  {
  message_die(CRITICAL_ERROR, "Could not update trans_php sess_trans", "", __LINE__, __FILE__, $sql);
  }
//
// If we reach here then no (valid) session exists. So we'll create a new one,
// using the cookie user_id if available to pull basic user prefs.
//
} else {
  $user_id = ( isset($sessiondata['userid']) ) ? intval($sessiondata['userid']) : ANONYMOUS;
}
// EOF osCsid trans check by AlexStudio

 

STEP-3.6 phpBB2/language/lang_english/lang_main.php

Find:

$lang['Username_Email'] =

Replace that line with:

$lang['Username_Email'] = 'Email Address'; ////<--- Added by Username or Email mod

 

STEP-3.7 phpBB2/templates/subSilver/index_body.tpl

Find:

	  <td class="row1" align="center" valign="middle" height="28"><span class="gensmall">{L_USERNAME_EMAIL}: 
	<input class="post" type="text" name="username" size="10" />
	???{L_PASSWORD}: 
	<input class="post" type="password" name="password" size="10" maxlength="32" />
	<!-- BEGIN switch_allow_autologin -->
	?? ??{L_AUTO_LOGIN} 
	<input class="text" type="checkbox" name="autologin" />
	<!-- END switch_allow_autologin -->
	??? 
	<input type="submit" class="mainoption" name="login" value="{L_LOGIN}" />
	</span> </td>

Rplace with:

	  <td class="row1" align="center" valign="middle" height="28"><span class="gensmall">{L_USERNAME_EMAIL}: 
	<input class="post" type="text" name="email_address" size="25" />
	???{L_PASSWORD}: 
	<input class="post" type="password" name="password" size="25" maxlength="32" />
	<!-- BEGIN switch_allow_autologin -->
<!--
	?? ??{L_AUTO_LOGIN} 
	<input class="text" type="checkbox" name="autologin" />  -->
	<!-- END switch_allow_autologin -->
	??? 
	<input type="submit" class="mainoption" name="login" value="{L_LOGIN}" />
	</span> </td>

 

Not finished yet...

Share this post


Link to post
Share on other sites

STEP-3.8 phpBB2/templates/subSilver/login_body.tpl

Find:

			  <input type="text" class="post" name="username" size="25" maxlength="40" value="{USERNAME}" />

Replace with:

			  <input type="text" class="post" name="email_address" size="25" maxlength="40" value="{USERNAME}" />

 

Find:

		  <!-- BEGIN switch_allow_autologin -->
	  <tr align="center"> 
		<td colspan="2"><span class="gen">{L_AUTO_LOGIN}: <input type="checkbox" name="autologin" /></span></td>
	  </tr>
	  <!-- END switch_allow_autologin -->

Replace with:

		  <!-- BEGIN switch_allow_autologin -->
<!--		  <tr align="center"> 
		<td colspan="2"><span class="gen">{L_AUTO_LOGIN}: <input type="checkbox" name="autologin" /></span></td>
	  </tr>  -->
	  <!-- END switch_allow_autologin -->

 

STEP-3.9 phpBB2/tamplates/subSilver/overall_header.tpl

Find:

<a href="{U_FAQ}" class="mainmenu"><img src="templates/subSilver/images/icon_mini_faq.gif" width="12" height="13" border="0" alt="{L_FAQ}" hspace="3" />{L_FAQ}</a>? ?<a href="{U_SEARCH}" class="mainmenu"><img src="templates/subSilver/images/icon_mini_search.gif" width="12" height="13" border="0" alt="{L_SEARCH}" hspace="3" />{L_SEARCH}</a>? ?<a href="{U_MEMBERLIST}" class="mainmenu"><img src="templates/subSilver/images/icon_mini_members.gif" width="12" height="13" border="0" alt="{L_MEMBERLIST}" hspace="3" />{L_MEMBERLIST}</a>? ?<a href="{U_GROUP_CP}" class="mainmenu"><img src="templates/subSilver/images/icon_mini_groups.gif" width="12" height="13" border="0" alt="{L_USERGROUPS}" hspace="3" />{L_USERGROUPS}</a>?

Add a button to link to your store in this section.

 

 

 

 

I think that is all, but can't be very sure. Please test these codes if you're interested, and kindly let me know if any problem. The codes in my store work perfectly, if there is any problem in the codes here, probably I missed something in here.

 

cheers! :)

Share this post


Link to post
Share on other sites

oh yes, I did miss something.

 

STEP-2.4 catalog/includes/information.php or any other files you put the link to phpbb2. Change the link to:

'<a href="http://yourdomain.com/catalog/trans_phpbb.php">phpBB2</a>'

Edited by AlexStudio

Share this post


Link to post
Share on other sites

Found an issue when phpbb board disabled in phpbb admin->configuration, there is no way to get back in the phpbb admin page again if the session closed.

 

Fix: phpbb2/admin/pagestart.php

Find:

//
// End session management
//

Replace all after with:

/* ///////// Removed by AlexStudio for osC phpbb integration
if (!$userdata['session_logged_in'])
{
redirect(append_sid("login.$phpEx?redirect=admin/index.$phpEx", true));
}
else if ($userdata['user_level'] != ADMIN)
{
message_die(GENERAL_MESSAGE, $lang['Not_admin']);
}

if ($HTTP_GET_VARS['sid'] != $userdata['session_id'])
{
redirect("index.$phpEx?sid=" . $userdata['session_id']);
}

if (!$userdata['session_admin'])
{
redirect(append_sid("login.$phpEx?redirect=admin/index.$phpEx&admin=1", true));
}
*/
if (empty($no_page_header))
{
// Not including the pageheader can be neccesarry if META tags are
// needed in the calling script.
include('./page_header_admin.'.$phpEx);
}

?>

And you have to get in the admin page by the URL:

http://yourdomain.com/phpbb2/admin/index.php

By applying this change, you must have a .htaccess file in phpbb2/admin folder to password protect it.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0