trabajo-afectivo/lib/sessions/event/login.rb

47 lines
1 KiB
Ruby
Raw Normal View History

2015-12-09 13:09:37 +00:00
class Sessions::Event::Login < Sessions::Event::Base
database_connection_required
=begin
Event module to start websocket session for new client connections.
To execute this manually, just paste the following into the browser console
App.WebSocket.send({event:'login', session_id: '123'})
=end
2015-12-09 13:09:37 +00:00
def run
# get user_id
session = nil
app_version = AppVersion.event_data
2015-12-09 13:09:37 +00:00
if @payload && @payload['session_id']
session = ActiveRecord::SessionStore::Session.find_by(session_id: @payload['session_id'])
end
new_session_data = {}
2017-11-23 08:09:44 +00:00
if session&.data && session.data['user_id']
new_session_data = {
'id' => session.data['user_id'],
}
end
2015-12-09 13:09:37 +00:00
# create new session
2015-12-09 13:09:37 +00:00
if @clients[@client_id]
@clients[@client_id][:session] = new_session_data
Sessions.create(@client_id, new_session_data, { type: 'websocket' })
else
Sessions.create(@client_id, new_session_data, { type: 'ajax' })
end
# send app version
Sessions.send(@client_id, app_version)
2015-12-09 13:09:37 +00:00
false
end
end