Rails 3 Devise confirmation filter

↘锁芯ラ 提交于 2019-12-23 03:31:55

问题


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.

I'm hoping for something like before_filter: user_is_confirmed, only: [payment_related_stuff]

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.


回答1:


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



来源:https://stackoverflow.com/questions/11619388/rails-3-devise-confirmation-filter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!