Module | Devise::Models::Confirmable |
In: |
lib/devise/models/confirmable.rb
|
Confirmable is responsible to verify if an account is already confirmed to sign in, and to send emails with confirmation instructions. Confirmation instructions are sent to the user email after creating a record and when manually requested by a new confirmation instruction request.
Confirmable adds the following options to devise_for:
* +confirm_within+: the time you want to allow the user to access his account before confirming it. After this period, the user access is denied. You can use this to let your user access some features of your application without confirming the account, but blocking it after a certain period (ie 7 days). By default confirm_within is zero, it means users always have to confirm to sign in.
User.find(1).confirm! # returns true unless it's already confirmed User.find(1).confirmed? # true/false User.find(1).send_confirmation_instructions # manually send instructions
Overwrites active_for_authentication? for confirmation by verifying whether a user is active to sign in or not. If the user is already confirmed, it should never be blocked. Otherwise we need to calculate if the confirm time has not expired for this user.
Confirm a user by setting its confirmed_at to actual time. If the user is already confirmed, add en error to email field
If you don‘t want confirmation to be sent on create, neither a code to be generated, call skip_confirmation!
Checks if the confirmation for the user is within the limit time. We do this by calculating if the difference between today and the confirmation sent date does not exceed the confirm in time configured. Confirm_within is a model configuration, must always be an integer value.
Example:
# confirm_within = 1.day and confirmation_sent_at = today confirmation_period_valid? # returns true # confirm_within = 5.days and confirmation_sent_at = 4.days.ago confirmation_period_valid? # returns true # confirm_within = 5.days and confirmation_sent_at = 5.days.ago confirmation_period_valid? # returns false # confirm_within = 0.days confirmation_period_valid? # will always return false