module Devision::Models::Confirmable
Attributes
raw_confirmation_token[R]
Public Class Methods
required_fields(klass)
click to toggle source
Fields required on the target Model
# File lib/devision/models/confirmable.rb, line 7 def self.required_fields(klass) [:confirmation_token, :confirmed_at, :confirmation_sent_at] end
Public Instance Methods
clear_confirmation_token()
click to toggle source
# File lib/devision/models/confirmable.rb, line 42 def clear_confirmation_token @raw_confirmation_token = nil self.confirmation_token = nil self.confirmation_sent_at = nil end
confirm!()
click to toggle source
# File lib/devision/models/confirmable.rb, line 15 def confirm! pending_any_confirmation do if confirmation_period_expired? self.errors.add(:email, :confirmation_period_expired) return false end self.confirmation_token = nil self.confirmed_at = Time.now.utc save(validate: false) end end
confirmation_period_expired?()
click to toggle source
# File lib/devision/models/confirmable.rb, line 58 def confirmation_period_expired? self.class.confirm_within && (Time.now > self.confirmation_sent_at + self.class.confirm_within ) end
confirmation_period_valid?()
click to toggle source
# File lib/devision/models/confirmable.rb, line 62 def confirmation_period_valid? self.class.allow_unconfirmed_access_for.nil? || (confirmation_sent_at && confirmation_sent_at.utc >= self.class.allow_unconfirmed_access_for.ago) end
confirmed?()
click to toggle source
# File lib/devision/models/confirmable.rb, line 27 def confirmed? !!confirmed_at end
generate_confirmation_tokens()
click to toggle source
# File lib/devision/models/confirmable.rb, line 31 def generate_confirmation_tokens raw, enc = Devision.token_generator.generate(self.class, :confirmation_token) @raw_confirmation_token = raw self.confirmation_token = enc self.confirmation_sent_at = Time.now.utc end
generate_confirmation_tokens!()
click to toggle source
# File lib/devision/models/confirmable.rb, line 38 def generate_confirmation_tokens! generate_confirmation_tokens && save(validate: false) end
pending_any_confirmation() { || ... }
click to toggle source
Checks whether the record requires any confirmation.
# File lib/devision/models/confirmable.rb, line 49 def pending_any_confirmation if !confirmed? yield else self.errors.add(:email, :already_confirmed) false end end