lib/frikandel/limit_session_lifetime.rb in frikandel-2.0.0 vs lib/frikandel/limit_session_lifetime.rb in frikandel-2.1.0

- old
+ new

@@ -3,24 +3,38 @@ extend ActiveSupport::Concern include SessionInvalidation included do append_before_filter :validate_session_timestamp - append_after_filter :persist_session_timestamp end private def validate_session_timestamp - if session.key?(:ttl) && session.key?(:max_ttl) && (session[:ttl] < Frikandel::Configuration.ttl.ago || session[:max_ttl] < Time.now) + if session.key?(:ttl) && session.key?(:max_ttl) && (reached_ttl? || reached_max_ttl?) on_invalid_session - elsif !session.key?(:ttl) && !session.key?(:max_ttl) + elsif !session.key?(:ttl) || !session.key?(:max_ttl) reset_session + else # session timestamp is valid + persist_session_timestamp end end + def reached_ttl? + session[:ttl] < Frikandel::Configuration.ttl.ago + end + + def reached_max_ttl? + session[:max_ttl] < Time.now + end + def persist_session_timestamp session[:ttl] = Time.now - session[:max_ttl] ||= Frikandel::Configuration.max_ttl.from_now + session[:max_ttl] ||= Frikandel::Configuration.max_ttl.since + end + + def reset_session + super + persist_session_timestamp end end end