diff --git a/app/controllers/long_polling_controller.rb b/app/controllers/long_polling_controller.rb index 5512175e8..fa5a99b6b 100644 --- a/app/controllers/long_polling_controller.rb +++ b/app/controllers/long_polling_controller.rb @@ -59,7 +59,7 @@ class LongPollingController < ApplicationController user_id = session[:user_id] user = {} if user_id - user = User.find( user_id ) + user = User.find( user_id ).attributes end log 'notice', "send auth login (user_id #{user_id})", client_id Sessions.create( client_id, user, { :type => 'ajax' } ) diff --git a/lib/sessions.rb b/lib/sessions.rb index 7d299ee7e..0962312d9 100644 --- a/lib/sessions.rb +++ b/lib/sessions.rb @@ -37,7 +37,7 @@ returns :user => session, :meta => meta, } - file.write Marshal.dump(data) + file.write data.to_json } # send update to browser @@ -195,7 +195,7 @@ returns path = @path + '/' + client_id.to_s data[:meta][:last_ping] = Time.new.to_i.to_s File.open( path + '/session', 'wb' ) { |file| - file.write Marshal.dump(data) + file.write data.to_json } true end @@ -234,7 +234,11 @@ returns file.flock( File::LOCK_EX ) all = file.read file.flock( File::LOCK_UN ) - data = Marshal.load( all ) + dataJSON = JSON.parse( all ) + if dataJSON + data = self.symbolize_keys(dataJSON) + data[:user] = dataJSON['user'] # for compat. reasons + end } rescue Exception => e puts e.inspect @@ -567,4 +571,19 @@ returns puts "/LOOP #{client_id} - #{try_count}" end -end + def self.symbolize_keys(hash) + hash.inject({}){|result, (key, value)| + new_key = case key + when String then key.to_sym + else key + end + new_value = case value + when Hash then symbolize_keys(value) + else value + end + result[new_key] = new_value + result + } + end + +end \ No newline at end of file