Facebook登录按钮问题

Facebook登录按钮问题,facebook,facebook-graph-api,facebook-fbml,Facebook,Facebook Graph Api,Facebook Fbml,我正在尝试用facebook实现一个登录和注册系统。我正在使用下面的代码: <div id="fb-root"></div> <script type="text/javascript"> window.fbAsyncInit = function() { FB.init({appId: 'MYAPPIDHERE', status: true, cookie: true, xfbml: true}); FB.Event.subscribe('a

我正在尝试用facebook实现一个登录和注册系统。我正在使用下面的代码:

<div id="fb-root"></div>

<script type="text/javascript">
window.fbAsyncInit = function() {
 FB.init({appId: 'MYAPPIDHERE', status: true, cookie: true, xfbml: true});

     FB.Event.subscribe('auth.login', function(response) {
         window.location = "https://domain.com/fblogin.aspx";
     });
     FB.Event.subscribe('auth.logout', function(response) {
         window.location.reload();
     });

 };
 (function() {
        var e = document.createElement('script');
        e.type = 'text/javascript';
        e.src = document.location.protocol +
            '//connect.facebook.net/en_US/all.js';
        e.async = true;
        document.getElementById('fb-root').appendChild(e);
 }());

</script>

<fb:login-button autologoutlink="true" perms="email,offline_access" registration-url="https://domain.com/register_fb.aspx" />

window.fbAsyninit=函数(){
init({appId:'MYAPPIDHERE',状态:true,cookie:true,xfbml:true});
FB.Event.subscribe('auth.login',函数(响应){
window.location=”https://domain.com/fblogin.aspx";
});
FB.Event.subscribe('auth.logout',函数(响应){
window.location.reload();
});
};
(功能(){
var e=document.createElement('script');
e、 类型='text/javascript';
e、 src=document.location.protocol+
“//connect.facebook.net/en_US/all.js”;
e、 异步=真;
document.getElementById('fb-root').appendChild(e);
}());
我需要一些建议。当前,如果我登录到facebook,该页面将自动触发“auth.login”事件,并将我重定向到我的应用程序。它工作得很好,但我想阻止这种行为。在理想情况下,如果Facebook登录按钮只在单击时触发“auth.login”事件,那就太好了

你的想法是什么?我是否应该放弃fb:login按钮并创建绑定到onclick事件的我自己的按钮?如果有的话,有什么好的例子可以分享吗


谢谢

我想你应该保留你的密码。给fb:login按钮一个id(比如,id=“fb_loginbutton”)并包装您的

window.location = "https://domain.com/fblogin.aspx";
…变成这样

var fb_loginbutton = document.getElementById('fb_loginbutton');
fb_loginbutton.onclick = function() {
    window.location = "https://domain.com/fblogin.aspx";
}
(这将包含在Event.subscribe…auth.login函数中。)

这样,成功的登录操作不是重定向浏览器,而是在单击时告诉按钮重定向

如果Facebook按钮没有说正确的东西,那么你可以改变它的HTML来说一些更有用的东西

fb_loginbutton.innerHTML = "Click here to continue";
…或者自己滚


我希望这有帮助

更新我设法找到了一个可行的解决方案:

<div id="fb-root"></div>
<script type="text/javascript">
window.fbAsyncInit = function() {
 FB.init({appId: 'MYAPPID', status: true, cookie: true, xfbml: true});

     FB.Event.subscribe('auth.login', function(response) {
         login();
     });

     FB.getLoginStatus(function(response) {
         if (response.session) {
             login();
         }
     });

 };
 (function() {
        var e = document.createElement('script');
        e.type = 'text/javascript';
        e.src = document.location.protocol +
            '//connect.facebook.net/en_US/all.js';
        e.async = true;
        document.getElementById('fb-root').appendChild(e);
 }());

 function login() {

     var fb_loginbutton = document.getElementById('fb_loginbutton');

    $('.fb_button_text').html('Continue to your account...');

    fb_loginbutton.onclick = function() {
        window.location = "https://domain.com/login_controller.aspx";
    }

 }
 </script>
使用密码存储用户ID的最佳实践是什么?我想用AES加密密码。userid是passphase,facebook secret是salt,系统生成的机器密钥是文本


当有人试图使用facebook登录时,它会生成一个加密密码,并将其与数据库中存储的密码进行比较。这将从本质上提供一个额外的安全层。想法?

谢谢你的建议。您的建议有些效果,但在我通过facebook凭据输入后,需要额外单击“继续”。另外,如果用户当前未连接到我的应用程序,我想知道如何将用户重定向到我的自定义facebook注册页面。我想我明白你的问题了-如果用户已经登录到facebook,那么他们应该需要单击按钮登录到你的站点,但是一旦他们登录Facebook并返回,他们就不需要再点击它了。此外,还可以将redirect_uri参数传递给FB.login调用,该调用可以将GET值(如“return_from_facebook=true”)返回到代码中,从而自动启动按钮。
Dim FacebookAPPID As String = "MY_FB_APP_ID"

If Request.Cookies("fbs_" & FaceBookAppID) Is Nothing Then
    'Response.Redirect("error.aspx")
End If

Dim cookie As String = Request.Cookies("fbs_" & FaceBookAppID).Value
cookie = cookie.Replace("""", "")

Dim facebookValues As NameValueCollection = HttpUtility.ParseQueryString(cookie)

'Response.Write(facebookValues("access_token"))
'Response.Write("<br><br>")
'Response.Write(facebookValues("secret"))
'Response.Write("<br><br>")
'Response.Write(facebookValues("session_key"))
'Response.Write("<br><br>")
'Response.Write(facebookValues("sig"))
'Response.Write("<br><br>")
'Response.Write(facebookValues("uid"))

doLogin(facebookValues("uid").ToString)
<div id="fb-root"></div>
<script>
  window.fbAsyncInit = function() {
    FB.init({appId: 'MY_APP_ID', status: true, cookie: true, xfbml: true});
  };
  (function() {
    var e = document.createElement('script'); e.async = true;
    e.src = document.location.protocol +
      '//connect.facebook.net/en_US/all.js';
    document.getElementById('fb-root').appendChild(e);
  }());
</script>


<fb:registration fields="[{'name':'name', 'view':'prefilled'},{'name':'username', 'view':'not_prefilled', 'description':'Username','type':'text'},{'name':'password', 'view':'not_prefilled', 'description':'Password','type':'text'},{'name':'lastname', 'description':'Last name','type':'text'},{'name':'email'},{'name':'accountnumber', 'description': ' Account number','type':'text'}]" onvalidate="validate_async" redirect-uri="https://domain.com/fbregister.aspx"></fb:registration>

<script> 
function validate_async(form, cb) {

    tmp = form.accountnumber;
    tmp = tmp.split("-");

    if (tmp.length != 2) {
        cb({'accountnumber': 'Please include the dash in your account number. Example: xxxxx-xxxxxx.'});
    } 

    if (form.username) {

        if (form.username.length > 0) {

            $.getJSON('checkUsernameExists.aspx?username=' + form.username, 
                function(response) {
                    if (response.error) {
                        cb({username: 'That username is taken'});
                    }
                    cb();
            });

        }

    } else {
        cb();
    }

}
</script> 
data = ClientSite.Classes.Facebook.DecodeFacebookRequest(HttpContext.Current.Request.Form("signed_request"), FBSecret)

Response.Write(data)