Module: Revise::Models::Confirmable
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/revise/models/confirmable.rb
Defined Under Namespace
Modules: ClassMethods
Constant Summary collapse
- MAILERS =
['Confirmable']
- HELPERS =
[]
- CONTROLLERS =
['Confirmations']
Class Method Summary collapse
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.
- #pending_reconfirmation? ⇒ Boolean
-
#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!.
-
#skip_reconfirmation! ⇒ Object
If you don’t want reconfirmation to be sent, neither a code to be generated, call skip_reconfirmation!.
Class Method Details
.required_fields(klass) ⇒ Object
17 18 19 20 21 |
# File 'lib/revise/models/confirmable.rb', line 17 def self.required_fields(klass) required_methods = [:confirmation_token, :confirmed_at, :confirmation_sent_at] required_methods << :unconfirmed_email if klass.reconfirmable required_methods end |
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.
79 80 81 |
# File 'lib/revise/models/confirmable.rb', line 79 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 an error to email field. If the user is invalid add errors
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/revise/models/confirmable.rb', line 26 def confirm! pending_any_confirmation do if confirmation_period_expired? self.errors.add(:confirmation_period_expired, 'Token expired') return false end self.confirmation_token = nil self.confirmed_at = Time.now.utc if self.class.reconfirmable && unconfirmed_email.present? skip_reconfirmation! self.email = unconfirmed_email self.unconfirmed_email = nil # We need to validate in such cases to enforce e-mail uniqueness save(:validate => true) else save(:validate => false) end end end |
#confirmed? ⇒ Boolean
Verifies whether a user is confirmed or not
50 51 52 |
# File 'lib/revise/models/confirmable.rb', line 50 def confirmed? !!confirmed_at end |
#inactive_message ⇒ Object
The message to be shown if the account is inactive.
84 85 86 |
# File 'lib/revise/models/confirmable.rb', line 84 def !confirmed? ? :unconfirmed : super end |
#pending_reconfirmation? ⇒ Boolean
54 55 56 |
# File 'lib/revise/models/confirmable.rb', line 54 def pending_reconfirmation? self.class.reconfirmable && unconfirmed_email.present? end |
#resend_confirmation_token ⇒ Object
Resend confirmation token. This method does not need to generate a new token.
68 69 70 71 72 73 |
# File 'lib/revise/models/confirmable.rb', line 68 def resend_confirmation_token pending_any_confirmation do self.confirmation_token = nil if confirmation_period_expired? send_confirmation_instructions end end |
#send_confirmation_instructions ⇒ Object
Send confirmation instructions by email
59 60 61 62 63 64 65 |
# File 'lib/revise/models/confirmable.rb', line 59 def send_confirmation_instructions self.confirmation_token = nil if reconfirmation_required? @reconfirmation_required = false generate_confirmation_token! if self.confirmation_token.blank? send_revise_notification(:confirmable, :confirmation_instructions, self.name, self.email, self.confirmation_token) end |
#skip_confirmation! ⇒ Object
If you don’t want confirmation to be sent on create, neither a code to be generated, call skip_confirmation!
90 91 92 |
# File 'lib/revise/models/confirmable.rb', line 90 def skip_confirmation! self.confirmed_at = Time.now.utc end |
#skip_reconfirmation! ⇒ Object
If you don’t want reconfirmation to be sent, neither a code to be generated, call skip_reconfirmation!
96 97 98 |
# File 'lib/revise/models/confirmable.rb', line 96 def skip_reconfirmation! @bypass_postpone = true end |