class FbSessionsController

Login a través de Facebook

Documentación: veerasundaravel.wordpress.com/2010/11/23/facebook-connect-in-rails-using-facebooker-gem/ Facebook OAuth on Rails: www.wisejive.com/2010/05/facebook-oauth-on-rails.html

Attributes

facebook_settings[RW]

Public Instance Methods

create() click to toggle source

Conectarse a www.facebook.com/dialog/oauth?client_id=YOUR_APP_ID&redirect_uri=YOUR_URL Esto hace el login y luego redirect a YOUR_URL?code=A_CODE_GENERATED_BY_SERVER

# File app/controllers/fb_sessions_controller.rb, line 35
def create
  session[:return_to] = params[:return_to] || request.env['HTTP_REFERER']
  
  redirect_to "https://graph.facebook.com/oauth/authorize?client_id=#{facebook_settings[RAILS_ENV]['application_id']}&redirect_uri=#{callback_url}"
  
end
finalize() click to toggle source

Terminar el login: aquí tenemos params. Llamamos la función get_user_profile para completar el login

# File app/controllers/fb_sessions_controller.rb, line 45
def finalize    
  if not params[:code].nil?
    profile = get_user_profile
    
    logger.info " FFFFFFFFFFFFF error: #{profile[:error]}"
    
    if profile[:error].present?
      flash[:notice] = t('session.no_hemos_podido_confirmar_el_fb_login')
      redirect_back_or_default(root_path) and return
    else
      user = Person.find_or_initialize_by_fb_id(profile[:fb_id])
    
      if user.new_record?
        user.update_attributes(profile.merge({:status => "aprobado"}))
        self.current_user = user
        flash[:notice] = t('session.Has_entrado', :name => current_user.name)
        redirect_back_or_default(root_path) and return
      else
        if user.status.eql?("pendiente")
          render :template => "/sessions/waiting_for_approval" and return
        elsif user.status.eql?("vetado")
          flash[:notice] = "Este usuario ha sido eliminado"
          redirect_to root_path and return
        else
          self.current_user = user
          flash[:notice] = t('session.Has_entrado', :name => current_user.name)
          redirect_back_or_default(root_path) and return
        end
        session[:return_to] = nil
      end
    end
  end
  
end