who_am_i.rb 871 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. class Sessions::Event::WhoAmI < Sessions::Event::Base
  2. database_connection_required
  3. =begin
  4. Event module to send `who am i` to client connection.
  5. To execute this manually, just paste the following into the browser console
  6. App.WebSocket.send({event:'who_am_i'})
  7. =end
  8. def run
  9. if !@session || !@session['id']
  10. return {
  11. event: 'who_am_i',
  12. data: {
  13. message: 'session not authenticated',
  14. },
  15. }
  16. end
  17. user = User.find_by(id: @session['id'])
  18. if !user
  19. return {
  20. event: 'who_am_i',
  21. data: {
  22. message: "No such user with id #{@session['id']}",
  23. },
  24. }
  25. end
  26. attributes = user.attributes
  27. attributes.delete('password')
  28. {
  29. event: 'who_am_i',
  30. data: {
  31. message: 'session authenticated',
  32. user: attributes,
  33. },
  34. }
  35. end
  36. end