要把magento和phpbb登录注册联合起来,首先在根目录下创建一个forum文件夹,用于存放Phpbb源程序。然后在根目录下建立一下loginphpbb.php文件。
loginphpbb.php
<?php
/*
*论坛同步程序
*/
define('IN_PHPBB', true);
//同步登陆论坛
function forumLogin($username, $password, $admin = false)
{
global $db, $template, $config, $auth, $phpEx, $phpbb_root_path, $cache, $user;
$ss = array();
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : dirname(__FILE__).'/forum/';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
require_once($phpbb_root_path.'common.php');
require_once($phpbb_root_path.'includes/functions_user.php');
require_once($phpbb_root_path.'includes/functions_module.php');
$_REQUEST['username'] = $_POST['username'] = $username;
$_REQUEST['password'] = $_POST['password'] = $password;
$password = request_var('password', '', true);
$username = request_var('username', '', true);
$user->session_begin();
$auth->acl($user->data);
$user->setup();
$_REQUEST['sid'] = $_POST['sid']= $user->session_id;
$autologin = false;
$viewonline = 1;
$admin = ($admin) ? 1 : 0;
$viewonline = ($admin) ? $user->data['session_viewonline'] : $viewonline;
$auth->login($username, $password, $autologin, $viewonline, $admin);
if($admin){
$result = $db->sql_query("Select session_id From gr_bbs_sessions where session_user_id = '2' order by session_time desc");
$ss = $db->sql_fetchrow($result);
}
return $ss[session_id];
}
//同步退出论坛
function forumLogout()
{
global $db, $template, $config, $auth, $phpEx, $phpbb_root_path, $cache, $user;
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : dirname(__FILE__).'/forum/';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
require_once($phpbb_root_path.'common.php');
require_once($phpbb_root_path.'includes/functions_user.php');
require_once($phpbb_root_path.'includes/functions_module.php');
$user->session_kill();
$user->session_begin();
}
//同步注册论坛会员
function forumRegister($user_name, $password, $email, $coppa = false)
{
global $db, $template, $config, $auth, $phpEx, $phpbb_root_path, $cache, $user;
$_REQUEST['username'] = $_POST['username']=$user_name;
$_REQUEST['email'] = $_REQUEST['email_confirm'] = $_POST['email']= $_POST['email_confirm']= $email;
$_REQUEST['new_password'] = $_REQUEST['password_confirm'] = $_POST['new_password']= $_POST['password_confirm']= $password;
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : dirname(__FILE__).'/forum/';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
require_once($phpbb_root_path.'common.php');
require_once($phpbb_root_path.'includes/functions_user.php');
require_once($phpbb_root_path.'includes/functions_module.php');
// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup();
$timezone = date('Z') / 3600;
$is_dst = date('I');
if ($config['board_timezone'] == $timezone || $config['board_timezone'] == ($timezone - 1))
{
$timezone = ($is_dst) ? $timezone - 1 : $timezone;
if (!isset($user->lang['tz_zones'][(string) $timezone]))
{
$timezone = $config['board_timezone'];
}
}
else
{
$is_dst = $config['board_dst'];
$timezone = $config['board_timezone'];
}
$data = array(
'username' => utf8_normalize_nfc(request_var('username', '', true)),
'new_password' => request_var('new_password', '', true),
'password_confirm' => request_var('password_confirm', '', true),
'email' => strtolower(request_var('email', '')),
'email_confirm' => strtolower(request_var('email_confirm', '')),
'lang' => basename(request_var('lang', $user->lang_name)),
'tz' => request_var('tz', (float) $timezone),
);
$server_url = generate_board_url();
// Which group by default?
$group_name = ($coppa) ? 'REGISTERED_COPPA' : 'REGISTERED';
$sql = 'SELECT group_id
FROM ' . GROUPS_TABLE . "
WHERE group_name = '" . $db->sql_escape($group_name) . "'
AND group_type = " . GROUP_SPECIAL;
$result = $db->sql_query($sql);
$row = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
$group_id = $row['group_id'];
if (($coppa ||
$config['require_activation'] == USER_ACTIVATION_SELF ||
$config['require_activation'] == USER_ACTIVATION_ADMIN) && $config['email_enable'])
{
$user_actkey = gen_rand_string(10);
$key_len = 54 - (strlen($server_url));
$key_len = ($key_len < 6) ? 6 : $key_len;
$user_actkey = substr($user_actkey, 0, $key_len);
$user_type = USER_INACTIVE;
$user_inactive_reason = INACTIVE_REGISTER;
$user_inactive_time = time();
}
else
{
$user_type = USER_NORMAL;
$user_actkey = '';
$user_inactive_reason = 0;
$user_inactive_time = 0;
}
$user_row = array(
'username' => $data['username'],
'user_password' => phpbb_hash($data['new_password']),
'user_email' => $data['email'],
'group_id' => (int) $group_id,
'user_timezone' => (float) $data['tz'],
'user_dst' => $is_dst,
'user_lang' => $data['lang'],
'user_type' => $user_type,
'user_actkey' => $user_actkey,
'user_ip' => $user->ip,
'user_regdate' => time(),
'user_inactive_reason' => $user_inactive_reason,
'user_inactive_time' => $user_inactive_time,
);
// Register user...
$user_id = user_add($user_row);
if($user_id){
forumLogin($data[username],$data[new_password],false);
}
}
然后再更改magneto程序:
app\code\core\Mage\Customer\controllers\AccountController.php
大约是在174行,
在$this->_loginPostRedirect();前面添加:
$phpbbname = explode('@',$login['username']);
include('/web/loginphpbb.php');
forumLogin($phpbbname[0],$login['password']);
在355行,$this->_redirectSuccess($url);前面添加
$phpbbname = explode('@',$this->getRequest()->getPost('email'));
include('/web/loginphpbb.php');
forumRegister($phpbbname[0],$this->getRequest()->getPost('password'),$this->getRequest()->getPost('email'));
然后测试一下,OK。
值得注意的是,在phpbb后台,要记得把cookie关掉。
(责任编辑:最模板) |