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

Then we need to define overridden method inside User model

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

got easy..wooooooo 🙂


About sandipransing

Web Developer #ruby #rails #JS
This entry was posted in Ruby on Rails and tagged . Bookmark the permalink.

2 Responses to 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.

    • 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: Logo

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