Module: FbGraphRails::FbActionControllerExtension::InstanceMethods
- Defined in:
- lib/fb_graph_rails/fb_action_controller_extension.rb
Overview
module
Instance Method Summary collapse
- #authenticate(user) ⇒ Object
- #authenticated? ⇒ Boolean
- #current_user ⇒ Object
- #fb_auth_required ⇒ Object
- #require_authentication ⇒ Object
- #unauthenticate ⇒ Object
Instance Method Details
#authenticate(user) ⇒ Object
34 35 36 37 |
# File 'lib/fb_graph_rails/fb_action_controller_extension.rb', line 34 def authenticate(user) raise Unauthorized unless user session[:current_user] = user.id end |
#authenticated? ⇒ Boolean
50 51 52 |
# File 'lib/fb_graph_rails/fb_action_controller_extension.rb', line 50 def authenticated? !current_user.blank? and current_user.fb_profile rescue false end |
#current_user ⇒ Object
44 45 46 47 48 |
# File 'lib/fb_graph_rails/fb_action_controller_extension.rb', line 44 def current_user @current_user ||= self.class.fb_model.find(session[:current_user]) rescue ActiveRecord::RecordNotFound nil end |
#fb_auth_required ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/fb_graph_rails/fb_action_controller_extension.rb', line 13 def fb_auth_required unless self.authenticated? auth = self.class.fb_auth auth.from_signed_request(params[:signed_request]) unless params[:signed_request].blank? if auth. authenticate self.class.fb_model.identify(auth.user) return true else url = auth.(self.class.fb_canvas_url, :scope => self.class.fb_auth_scope).html_safe return render :inline => "<script>top.location.href = '#{url}';</script>" end end end |
#require_authentication ⇒ Object
28 29 30 31 32 |
# File 'lib/fb_graph_rails/fb_action_controller_extension.rb', line 28 def require_authentication authenticate self.class.fb_model.find_by_id(session[:current_user]) rescue Unauthorized => e redirect_to root_url and return false end |
#unauthenticate ⇒ Object
39 40 41 42 |
# File 'lib/fb_graph_rails/fb_action_controller_extension.rb', line 39 def unauthenticate current_user.destroy @current_user = session[:current_user] = nil end |