Module: Authlogic::ORMAdapters::ActiveRecordAdapter::SessionMaintenance
- Defined in:
- lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/session_maintenance.rb
Overview
:nodoc:
Instance Method Summary collapse
Instance Method Details
#acts_as_authentic_with_session_maintenance(options = {}) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/session_maintenance.rb', line 5 def acts_as_authentic_with_session_maintenance( = {}) acts_as_authentic_without_session_maintenance() [:session_class] ||= "#{name}Session" [:session_ids] ||= [nil] before_save :get_session_information, :if => :update_sessions? after_save :maintain_sessions!, :if => :update_sessions? class_eval <<-"end_eval", __FILE__, __LINE__ def save_without_session_maintenance(*args) @skip_session_maintenance = true result = save(*args) @skip_session_maintenance = false result end protected def update_sessions? !@skip_session_maintenance && #{[:session_class]}.activated? && !#{[:session_ids].inspect}.blank? && #{remember_token_field}_changed? end def get_session_information # Need to determine if we are completely logged out, or logged in as another user @_sessions = [] @_logged_out = true #{[:session_ids].inspect}.each do |session_id| session = #{[:session_class]}.find(*[session_id].compact) if session if !session.record.blank? @_logged_out = false @_sessions << session if session.record == self end end end end def maintain_sessions! if @_logged_out create_session! elsif !@_sessions.blank? update_sessions! end end def create_session! # We only want to automatically login into the first session, since this is the main session. The other sessions are sessions # that need to be created after logging into the main session. session_id = #{[:session_ids].inspect}.first # If we are already logged in, ignore this completely. All that we care about is updating ourself. next if #{[:session_class]}.find(*[session_id].compact) # Log me in args = [self, session_id].compact #{[:session_class]}.create(*args) end def update_sessions! # We found sessions above, let's update them with the new info @_sessions.each do |stale_session| stale_session.unauthorized_record = self stale_session.save end end end_eval end |