0
我正在为正在开发的Web应用程序构建一个API,并且我正尝试使用API验证/登录的以下代码在授权上返回false。Ruby on Rails .authentication失败
在我的API用户控制器我有:
def login
if params[:user]
# Find the user by email first
@user = User.where(email: params[:user][:email]).first
if [email protected]
respond_with nil
else
@auth = @user.authenticate(params[:user][:password])
if @auth
respond_with @user
else
respond_with @auth
end
end
end
end
它总是与@auth,这是假的,即使正在提供有效的电子邮件地址和密码响应。从我的Mongo数据库中抽取用户信息没有任何问题。
我想我只是不清楚什么.authenticate。根据我观看的一个railscast.com视频,应该将用户密码摘要与输入的密码进行比较。当为用户提供有效密码时,@auth始终为false。
这是来自railscast#250吗?如果是这样,你是否也需要将电子邮件传递给验证功能? –