login.rb 1.2 KB

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