Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails + Devise - Authenticate method in custom controller

Is there an equivalent to the Authenticate method from RestfulAuthentication, like so?

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

I have a custom controller i use for authenticating a mobile request, where the email/password come from the url, like http://localhost:3000/iphone/auth/[email protected]/mypassword

like image 390
Frexuz Avatar asked Jan 29 '11 18:01

Frexuz


People also ask

How does devise authentication work?

Devise is an excellent authentication system made for Rails that allows us to easily drop-in User functionality into our project. Devise only includes an email and password for registration, let's also add our own username to our User model. We also want to have a unique index on our username.

Does devise work with Rails 7?

Our out-of-the box Devise setup is now working with Rails 7. Once again, if you'd like to refer to any of the code for this setup, or use the template wholesale for a new app, the code is available on GitHub, and you may also use it as a template repo to kick off your own Rails 7 devise projects.


1 Answers

Maybe you can use something like this:

user = User.find(:first, :conditions => ["email = ?", @email])
user.valid_password?(@password) unless user.nil?
like image 192
Matteo Alessani Avatar answered Oct 18 '22 04:10

Matteo Alessani