本文介绍了设计回调的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



这是我想出的:



  Warden :: Manager.after_authentication do | user,auth,opts | 
user.update_attribute(:currently_signed_in,true)
end

Warden :: Manager.before_logout do | user,auth,opts |
user.update_attribute(:Currently_signed_in,false)
end

这是什么我来跟踪目前登录的用户。

解决方案

我不是专家,但我相信回调(hooks)在监狱长级别(Devise建在监狱长之上)。



after_set_user和before_logout在Warden应该为你做的伎俩,但还有其他选项列在


Does devise have call backs when a user signs in and out?

This is what I came up with:

Warden::Manager.after_authentication do |user,auth,opts|
  user.update_attribute(:currently_signed_in, true)
end

Warden::Manager.before_logout do |user,auth,opts|
  user.update_attribute(:currently_signed_in, false)
end

This is what I came with to track users that are currently signed in.

解决方案

I'm no expert but I believe the callbacks (hooks) are at the Warden level (Devise is built on top of Warden).

after_set_user and before_logout in Warden should do the trick for you but there are other options listed in Warden::Hooks

这篇关于设计回调的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-09 14:07