John Woods
2010-Jan-09 20:47 UTC
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 provided> 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 -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Lee Smith
2010-Jan-10 04:28 UTC
Re: AuthLogic login page: undefined method `login'' and `password''
Check your routes to make sure you''ve configured the login correctly: rake routes -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
John Woods
2010-Jan-10 19:21 UTC
Re: AuthLogic login page: undefined method `login'' and `password''
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
On Jan 9, 10:28 pm, Lee Smith
<autige...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> Check your routes to make sure you''ve configured the login
correctly:
>
> rake routes
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
John Woods
2010-Jan-11 01:57 UTC
Re: AuthLogic login page: undefined method `login'' and `password''
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 On Jan 10, 1:21 pm, John Woods <john.wo...-+ksaPUZU+wsI+954vlgkHg@public.gmane.org> wrote:> 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 > > On Jan 9, 10:28 pm, Lee Smith <autige...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > Check your routes to make sure you''ve configured the login correctly: > > > rake routes-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Marnen Laibow-Koser
2010-Jan-11 17:58 UTC
Re: AuthLogic login page: undefined method `login'' and `pas
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. :)> 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. > > JohnBest, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/. --0022158df84fca0b14047ce74815 Content-Type: text/plain; charset=ISO-8859-1 -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. --0022158df84fca0b14047ce74815--