Skip to content

Instantly share code, notes, and snippets.

@hassox
Created August 22, 2011 23:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save hassox/7b63df9506edf43f85dd to your computer and use it in GitHub Desktop.
Save hassox/7b63df9506edf43f85dd to your computer and use it in GitHub Desktop.
class Warden::SessionSerializer
def serialize(record)
case record.class
when TrueClass, FalseClass
[record.class.name, record]
else
[record.class.name, record.to_key, record.authenticatable_salt]
end
end
def deserialize(keys)
if keys.size == 2 && ['TrueClass', 'FalseClass'].includes?(keys.first)
return keys.last
end
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
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment