2017-07-24 20 views
0

我创建了会话控制器,我正在关注this如何修改会话控制器以使用可锁定策略?

我在模型中已经添加可锁定策略和运行rails db:migrate

我不想使用warden.authenticate 我读了色器件文档,可锁定策略,找到方法valid_for_authentication更新失败的尝试。

我该如何使用valid_for_authentication? 我只是跳过sign_in,如果它是零,但我想更新失败的尝试。我错过了什么方法?

def create 
    @user = User.authenticate(params[:user][:email], params[:user][:password]) 
    sign_in(:user, @user) if @user&.valid_for_authentication? 
    redirect_to root_path 
end 

回答

0

那么,我刚刚通过筛选相关的来源here。据我所知,使用@user&.valid_for_authentication?将增加failed_attempts计数器并锁定帐户,如果超过登录尝试的次数。所以这应该是开箱即用的。如果你想测试它,我建议使用rails console

+0

是的,它必须这样做,但没有任何反应,因为用户在通过错误密码或电子邮件时为零 –