authlogic custom conditions for authentication

>To Add custom conditions to authlogic finders first of all we need to override authlogic find_by_login method.

class UserSession < Authlogic::Session::Base
  after_validation :check_if_verified
  find_by_login_method :find_by_login_and_deleted_method
end

Then we need to define overridden method inside User model

class User < ActiveRecord::Base
  acts_as_authentic
  def self.find_by_login_and_deleted_method(login)
    find_by_email_and_deleted(login, false)
  end
end

got easy..wooooooo 🙂

2 thoughts on “authlogic custom conditions for authentication

  1. I had a similar issue and I found the same solution but I’m having problem while passing two arguments to the overriden method.

    I want to pass one more argument which is necessary for finding the user.
    I can’t access or get that parameter in model.

    Please let me know if you have some solution to it.

    1. Hi Nitin,
      First, you need to change model method to accept second parameter. I guess you already made those changes. Regarding not able to access second parameter in model, How you passing second parameter from controller..?

      Wherever find_by_login is used, change it to pass second parameter –
      User.find_by_login(param1, param2)

Leave a Reply

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

WordPress.com Logo

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

Google photo

You are commenting using your Google 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

This site uses Akismet to reduce spam. Learn how your comment data is processed.