Facebook通过Javascript登录

时间:2017-01-31 21:06:06

标签: ruby-on-rails ruby-on-rails-4 devise omniauth-facebook

我已在同一页面使用facebook弹出窗口成功登录。

我已经检查了回复response.status === 'connected'并确实已经成功了。

 $('#sign_in').on('click', function (e) {
        e.preventDefault();

        FB.login(function(response){

        });

        FB.getLoginStatus(function(response) {
            statusChangeCallback(response);
        });

        function statusChangeCallback(response) {

            if (response.status === 'connected') {
                // Logged into your app and Facebook.
            } else if (response.status === 'not_authorized') {
                // The person is logged into Facebook, but not your app.
            } else {
                // The person is not logged into Facebook, so we're not sure if
                // they are logged into this app or not.
            }
        }


    }); 

现在,问题是,我如何主动登录设计? 我已经将路线设置为:

devise_for :users, :controllers => { :omniauth_callbacks => "callbacks" }

我添加了回调控制器:

class CallbacksController < Devise::OmniauthCallbacksController

  def facebook

    puts "FACEBOOK CALLBACK"
    # You need to implement the method below in your model (e.g. app/models/user.rb)
    @user = User.from_omniauth(request.env["omniauth.auth"])

    if @user.persisted?
      sign_in_and_redirect @user, :event => :authentication #this will throw if @user is not activated
      set_flash_message(:notice, :success, :kind => "Facebook") if is_navigational_format?
    else
      session["devise.facebook_data"] = request.env["omniauth.auth"]
      redirect_to new_user_registration_url
    end
  end

  def failure
    redirect_to root_path
  end

end

但是我注意到没有调用回调,请建议!

修改 以下是facebook上测试应用程序的基本设置: enter image description here

0 个答案:

没有答案