PHP HybridAuth:如何重定向到“允许”所选社交网络的页面?

发布于 2024-12-21 07:28:34 字数 976 浏览 6 评论 0原文

当我需要将“本地数据库中的非注册用户”重定向到选定的社交网络时,我遇到了 HybridAuth 的一些问题:facebook、twitter、windows live、linkedin、openid 等,更重要的是重定向到“允许”和“取消”页面!?

到目前为止,我已经得到了这段代码:

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'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!?

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浅紫色的梦幻 2024-12-28 07:28:34

我所做的方法是将提供者和提供者标识符存储在数据库中,这似乎也是您实现的方式。

如果用户不存在,我将创建它,然后将用户重定向到用户配置文件编辑器。否则我只是重定向到主页或仪表板。

提供商数据具有创建基本配置文件所需的所有字段。如果您需要其他内容,请将用户重定向到包含表单的页面,以供他完成注册。将您需要的任何其他内容存储在 SESSION 或类似的位置中。您可以使用 $hybridauth->restoreSessionData($_SESSION['HYBRID']) 保持会话开启。

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. You can use $hybridauth->restoreSessionData($_SESSION['HYBRID']) to keep the session on.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文