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.

Options

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.

Examples

  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

Methods

Classes and Modules

Module Devise::Models::Confirmable::ClassMethods

Public Instance methods

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

Verifies whether a user is confirmed or not

The message to be shown if the account is inactive.

Resend confirmation token. This method does not need to generate a new token.

Send confirmation instructions by email

If you don‘t want confirmation to be sent on create, neither a code to be generated, call skip_confirmation!

Protected Instance methods

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

Callback to overwrite if confirmation is required or not.

Generates a new random token for confirmation, and stores the time this token is being generated

Checks whether the record is confirmed or not, yielding to the block if it‘s already confirmed, otherwise adds an error to email.

[Validate]