module Authlogic::Session::MagicColumns::InstanceMethods

The methods available for an Authlogic::Session::Base object that make up the magic columns feature.

Private Instance Methods

clear_failed_login_count() click to toggle source
# File lib/authlogic/session/magic_columns.rb, line 51
def clear_failed_login_count
  if record.respond_to?(:failed_login_count)
    record.failed_login_count = 0
  end
end
increase_failed_login_count() click to toggle source
# File lib/authlogic/session/magic_columns.rb, line 57
def increase_failed_login_count
  if invalid_password? && attempted_record.respond_to?(:failed_login_count)
    attempted_record.failed_login_count ||= 0
    attempted_record.failed_login_count += 1
  end
end
increment_login_cout() click to toggle source
# File lib/authlogic/session/magic_columns.rb, line 64
def increment_login_cout
  if record.respond_to?(:login_count)
    record.login_count = (record.login_count.blank? ? 1 : record.login_count + 1)
  end
end
last_request_at_threshold() click to toggle source
# File lib/authlogic/session/magic_columns.rb, line 125
def last_request_at_threshold
  self.class.last_request_at_threshold
end
set_last_request_at() click to toggle source
# File lib/authlogic/session/magic_columns.rb, line 121
def set_last_request_at
  record.last_request_at = klass.default_timezone == :utc ? Time.now.utc : Time.now
end
set_last_request_at?() click to toggle source

This method lets authlogic know whether it should allow the last_request_at field to be updated with the current time (Time.now). One thing to note here is that it also checks for the existence of a last_request_update_allowed? method in your controller. This allows you to control this method pragmatically in your controller.

For example, what if you had a javascript function that polled the server updating how much time is left in their session before it times out. Obviously you would want to ignore this request, because then the user would never time out. So you can do something like this in your controller:

def last_request_update_allowed?
  action_name != "update_session_time_left"
end

You can do whatever you want with that method.

# File lib/authlogic/session/magic_columns.rb, line 109
def set_last_request_at?
  if !record || !klass.column_names.include?("last_request_at")
    return false
  end
  if controller.responds_to_last_request_update_allowed? &&
      !controller.last_request_update_allowed?
    return false
  end
  record.last_request_at.blank? ||
    last_request_at_threshold.to_i.seconds.ago >= record.last_request_at
end
update_info() click to toggle source
# File lib/authlogic/session/magic_columns.rb, line 70
def update_info
  increment_login_cout
  clear_failed_login_count
  update_login_timestamps
  update_login_ip_addresses
end
update_login_ip_addresses() click to toggle source
# File lib/authlogic/session/magic_columns.rb, line 77
def update_login_ip_addresses
  if record.respond_to?(:current_login_ip)
    record.last_login_ip = record.current_login_ip if record.respond_to?(:last_login_ip)
    record.current_login_ip = controller.request.ip
  end
end
update_login_timestamps() click to toggle source
# File lib/authlogic/session/magic_columns.rb, line 84
def update_login_timestamps
  if record.respond_to?(:current_login_at)
    record.last_login_at = record.current_login_at if record.respond_to?(:last_login_at)
    record.current_login_at = klass.default_timezone == :utc ? Time.now.utc : Time.now
  end
end