I’m building an API for a web app I’m developing, and the following code I’m trying to use for API authentication/login is returning false on the authorization.
In my API user controller I have:
def login
if params[:user]
# Find the user by email first
@user = User.where(email: params[:user][:email]).first
if !@user
respond_with nil
else
@auth = @user.authenticate(params[:user][:password])
if @auth
respond_with @user
else
respond_with @auth
end
end
end
end
It is always responding with @auth, which is false, even when valid email and passwords are being provided. It has no problem pulling the user info from my Mongo db.
I guess I’m just not clear on what .authenticate does. According to a railscast.com video I watched, it should compare that users password digest with the password entered. When a valid password is provided for the user, @auth is always false.
This method was actually working fine, the test data in the database wasn’t what i thought it was..