Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retrieve user using credentials #346

Closed
ghost opened this issue Jun 25, 2010 · 6 comments
Closed

Retrieve user using credentials #346

ghost opened this issue Jun 25, 2010 · 6 comments

Comments

@ghost
Copy link

ghost commented Jun 25, 2010

I have been trying to figure this out for a number of hours and getting nowhere. I basically need to be able to retrieve a user instance based on email and password. I would normally do something like this with Restful Auth

user = User.authenticate('email', 'password')

...however I can't find the equivalent with devise. There may be a different user logged in at this stage who I want to leave logged in and just retrieve another user based on credentials but not affect the session.

@carlosantoniodasilva
Copy link
Member

Yes, there is find_for_authentication.
http:/plataformatec/devise/blob/master/lib/devise/models/authenticatable.rb#L92
Please use the mailing list for questions and doubts.

@ghost
Copy link
Author

ghost commented Jun 25, 2010

Apologies, I didn't know there was a mailing list, do you have a link to it?

find_for_authentication just does a find based on attributes, I need a way to determine if the returned user's password is correct.

@carlosantoniodasilva
Copy link
Member

Here is the mailing list: http://groups.google.com/group/plataformatec-devise.
And yes, after find the resource through find_for_authentication, you can call resource.valid_for_authentication? to check if the user is active or not, and also resource.valid_password?('foo') to check if the password is valid for that given resource.
If it's needed you can wrap all this in you own :authenticate method, pretty similar to your example.

@ghost
Copy link
Author

ghost commented Jun 25, 2010

Many thanks, I will use the mailing list in future.

@geeksam
Copy link

geeksam commented Oct 21, 2011

Spent a good 20 minutes trying to find this information, including wading through the mass of indirection that is the Devise code and looking on the wiki. All I wanted was User.authenticate(identifier, password), not Every Design Pattern Ever Invented(tm). Frustrated now, trying very hard to refrain from using obscenities.

@alpha123
Copy link

I find Google very helpful for this sort of thing, particularly 'site:github.com inurl:/issues ', which in this case is quite helpful.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants