安装后,我想通过用户名或电子邮件获取用户在API会话
我将login传递给参数,但rails显示错误
User.find_for_database_authentication(:login => params[:username][:email])
在模型上覆盖find_for_database_authentication已经完成。
def self.find_for_database_authentication(warden_conditions)
有人能给点提示吗?
设计
class Api::SessionsController < Devise::SessionsController
respond_to :json
def create
resource = User.find_for_database_authentication(:login => params[:username][:email])
if resource.valid_password?(params[:login][:password])
sign_in(:user, resource)
render :json=> {:auth_token=>resource.authentication_token, :email=>resource.email}, :status => :ok
return
end
invalid_login_attempt
end
end
2条答案
按热度按时间k4ymrczo1#
我通过像这样重写
find_for_database_authentication
来做到这一点:不需要更多了。
a64a0gku2#
试试这个:
User.find_by(username: 'username')
或User.find_by(email: ' [[email protected]](https://stackoverflow.com/cdn-cgi/l/email-protection) ')