dpassage
dpassage

Reputation: 5453

Use Devise :confirmable without time limit?

I'm using Devise for authentication in my application. I don't want to require email confirmation when a user signs up, but I do want to require it if the user wants the app to send them email updates. Is this possible with the built-in :confirmable feature of Devise? I found the setting to set how long a user can log in without confirming, but I essentially want to set that to "forever".

Upvotes: 1

Views: 822

Answers (2)

Chloe
Chloe

Reputation: 26264

Look in config/initializers/devise.rb for

  # ==> Configuration for :confirmable
  # A period that the user is allowed to access the website even without
  # confirming their account. For instance, if set to 2.days, the user will be
  # able to access the website for two days without confirming their account,
  # access will be blocked just in the third day. Default is 0.days, meaning
  # the user cannot access the website without confirming their account.
  # config.allow_unconfirmed_access_for = 2.days

Set it to 1000.years. Then in your email_updates method, call #confirmed? to test if the user has confirmed their account. If not, send them to the page to re-send the confirmation link, as it will likely have expired by now.

Upvotes: 0

Benjamin Tan Wei Hao
Benjamin Tan Wei Hao

Reputation: 9691

Check out https://github.com/plataformatec/devise/blob/master/lib/devise/models/confirmable.rb. You can probably override confirmation_period_valid? by returning always true.

Alternatively, maybe you can change your setting to something like 10000.years.from_now, which might be a good enough estimation for "forever", perhaps?

Upvotes: 1

Related Questions