find_for_database_authentication is never executed when attempting to log in with only username

618 views
Skip to first unread message

jiml

unread,
Feb 3, 2014, 2:26:19 PM2/3/14
to plataforma...@googlegroups.com
I've followed the instructions on allowing someone to log in with just their username: https://github.com/plataformatec/devise/wiki/How-To:-Allow-users-to-sign-in-using-their-username-or-email-address

However now I can never authenticate.  I would think that warden.authenticate! would pass execution down to devise/strategies/authenticatable/DatabaseAuthenticatable.authenticate! since the instructions tell me that I need to over write find_for_database_authentication  - https://github.com/plataformatec/devise/wiki/How-To:-Allow-users-to-sign-in-using-their-username-or-email-address#wiki-overwrite-devises-find_for_database_authentication-method-in-user-model

But find_for_database_authentication is never called.

Any ideas?


Thanks
Jim 

Lucas Mazza

unread,
Feb 3, 2014, 3:06:17 PM2/3/14
to plataforma...@googlegroups.com
Are you providing a valid password? This method is only called when the resource has a valid password so Devise won't hit your database on failed attempts. If you provide some more information about your app or some snippet of code we might be able to provide more insights to you.


--
 
---
You received this message because you are subscribed to the Google Groups "Devise" group.
To unsubscribe from this group and stop receiving emails from it, send an email to plataformatec-de...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

jiml

unread,
Feb 3, 2014, 3:10:45 PM2/3/14
to plataforma...@googlegroups.com
Here's a gist showing what I have  - https://gist.github.com/jimlyndon/6d647d226d9c1dc01cef


Thanks for any ideas

Jim

jiml

unread,
Feb 3, 2014, 3:12:04 PM2/3/14
to plataforma...@googlegroups.com
So the user has to supply a password as well?  Okay, I thought this was an option to just allow a user to use an email/username without password.  That's probably my problem

Lucas Mazza

unread,
Feb 3, 2014, 3:14:12 PM2/3/14
to plataforma...@googlegroups.com
Yeah, that would be your case. Also, I suggest that you override "find_first_by_auth_conditions" instead since that is method suggested by the tutorial. ("find_for_database_authentication" is only mentioned on the Mongoid example, but I don't know why)


--

jiml

unread,
Feb 3, 2014, 3:51:48 PM2/3/14
to plataforma...@googlegroups.com
Thanks for the help Lucas,

I used your suggestions and everything is working correctly now.


Cheers!
Jim
Reply all
Reply to author
Forward
0 new messages