Confirmable confirmation_required? disable per controller filter?

365 views
Skip to first unread message

Justin Hart

unread,
Jun 26, 2012, 11:07:45 AM6/26/12
to plataforma...@googlegroups.com
Is there a known/good way to skip the confirmation check in certain actions?  What I want to do is allow a user to log in and access certain 'preview' areas of the site without confirming their email, but then be reminded/prompted when they get further in.

it looks like overriding confirmation_required? in my user model should work, but I'm having trouble figuring out the best way to set a value there if I dont have the user yet when the before_filter runs. A thread local?  Have confirmation_required? look at the currently active controller instance?

Thanks.

Sherwin Yu

unread,
Jul 23, 2012, 3:45:52 PM7/23/12
to plataforma...@googlegroups.com
Hi, I'm wondering the exact same thing. 

I want users to sign up for an account (which will trigger a confirmation email), be automatically logged in, and be able to explore certain parts of the site as a signed in (but unconfirmed) user. When it comes time to certain areas (e.g., payment), the the user needs to first confirm their email.

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

I searched for a while and could not find a way to do this out of the box, so I also about 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. 

Justin, did you get confirmation_required? to work?

José Valim

unread,
Jul 23, 2012, 3:52:01 PM7/23/12
to plataforma...@googlegroups.com
Devise by default has a configuration named:

config.allow_unconfirmed_access_for

You can set it in your devise initializer and it will allow the user to access any page, any time, while still unconfirmed.

Then, for the pages you require confirmation, you can simply add a before filter:

     before_filter :only_confirmed

     def only_confirmed
      redirect_to "/", notice: "NOPE" unless current_user.confirmed?
     end

You can check other methods related to confirmation here:

Reply all
Reply to author
Forward
0 new messages