Gem devise 的几个回调方法

foxzool · 2012年03月12日 · 最后由 fsword 回复于 2012年03月12日 · 3076 次阅读

严格的来说是 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,要不我们下周说说这个?

需要 登录 后方可回复, 如果你还没有账号请 注册新账号