开发者

after_filter in devise

I would like to execute an action after the user has logged in. I need something like:

after_filter :log_l开发者_如何学运维ogin

The method should be called as soon as the user has logged in.


You could try inheriting the sessions controller, and add more of your custom login proc. http://github.com/zmbmartin/devise-roles-user-management. I use this as an example, it inherit registration controller, not example the same, but the principle is the same.


As already answered here:

Devise uses Warden behind the scenes and Warden supplies you with a number of callbacks:

https://github.com/hassox/warden/wiki/callbacks

Have a look at the after_authentication callback. That's what you are looking for.

Code:

Warden::Manager.after_authentication do |user, auth, opts|
  # your code here.. 
end

You can simply put that code into an initializer (eg. config/initializers/warden_callback.rb)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜