如何访问从督导员/设计会议after_authentication Rails中回调 [英] How to access session from Warden/Devise after_authentication callback in Rails

查看:108
本文介绍了如何访问从督导员/设计会议after_authentication Rails中回调的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从守望者访问当前会话 after_authenticate 回调Rails 3中(设计下运行)

I'm trying to access the current session from Warden's after_authenticate callback (running underneath Devise) in Rails 3.

在我想要做这样的事情我的应用程序控制器的顶部:

At the top of my application controller I want to do something like:

Warden::Manager.after_authentication do |user,auth,opts|
  user.associate_with_ids(session[:pending_ids])
end

的最终目标是要采取分别存储在会话记录ID列表注册之前,并将其与用户模型注册后,相关联。

The ultimate goal is to take a list of record IDs that were stored in the session before sign up and associate them with the user model after sign in.

任何帮助将是非常美联社preciated。

Any help would be much appreciated.

推荐答案

auth.session 获取/设置会话密钥数据 warden.user。#{}范围.session

"auth.session" get/sets the data in the session key "warden.user.#{scope}.session".

假设你有你的Rails应用程序中保存pending_ids:

Supposing you had saved pending_ids within your rails app:

session[:pending_ids] = ...

和您在监狱长钩想存取权限,你可以访问这种方式:

and you wanted to acces in the warden hook, you could access it this way:

Warden::Manager.after_authentication do |user,auth,opts|
  user.associate_with_ids(auth.env['rack.session'][:pending_ids])
end

我花了一段时间发现了,所以我想这可能是一些帮助某人。

It took me a while to find that out, so I guess it might be of some help for somebody.

(最初是从diegoscataglini.com/2012/02/09/383/manipulating-sessions-in-wardendevise拍摄,这是现在死了)。

这篇关于如何访问从督导员/设计会议after_authentication Rails中回调的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆