[英]PHP HybridAuth: How to redirect to the “Allow” page of the selected social network?
I'm having some issues with HybridAuth when I need to redirect "a non-registered user in my local database", to the selected social network: facebook, twitter, windows live, linkedin, openid, etc, more presiously to the "Allow" and "Cancel" page!? 当我需要将“我的本地数据库中的未注册用户”重定向到所选的社交网络时,HybridAuth出现了一些问题:facebook,twitter,windows live,linkedin,openid等,更主要地是“允许” ”和“取消”页面!
Till now I've got this code going on: 到现在为止,我正在执行以下代码:
try {
// $via for instance can be: Twitter, Facebook, etc
$hybridauth = new Hybrid_Auth( $myConfig );
$via = ucfirst($via);
$adapter = $hybridauth->authenticate( $via ); // from this line some redirecting accoures
if( $hybridauth->isConnectedWith( $via ) ){
$user = $hybridauth->authenticate($via)->getUserProfile();
}
$profile = Users::model()->findByAttributes(array(
'networkName' => $via,
'networkId' => $user->identifier,
));
if(!is_null($profile)) {
// do a login
} else {
// do a registration + login
}
} catch(Exception $e) {
echo "Error: please try again!";
echo "Original error message: " . $e->getMessage();
die();
}
I hope I've made my point clear. 我希望我已经阐明了我的观点。 Thanks for all assistance in this matter! 感谢您提供的所有协助!
The way I do is to store the provider and the provider identifier in a database, which seems to be the way you implemented as well. 我要做的方法是将提供程序和提供程序标识符存储在数据库中,这似乎也是您实现的方法。
If the user does not exist, I create it and then redirect the user to the user profile editor. 如果用户不存在,则创建它,然后将用户重定向到用户配置文件编辑器。 Otherwise I just redirect to the main page or dashboard. 否则,我只是重定向到主页或仪表板。
The provider data has all the required fields for creating a basic profile. 提供者数据具有用于创建基本配置文件的所有必填字段。 If you need something else, redirect the user to a page with a form for him to complete the registration. 如果您还需要其他内容,请将用户重定向到带有表单的页面,以便他完成注册。 Store anything else you need in SESSION or similar. 将您需要的其他任何内容存储在SESSION或类似内容中。 You can use $hybridauth->restoreSessionData($_SESSION['HYBRID']) to keep the session on. 您可以使用$ hybridauth-> restoreSessionData($ _ SESSION ['HYBRID'])来保持会话继续进行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.