Class/Module Index [+]

Quicksearch

Authlogic::Session::Validation

Responsible for session validation

Public Instance Methods

attempted_record() click to toggle source

You should use this as a place holder for any records that you find during validation. The main reason for this is to allow other modules to use it if needed. Take the failed_login_count feature, it needs this in order to increase the failed login count.

# File lib/authlogic/session/validation.rb, line 28
def attempted_record
  @attempted_record
end
attempted_record=(value) click to toggle source

See attempted_record

# File lib/authlogic/session/validation.rb, line 33
def attempted_record=(value)
  @attempted_record = value
end
errors() click to toggle source

The errors in Authlogic work JUST LIKE ActiveRecord. In fact, it uses the exact same ActiveRecord errors class. Use it the same way:

Example

class UserSession
  before_validation :check_if_awesome

  private
    def check_if_awesome
      errors.add(:login, "must contain awesome") if login && !login.include?("awesome")
      errors.add(:base, "You must be awesome to log in") unless attempted_record.awesome?
    end
end
# File lib/authlogic/session/validation.rb, line 51
def errors
  @errors ||= Errors.new(self)
end
valid?() click to toggle source

Determines if the information you provided for authentication is valid or not. If there is a problem with the information provided errors will be added to the errors object and this method will return false.

# File lib/authlogic/session/validation.rb, line 58
def valid?
  errors.clear
  self.attempted_record = nil
  
  before_validation
  new_session? ? before_validation_on_create : before_validation_on_update
  validate
  ensure_authentication_attempted
          
  if errors.size == 0
    new_session? ? after_validation_on_create : after_validation_on_update
    after_validation
  end
  
  save_record(attempted_record)
  errors.size == 0
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.