2015-12-09 13:09:37 +00:00
|
|
|
class Sessions::Event::Login < Sessions::Event::Base
|
2018-11-02 17:42:57 +00:00
|
|
|
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
|
2016-02-12 14:07:15 +00:00
|
|
|
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
|
|
|
|
|
2016-02-12 14:07:15 +00:00
|
|
|
new_session_data = {}
|
2017-11-23 08:09:44 +00:00
|
|
|
if session&.data && session.data['user_id']
|
2016-02-12 14:07:15 +00:00
|
|
|
new_session_data = {
|
|
|
|
'id' => session.data['user_id'],
|
|
|
|
}
|
|
|
|
end
|
2015-12-09 13:09:37 +00:00
|
|
|
|
2016-02-12 14:07:15 +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
|
|
|
|
|
2016-02-12 14:07:15 +00:00
|
|
|
# send app version
|
|
|
|
Sessions.send(@client_id, app_version)
|
|
|
|
|
2015-12-09 13:09:37 +00:00
|
|
|
false
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|