我使用带有重写控制器Sessions和方法create的Devise进行Ajax登录
class SessionsController < Devise::SessionsController
def create
resource = User.find_for_database_authentication(email: params[:user][:email])
unless resource
render json: 0
end
if resource.valid_password?(params[:user][:password])
sign_in :user, resource
return render json: 1
end
end
end登录运行良好,但如果我尝试使用错误的密码,它不会递增列failed_attempts。
我在模型User中有:lockable,在表中有所有列。失败的尝试可以在不覆盖类Sessions的情况下正常工作。
我知道,我需要使用一些方法或覆盖find_for_database_authentication方法,但我不知道这个方法的名称是什么。
发布于 2018-11-27 01:09:08
尝尝这个。
if resource.valid_for_authentication?{resource.valid_password?(params[:user][:password])}https://stackoverflow.com/questions/46391685
复制相似问题