login.rb 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. class Sessions::Event::Login < Sessions::Event::Base
  2. database_connection_required
  3. =begin
  4. Event module to start websocket session for new client connections.
  5. To execute this manually, just paste the following into the browser console
  6. App.WebSocket.send({event:'login', session_id: '123'})
  7. =end
  8. def run
  9. # get user_id
  10. session = nil
  11. app_version = AppVersion.event_data
  12. if @payload && @payload['session_id']
  13. private_session_id = Rack::Session::SessionId.new(@payload['session_id']).private_id
  14. session = ActiveRecord::SessionStore::Session.find_by(session_id: private_session_id)
  15. end
  16. new_session_data = {}
  17. if session&.data && session.data['user_id']
  18. new_session_data = {
  19. 'id' => session.data['user_id'],
  20. }
  21. end
  22. # create new session
  23. if @clients[@client_id]
  24. @clients[@client_id][:session] = new_session_data
  25. Sessions.create(@client_id, new_session_data, { type: 'websocket' })
  26. else
  27. Sessions.create(@client_id, new_session_data, { type: 'ajax' })
  28. end
  29. # send app version
  30. Sessions.send(@client_id, app_version)
  31. false
  32. end
  33. end