Parse.com Express与Facebook的完整登录过程 [英] Parse.com Express complete login process with Facebook

查看:71
本文介绍了Parse.com Express与Facebook的完整登录过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试调整Parse Express教程:

I am trying to tweak the Parse Express tutorial:

https://www.anyimg.org/基本上,而不是从其默认主页开始,如果用户尚未登录,我始终会显示一个登录页面.我能够通过在以下位置添加对Parse.User.Current()的简单检查来做到这一点.主页端点,如果没有发现,则重定向到登录名.

Basically, instead of starting with their default home page, I always show a login page if the user has not been logged in. I was able to do that by adding a simple check for Parse.User.Current() at the Homepage endpoint and redirecting to login if they are not looged in.

下一步,我想允许Facebook登录.因此,我对login.ejs进行了如下调整:

For my next step, I want to allow Facebook login. So I tweaked the login.ejs as follows:

<div id="fb-root"></div>
<script>
    window.fbAsyncInit = function() {
        Parse.FacebookUtils.init({
            appId      : '254642391362596',
            status     : true,
            xfbml      : true
        });
    };

(function(d, s, id){
    var js, fjs = d.getElementsByTagName(s)[0];
    if (d.getElementById(id)) {return;}
    js = d.createElement(s); js.id = id;
    js.src = "//connect.facebook.net/en_US/all.js";
    fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));

function fLogin() {

/*Parse.FacebookUtils.logIn(null, {
    *//*success: function(user) {
        alert("login success with user " + JSON.stringify(user));
        if (!user.existed()) {
            alert("User signed up and logged in through Facebook!");
        } else {
            alert("User logged in through Facebook!");
        }
        //FB.api('/me', function(response) {
        //  alert("got fb me api=" + JSON.stringify(response));
        //});

    },
    error: function(user, error) {
        alert("User cancelled the Facebook login or did not fully authorize.");
    }*//*
});*/

// log in with Parse
Parse.FacebookUtils.logIn(authData, {
    success: this._fbLoginSuccess,
    error: this._fbLoginError
});
}
</script>


<button class="btn-facebook btn-large" onclick="fLogin();"><img src="./images/FB-f-Logo__blue_58.png"> <span class="btn-facebook-text">Login with Facebook</span></button>

好消息:当我尝试不带登录块的带注释的块时,我收到FaceBook登录提示,然后可以转到DataBrowser并在其中查看AuthData.

The good news: When I try the commented block without the login block, I get a FaceBook login prompt, and I can go to the DataBrowser and see AuthData there.

但是,如果我使用//Login块,似乎什么也没发生.

However, if I use the //Login block, nothing seems to happen.

此外,如果FB登录成功,我如何在app.js或user.js中进行更改以允许主页呈现?我已经搜索了一天的文档和SO,但没有看到任何清晰的文档.

Also, if FB login is a success what do I change in app.js or user.js to allow the home page to render? I have been searching docs and SO for a day now, and I don't see any clear docs on this.

感谢您的帮助!

注意:我对Parse和Express都比较陌生,但是我基本上能够自己进步(请在这里查看我的其他帖子).

Note: I am rather new to both Parse and Express, but I have been able to make progress mostly on my own (please see my other postings here).

我取得了进步.上面的代码本质上是有效的.从上方删除不需要的警报,并使用window.location.href ='"home"/我的一个路线.但是,我仍然无法将帖子发送到我的users.js页面.任何帮助将不胜感激

I have made progress. The code above essentially works. Remove unwanted alerts from above and use window.location.href = '"home"/one-of-my-routes". However, I am still unable to send a post to my users.js page. Any help will be appreciated

推荐答案

我最近发现了这个有用的帖子.阿尔伯特(Albert),这就是您建议的turn().这至少帮了我一个版本.

I recently found this useful post. Albert, this has the become() that you suggested. And this helped me at least get one version working.

解析Javascript SDK -将客户端`user`另存为服务器端`Parse.User.current()`

这篇关于Parse.com Express与Facebook的完整登录过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆