Rails 3设计确认过滤器 [英] Rails 3 Devise confirmation filter
问题描述
我想知道是否可以选择性地要求使用Devise确认某些控制器的操作。
I'm wondering if it's possible to selectively require confirmation for certain controller actions using Devise.
基本上:我希望用户注册一个帐户触发确认电子邮件),自动登录,并且能够立即浏览网站的某些部分作为登录(但仍未确认)用户。访问某些区域(例如付款)将要求用户首先确认其电子邮件。
Basically: I want users to sign up for an account (which will trigger a confirmation email), be automatically logged in, and be able to immediately explore certain parts of the site as a signed in (but still unconfirmed) user. Access to certain areas (e.g., payment) would require the user to first confirm their email.
我希望像 before_filter:user_is_confirmed,only:[payment_related_stuff]
我搜索了一段时间,找不到办法所以我认为创建一个hacky解决方案,其中所有可能的保护区域仍然需要 before_filter:authenticate!
,但是我将覆盖Devise SessionsController的创建允许访问在某些地区确认前。但是,我不知道这是否是正确的方法。
I searched for a while and could not find a way to do this out of the box, so I thought creating a hacky solution in which all possibly protected areas would still require before_filter: authenticate!
, but I would override the Devise SessionsController's create to permissibly allow access to certain areas before confirmation. However, I'm not sure if this is the right way to go.
推荐答案
使用内置的解决方案,你可以使用 allow_unconfirmed_access_for 1.year
结合 current_user.confirmed?
在您的以前的过滤器
Using built in solution in devise, you could use allow_unconfirmed_access_for 1.year
in combination with current_user.confirmed?
in your before filter
这篇关于Rails 3设计确认过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!