我正在为我正在开发的web应用程序构建一个API,而我尝试用于API身份验证/登录的以下代码在授权时返回false。
在我的API用户控制器中,我有:
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即使提供了有效的电子邮件和密码,它也始终以@auth作为响应,这是假的。从我的Mongo数据库中获取用户信息没有任何问题。
我想我只是不清楚.authenticate是做什么的。根据我观看的一段railscast.com视频,它应该将用户的密码摘要与输入的密码进行比较。为用户提供有效密码时,@auth始终为false。
发布于 2012-06-22 02:57:02
这个方法实际上工作得很好,数据库中的测试数据并不是我想的那样。
https://stackoverflow.com/questions/11132617
复制相似问题