#30 ✓ resolved
David Baldwin

Alternate primary key in User model

Reported by David Baldwin | January 23rd, 2009 @ 12:55 AM

My User class has a primary key of "uid" rather than "id". I think that a hard-coded "find_by_id" in Authlogic::Session::Session is the problem. I changed to "find_by_#{klass.primary_key}" in github.com/bilson/authlogic and it seemed to fix the issue. Below is the code with the revision.

authlogic/lib/authlogic/session/session.rb


# Tries to validate the session from information in the session
def valid_session?
  persistence_token, record_id = session_credentials
  if !persistence_token.blank?
    if record_id
      record = search_for_record("find_by_#{klass.primary_key}", record_id)
      self.unauthorized_record = record if record && record.send(persistence_token_field) == persistence_token
    else
      # For backwards compatibility, will eventually be removed, just need to let the sessions update theirself
      record = search_for_record("find_by_#{persistence_token_field}", persistence_token)
      if record
        controller.session["#{session_key}_id"] = record.send(record.class.primary_key)
        self.unauthorized_record = record
      end
    end
    valid? && !stale?
  else
    false
  end
end

Best Regards,

David Baldwin

Comments and changes to this ticket

  • Ben Johnson

    Ben Johnson January 23rd, 2009 @ 01:14 AM

    • State changed from “new” to “resolved”

    Good call, I updated this and pushed the changes to the repo. Just update from the repo, let me know if you have any other problems.

  • David Baldwin

    David Baldwin January 23rd, 2009 @ 01:28 AM

    Great. Thanks Ben. As you may have guessed, this is a legacy db, so I'm expecting to run into a few obstacles along the way. I'll let you know if I hit on anything else.

    Best Regards, David Baldwin

  • Ben Johnson

    Ben Johnson January 23rd, 2009 @ 01:30 AM

    sounds good, let me know, i dont think you will have any other issues though, the other fields are configurable, but let me know if you do ahve any probs.

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

Object based authentication solution that handles all of the non sense for you. It's as easy as ActiveRecord is with a database.

People watching this ticket

Tags

Pages