Module: Kingsman::Models::Rememberable::ClassMethods

Defined in:
lib/kingsman/models/rememberable.rb

Instance Method Summary collapse

Instance Method Details

#remember_tokenObject

Generate a token checking if one does not already exist in the database.



147
148
149
150
151
152
# File 'lib/kingsman/models/rememberable.rb', line 147

def remember_token #:nodoc:
  loop do
    token = Kingsman.friendly_token
    break token unless to_adapter.find_first({ remember_token: token })
  end
end

Recreate the user based on the stored cookie



139
140
141
142
143
144
# File 'lib/kingsman/models/rememberable.rb', line 139

def serialize_from_cookie(*args)
  id, token, generated_at = *args

  record = to_adapter.get(id)
  record if record && record.remember_me?(token, generated_at)
end

Create the cookie key using the record id and remember_token



134
135
136
# File 'lib/kingsman/models/rememberable.rb', line 134

def serialize_into_cookie(record)
  [record.to_key, record.rememberable_value, Time.now.utc.to_f.to_s]
end