class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
  def passthru
    show_404
    # Or alternatively,
    # raise ActionController::RoutingError.new('Not Found')
  end

  def facebook
    @user = User.find_for_facebook_oauth(request.env["omniauth.auth"], current_user)

    if @user.persisted?
      flash[:notice] = I18n.t "devise.omniauth_callbacks.success", :kind => "Facebook"
      sign_in @user
      #redirect_to user_root_path, :event => :authentication, :current_user => @user # infinite loop
      redirect_to user_obtain_token_path, :event => :authentication, :current_user => @user
    else
      session["devise.facebook_data"] = request.env["omniauth.auth"]
      redirect_to new_user_registration_url
    end
  end

  def failure(env = {})
    #binding.pry
    show_404
  end
end
