Gem devise 的几个回调方法

foxzool · March 12, 2012 · Last by fsword replied at March 12, 2012 · 3076 hits

严格的来说是 warden 的回调方法

需求:我使用 devise 的 token 验证模块,需要在登录时,重置一次 token。

方法:

Warden::Manager.after_authentication do |user,auth,opts|
  user.reset_authentication_token!
end

Warden::Manager.before_logout do |user,auth,opts|
  user.reset_authentication_token!
end


warden 一共有 4 个回调方法

after_set_user
after_authentication
before_failure
before_logout


其中 after_set_user 是在每一次请求 devise 验证时都会调用,所以可以做自己的登录超时机制使用

参考文档:

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

devise 其实挺丰富的,涉及到的 warden 什么也很有谈头,本周还没有组织 ruby tuesday,要不我们下周说说这个?

You need to Sign in before reply, if you don't have an account, please Sign up first.