1
0
Fork 0
mirror of https://github.com/heartcombo/devise.git synced 2022-11-09 12:18:31 -05:00
heartcombo--devise/lib/devise/rails/warden_compat.rb
Sean Cribbs 9f032350e3 Use ActiveModel's to_key instead of id.
Signed-off-by: José Valim <jose.valim@gmail.com>
2010-10-10 17:51:32 +02:00

42 lines
1.1 KiB
Ruby

module Warden::Mixins::Common
def request
@request ||= ActionDispatch::Request.new(env)
end
def reset_session!
raw_session.inspect # why do I have to inspect it to get it to clear?
raw_session.clear
end
def cookies
request.cookie_jar
end
end
class Warden::SessionSerializer
def serialize(record)
[record.class.name, record.to_key, record.authenticatable_salt]
end
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 cookie secret or cleaning up your " <<
"database sessions if you are using a db store."
end
klass, id, salt = keys
begin
record = klass.constantize.find(:first, :conditions => { :id => id.first })
record if record && record.authenticatable_salt == salt
rescue NameError => e
if e.message =~ /uninitialized constant/
Rails.logger.debug "Trying to deserialize invalid class #{klass}"
nil
else
raise
end
end
end
end