Customizing User login with Authlogic: find_by_login_method

This post would be redundant especially when Devise is the “in” thing but I love the minimality of Authlogic and I’m sure over time I’ll grow to like Devise but for now Authlogic does everything I want.

In a scenario where you want Authlogic to find Users from a subset of users while adhering to a specific condition that you set (for instance: login users from a set of users who have active accounts), you would need to define some kind of condition or scope to find these users.

A simple configuration that Authlogic allows is

class UserSession < Authlogic::Session::Base
  find_by_login_method  :find_by_activated_user

The find_by_login_method identifies the class method that would be called upon the User model to find the user.

In user.rb

  def self.find_by_activated_user(email)
    self.find_by_email_and_activated(email, true)

where activated is a boolean attribute that identifies if a user has been blocked from using the site.

One thought on “Customizing User login with Authlogic: find_by_login_method

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s