我目前允许用户使用其PHPBB凭据登录我的网站。我使用这里描述的方法:
https://wiki.phpbb.com/Practical.External_login
但是,我想升级到PHPBB 3.1,并且还可以通过在表单上放置“使用Google登录”,“使用Facebook登录”按钮作为替代方法来登录。
我使用新的PHPBB 3.1功能在论坛上使用“使用Google登录”,但是我不知道如何在我的网站上将其实现为外部登录。
我遇到的最大问题是,如果使用“ Google”成功登录,我的用户将被重定向到论坛。但是,我希望将用户重定向到我网站上的特定页面。
我想出了如何做到这一点:
例如,创建一个“使用Google登录”按钮并将其链接到:
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');
}
}
?>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句