mirror of
https://github.com/heartcombo/devise.git
synced 2022-11-09 12:18:31 -05:00
9f032350e3
Signed-off-by: José Valim <jose.valim@gmail.com>
42 lines
1.1 KiB
Ruby
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
|