Module: RFacebook::Rails::SessionStoreExtensions

Defined in:
lib/rfacebook_on_rails/session_extensions.rb

Overview

Module: SessionStoreExtensions

Special initialize method that attempts to force any session store to use the Facebook session

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object

:section: Extension Helpers



195
196
197
198
199
200
# File 'lib/rfacebook_on_rails/session_extensions.rb', line 195

def self.included(base) # :nodoc:
  base.class_eval'
    alias :initialize__ALIASED :initialize
    alias :initialize :initialize__RFACEBOOK
  '
end

Instance Method Details

#initialize__RFACEBOOK(session, options, *extraParams) ⇒ Object

:section: Base Overrides



163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# File 'lib/rfacebook_on_rails/session_extensions.rb', line 163

def initialize__RFACEBOOK(session, options, *extraParams) # :nodoc:
  
  if session.using_facebook_session_id?
    
    # we got the fb_sig_session_key, so alter Rails' behavior to use that key to make a session
    begin
      RAILS_DEFAULT_LOGGER.debug "** RFACEBOOK INFO: using fb_sig_session_key for the #{self.class.to_s} session (session_id=#{session.session_id})"
      initialize__ALIASED(session, options, *extraParams)
    rescue Exception => e 
      begin
        RAILS_DEFAULT_LOGGER.debug "** RFACEBOOK INFO: failed to initialize session (session_id=#{session.session_id}), trying to force a new session"
        if session.session_id
          session.force_to_be_new!
        end
        initialize__ALIASED(session, options, *extraParams)
      rescue Exception => e
        RAILS_DEFAULT_LOGGER.debug "** RFACEBOOK INFO: failed to force a new session, falling back to default Rails behavior"
        raise e
      end
    end
    
  else
    
    # we didn't get the fb_sig_session_key, do not alter Rails' behavior
    RAILS_DEFAULT_LOGGER.debug "** RFACEBOOK INFO: using default Rails sessions (since we didn't find an fb_sig_session_key in the environment)"
    initialize__ALIASED(session, options, *extraParams)
    
  end
end