PHPBB 3.1 使用 Google 的外部登录
External login using Google for PHPBB 3.1
我目前允许用户使用他们的 PHPBB 凭据登录我的网站。我使用此处描述的方法:
https://wiki.phpbb.com/Practical.External_login
但是,我想升级到 PHPBB 3.1,并且还可以通过在表单上放置 "Login with Google"、"Login with Facebook" 按钮来允许登录。
我有 "Login with Google" 使用新的 PHPBB 3.1 功能在论坛上工作,但我不知道如何在我的网站上实现它作为外部登录。
我 运行 遇到的最大问题是,如果使用 "Google" 登录成功,我的用户将被重定向到论坛。但是,我希望用户被重定向到我网站上的特定页面。
我知道怎么做了:
创建一个 "Login with Google" 按钮,例如 link 到:
http://www.example.com/forum/loginoauth.php?mode=login&login=external&oauth_service=google
这是我的 loginoauth.php 文件:
<?php
// phpBB inclusion protection
define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
require($phpbb_root_path . 'common.' . $phpEx);
// Start session management
$user->session_begin();
$auth->acl($user->data);
if ($user->data['is_registered'])
{
redirect('http://www.example.com/profile');
}
else
{
//$autologin = $request->is_set_post('autologin');
$admin = ($admin) ? 1 : 0;
// Check if the supplied username is equal to the one stored within the database if re-authenticating
if ($admin && utf8_clean_string($username) != utf8_clean_string($user->data['username']))
{
// We log the attempt to use a different username...
add_log('admin', 'LOG_ADMIN_AUTH_FAIL');
trigger_error('NO_AUTH_ADMIN_USER_DIFFER');
}
// If authentication is successful we redirect user to previous page
// $result = $auth->login($username, $password, $autologin, $viewonline, $admin);
$result = $auth->login('','');
// The result parameter is always an array, holding the relevant information...
if ($result['status'] == LOGIN_SUCCESS)
{
redirect('http://www.example.com/profile');
}
}
?>
我目前允许用户使用他们的 PHPBB 凭据登录我的网站。我使用此处描述的方法:
https://wiki.phpbb.com/Practical.External_login
但是,我想升级到 PHPBB 3.1,并且还可以通过在表单上放置 "Login with Google"、"Login with Facebook" 按钮来允许登录。
我有 "Login with Google" 使用新的 PHPBB 3.1 功能在论坛上工作,但我不知道如何在我的网站上实现它作为外部登录。
我 运行 遇到的最大问题是,如果使用 "Google" 登录成功,我的用户将被重定向到论坛。但是,我希望用户被重定向到我网站上的特定页面。
我知道怎么做了:
创建一个 "Login with Google" 按钮,例如 link 到:
http://www.example.com/forum/loginoauth.php?mode=login&login=external&oauth_service=google
这是我的 loginoauth.php 文件:
<?php
// phpBB inclusion protection
define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
require($phpbb_root_path . 'common.' . $phpEx);
// Start session management
$user->session_begin();
$auth->acl($user->data);
if ($user->data['is_registered'])
{
redirect('http://www.example.com/profile');
}
else
{
//$autologin = $request->is_set_post('autologin');
$admin = ($admin) ? 1 : 0;
// Check if the supplied username is equal to the one stored within the database if re-authenticating
if ($admin && utf8_clean_string($username) != utf8_clean_string($user->data['username']))
{
// We log the attempt to use a different username...
add_log('admin', 'LOG_ADMIN_AUTH_FAIL');
trigger_error('NO_AUTH_ADMIN_USER_DIFFER');
}
// If authentication is successful we redirect user to previous page
// $result = $auth->login($username, $password, $autologin, $viewonline, $admin);
$result = $auth->login('','');
// The result parameter is always an array, holding the relevant information...
if ($result['status'] == LOGIN_SUCCESS)
{
redirect('http://www.example.com/profile');
}
}
?>