Class: Warden::SessionSerializer

Inherits:
Object
  • Object
show all
Defined in:
lib/devise/rails/warden_compat.rb

Instance Method Summary collapse

Instance Method Details

#deserialize(keys) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/devise/rails/warden_compat.rb', line 21

def deserialize(keys)
  if keys.size == 2
    raise "Devise changed how it stores objects in session. If you are seeing this message, " <<
      "you can fix it by changing one character in your secret_token or cleaning up your " <<
      "database sessions if you are using a db store."
  end

  klass, id, salt = keys

  begin
    record = ActiveSupport::Inflector.constantize(klass).to_adapter.get(id)
    record if record && record.authenticatable_salt == salt
  rescue NameError => e
    if e.message =~ /uninitialized constant/
      Rails.logger.debug "[Devise] Trying to deserialize invalid class #{klass}"
      nil
    else
      raise
    end
  end
end

#serialize(record) ⇒ Object



17
18
19
# File 'lib/devise/rails/warden_compat.rb', line 17

def serialize(record)
  [record.class.name, record.to_key, record.authenticatable_salt]
end