module Devise::Models::Rememberable
def self.required_fields(klass)
def self.required_fields(klass) [:remember_created_at] end
def after_remembered
end
self.update_attribute(:invite_code, nil)
def after_remembered
Example:
remembered.
used to insert your own logic that is only run after the user is
A callback initiated after successfully being remembered. This can be
def after_remembered end
def extend_remember_period
def extend_remember_period self.class.extend_remember_period end
def forget_me!
If the record is persisted, remove the remember token (but only if
def forget_me! return unless persisted? self.remember_token = nil if respond_to?(:remember_token) self.remember_created_at = nil if self.class.expire_all_remember_me_on_sign_out save(validate: false) end
def remember_expires_at
def remember_expires_at self.class.remember_for.from_now end
def remember_me!
def remember_me! self.remember_token ||= self.class.remember_token if respond_to?(:remember_token) self.remember_created_at ||= Time.now.utc save(validate: false) if self.changed? end
def remember_me?(token, generated_at)
def remember_me?(token, generated_at) # TODO: Normalize the JSON type coercion along with the Timeoutable hook # in a single place https://github.com/heartcombo/devise/blob/ffe9d6d406e79108cf32a2c6a1d0b3828849c40b/lib/devise/hooks/timeoutable.rb#L14-L18 if generated_at.is_a?(String) generated_at = time_from_json(generated_at) end # The token is only valid if: # 1. we have a date # 2. the current time does not pass the expiry period # 3. the record has a remember_created_at date # 4. the token date is bigger than the remember_created_at # 5. the token matches generated_at.is_a?(Time) && (self.class.remember_for.ago < generated_at) && (generated_at > (remember_created_at || Time.now).utc) && Devise.secure_compare(rememberable_value, token) end
def rememberable_options
def rememberable_options self.class.rememberable_options end
def rememberable_value
def rememberable_value if respond_to?(:remember_token) remember_token elsif respond_to?(:authenticatable_salt) && (salt = authenticatable_salt.presence) salt else raise "authenticatable_salt returned nil for the #{self.class.name} model. " \ "In order to use rememberable, you must ensure a password is always set " \ "or have a remember_token column in your model or implement your own " \ "rememberable_value in the model with custom logic." end end
def time_from_json(value)
def time_from_json(value) if value =~ /\A\d+\.\d+\Z/ Time.at(value.to_f) else Time.parse(value) rescue nil end end