Module: Devise::Models::Confirmable
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/devise/models/confirmable.rb
Overview
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
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
-
#active_for_authentication? ⇒ Boolean
Overwrites active_for_authentication? for confirmation by verifying whether a user is active to sign in or not.
-
#confirm! ⇒ Object
Confirm a user by setting it’s confirmed_at to actual time.
-
#confirmed? ⇒ Boolean
Verifies whether a user is confirmed or not.
-
#inactive_message ⇒ Object
The message to be shown if the account is inactive.
-
#resend_confirmation_token ⇒ Object
Resend confirmation token.
-
#send_confirmation_instructions ⇒ Object
Send confirmation instructions by email.
-
#skip_confirmation! ⇒ Object
If you don’t want confirmation to be sent on create, neither a code to be generated, call skip_confirmation!.
Instance Method Details
#active_for_authentication? ⇒ Boolean
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.
62 63 64 |
# File 'lib/devise/models/confirmable.rb', line 62 def active_for_authentication? super && (!confirmation_required? || confirmed? || confirmation_period_valid?) end |
#confirm! ⇒ Object
Confirm a user by setting it’s confirmed_at to actual time. If the user is already confirmed, add en error to email field
34 35 36 37 38 39 40 |
# File 'lib/devise/models/confirmable.rb', line 34 def confirm! unless_confirmed do self.confirmation_token = nil self.confirmed_at = Time.now save(:validate => false) end end |
#confirmed? ⇒ Boolean
Verifies whether a user is confirmed or not
43 44 45 |
# File 'lib/devise/models/confirmable.rb', line 43 def confirmed? !!confirmed_at end |
#inactive_message ⇒ Object
The message to be shown if the account is inactive.
67 68 69 |
# File 'lib/devise/models/confirmable.rb', line 67 def !confirmed? ? :unconfirmed : super end |
#resend_confirmation_token ⇒ Object
Resend confirmation token. This method does not need to generate a new token.
54 55 56 |
# File 'lib/devise/models/confirmable.rb', line 54 def resend_confirmation_token unless_confirmed { send_confirmation_instructions } end |
#send_confirmation_instructions ⇒ Object
Send confirmation instructions by email
48 49 50 51 |
# File 'lib/devise/models/confirmable.rb', line 48 def send_confirmation_instructions generate_confirmation_token! if self.confirmation_token.nil? ::Devise.mailer.confirmation_instructions(self).deliver end |
#skip_confirmation! ⇒ Object
If you don’t want confirmation to be sent on create, neither a code to be generated, call skip_confirmation!
73 74 75 |
# File 'lib/devise/models/confirmable.rb', line 73 def skip_confirmation! self.confirmed_at = Time.now end |