Sha256: 65f49ee950b48e9363b92af35a35bbf7541373bffd83ec5cb0084566ffdf4d82

Contents?: true

Size: 1.39 KB

Versions: 2

Compression:

Stored size: 1.39 KB

Contents

#Here I've written the code to offer methods to simplify FB connections, like login links for example
#OR methods required outside of the facebook controller inside the gem

def parse_fb_cookie
  return MiniFB.parse_cookie_information FB_APP_ID, cookies
end

def user_from_fb?
  if signed_in? then
  return !current_user.fbid.blank? #If that's not blank then its a FB user
  else return false end
end

#Si da false entonces el usuario se le deniega el acceso
def authenticated_fbu?
  @fbcookie = parse_fb_cookie
  if @fbcookie.nil? then return false end
  begin
    @uid = MiniFB.rest(@fbcookie["access_token"], "users.getLoggedInUser", {})
    if @uid.to_hash["response"] == current_user.fbid then return true else return false end 
  rescue MiniFB::FaceBookError #Is this error happen the token expired
    return false
  end
  #The user is authenticated if the UID than own the token is the same as the one in current user
end

def delete_fb_cookie
  cookies.delete("fbs_#{FB_APP_ID}".to_sym)
end


def facebook_js
  render :partial => "facebook/fbjs"
end

#only shows the login button if there's no logged in user
def facebook_login
    return "<fb:login-button></fb:login-button>"
end

def fb_signed_in?
  if parse_fb_cookie.nil? then return false else return true end
end

#TBD: Save the url in the DB. 50x50 px
def facebook_pic_url
  return "http://graph.facebook.com/#{current_user.fbid}/picture?type=square"
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
fbdoorman-0.0.2 lib/facebook_helpers.rb
fbdoorman-0.0.1 lib/facebook_helpers.rb