Module: RPlatform::Rails::SessionStoreExtensions

Defined in:
lib/rplatform_rails/session_extensions.rb

Overview

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



192
193
194
195
196
# File 'lib/rplatform_rails/session_extensions.rb', line 192

def self.included(base) # :nodoc:
  base.class_eval do
    alias_method_chain :initialize, :rplatform
  end
end

Instance Method Details

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

:section: Base Overrides



160
161
162
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
# File 'lib/rplatform_rails/session_extensions.rb', line 160

def initialize_with_rplatform(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_without_rplatform(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_without_rplatform(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_without_rplatform(session, options, *extraParams)
    
  end
end