在 Rails 使用 Devise gem 时,如何记录失败的登录和锁定?
In Rails when using the Devise gem, how to log failed logins and lockups?
我使用 Devise
来处理我的应用程序中的身份验证,并使用 public_activity
来记录事情和日志。现在我需要在发生登录失败和帐户被锁定时在日志中添加一条记录。我该怎么做?
您可以使用 Warden 的 after_authentication
挂钩,因为设计是基于 warden 构建的。把这个放在 config/initializers/devise_hooks.rb
:
Warden::Manager.after_authentication do |user, auth, opts|
# do something with user
end
中的详细信息
我使用 Devise
来处理我的应用程序中的身份验证,并使用 public_activity
来记录事情和日志。现在我需要在发生登录失败和帐户被锁定时在日志中添加一条记录。我该怎么做?
您可以使用 Warden 的 after_authentication
挂钩,因为设计是基于 warden 构建的。把这个放在 config/initializers/devise_hooks.rb
:
Warden::Manager.after_authentication do |user, auth, opts|
# do something with user
end
中的详细信息