login.rb 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. session = ActiveRecord::SessionStore::Session.find_by(session_id: @payload['session_id'])
  14. end
  15. new_session_data = {}
  16. if session&.data && session.data['user_id']
  17. new_session_data = {
  18. 'id' => session.data['user_id'],
  19. }
  20. end
  21. # create new session
  22. if @clients[@client_id]
  23. @clients[@client_id][:session] = new_session_data
  24. Sessions.create(@client_id, new_session_data, { type: 'websocket' })
  25. else
  26. Sessions.create(@client_id, new_session_data, { type: 'ajax' })
  27. end
  28. # send app version
  29. Sessions.send(@client_id, app_version)
  30. false
  31. end
  32. end