AuthLogic login page: undefined method `login' and `password'

I have an application that allows multiple email addresses per user, each of which works as a login for a single account. As such, the user table has no login field, but instead has_many :emails, each of which includes an address field.

I'm using AuthLogic for this, as I've had some success with it in the past. Unfortunately, AuthLogic is not behaving as well in my app as in the examples.

I start with: class UserSession < AuthLogic::Session::Base   find_by_login_method :find_by_email end (with an appropriate find_by_email(address) function defined in user.rb)

First, Rails won't serve the login page: undefined method `login' for #<UserSession: no credentials provided>

If I add to user_session.rb a method: def login; @login; end, it instead complains about password: undefined method `password' for #<UserSession: no credentials

I can provide both, and the page loads, but then when I submit (with ANY value in the fields), I get the following validation error:

1 error prohibited this user session from being saved There were problems with the following fields: You did not provide any details for authentication.

My user_sessions_controller.rb is pretty much the default given in the authlogic example app.

I know it shouldn't be necessary for me to write in a def login and def password method in user_session.rb. I gather that I've made some trivial mistake, but have no idea where to look and can find no tips anywhere in the Googleverse.

Many thanks! John

Check your routes to make sure you've configured the login correctly:

rake routes

Hi Lee, and thanks so much for your reply.

I checked over my routes, and I think I have resolved a few issues that might have been preventing the login page from working correctly -- but alas, not all of them. I'm still getting exactly the same problems when serving the login page.

One issue is that I don't create new users through the UsersController, but rather through PeopleController (each User belongs_to :person). I have in UsersController's new and create methods simple redirects to equivalent methods in PeopleController.

Otherwise, here is a sample of my routes.rb file. I admit that I am behind on my understanding of this config compared to other elements of rails.

ActionController::Routing::Routes.draw do |map|   map.resource :account, :controller => "users" # this formerly pointed to people instead of users   map.resources :users

  map.resources :pages

  begin     Page.all.each do |page|       Rails.logger.info("Connecting page #{page.title}")       map.connect page.slug, :controller => 'pages', :action => 'show', :id => page.id     end   rescue     Rails.logger.error("Could not connect Page routes")   end

  # ... other normal resources ...

  map.resources :people

  map.resources :password_resets

  map.resource :user_session   # map.resources :user_sessions # I just removed this one

  map.login 'login', :controller => 'user_sessions', :action => 'new'   map.logout 'logout', :controller => 'user_sessions', :action => 'destroy'

  # Set default root   map.root :controller => "people", :action => "new"

  # 404: Not found has ID 404   begin     not_found_page = Page.find 404     unless not_found_page.nil?       map.error '*url', :controller => 'pages', :action => 'show', :id => 404     end   rescue     Rails.logger.error("Could not connect 404 Page route")   end

  # Install the default routes as the lowest priority.   # Note: These default routes make all actions in every controller accessible via GET requests. You should   # consider removing or commenting them out if you're using named routes and resources.   map.connect ':controller/:action/:id'   map.connect ':controller/:action/:id.:format' end

Again, thanks for your assistance.

John

For the record, I believe I have discovered the problem.

Authlogic absolutely requires that there be a login field of some sort in the User model -- even if you don't actually use it for logging in. It also needs to contain some unique value, presumably, or there will be validation problems. I simply used the email address people sign up with initially, and also keep a copy of that in the emails table.

I assume this is a bug of some sort. It'd be great if Authlogic were more informative with its error messages; without a login field, it produces all kinds of unrelated errors.

Thanks so much for the help.

John

John Woods wrote:

For the record, I believe I have discovered the problem.

Authlogic absolutely requires that there be a login field of some sort in the User model -- even if you don't actually use it for logging in.

No. Authlogic is smart enough to use email if login doesn't exist. Further configuration is probably possible; check the docs.

It also needs to contain some unique value, presumably, or there will be validation problems.

Well, yes, Authlogic expects that the username or e-mail address will actually be in the users table. :slight_smile:

I simply used the email address people sign up with initially, and also keep a copy of that in the emails table.

You shouldn't need to keep the same data in two places. Try reworking your associations or your Authlogic configuration.

I assume this is a bug of some sort. It'd be great if Authlogic were more informative with its error messages; without a login field, it produces all kinds of unrelated errors.

Thanks so much for the help.

John

Best,