2021-06-01 12:20:20 +00:00
|
|
|
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
|
|
|
|
|
2018-11-02 17:42:57 +00:00
|
|
|
class Sessions::Event::WhoAmI < Sessions::Event::Base
|
|
|
|
database_connection_required
|
|
|
|
|
|
|
|
=begin
|
|
|
|
|
|
|
|
Event module to send `who am i` to client connection.
|
|
|
|
|
|
|
|
To execute this manually, just paste the following into the browser console
|
|
|
|
|
|
|
|
App.WebSocket.send({event:'who_am_i'})
|
|
|
|
|
|
|
|
=end
|
|
|
|
|
|
|
|
def run
|
|
|
|
|
|
|
|
if !@session || !@session['id']
|
|
|
|
return {
|
|
|
|
event: 'who_am_i',
|
2018-12-19 17:31:51 +00:00
|
|
|
data: {
|
2018-11-02 17:42:57 +00:00
|
|
|
message: 'session not authenticated',
|
|
|
|
},
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
user = User.find_by(id: @session['id'])
|
|
|
|
|
|
|
|
if !user
|
|
|
|
return {
|
|
|
|
event: 'who_am_i',
|
2018-12-19 17:31:51 +00:00
|
|
|
data: {
|
2018-11-02 17:42:57 +00:00
|
|
|
message: "No such user with id #{@session['id']}",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
end
|
|
|
|
attributes = user.attributes
|
|
|
|
attributes.delete('password')
|
|
|
|
{
|
|
|
|
event: 'who_am_i',
|
2018-12-19 17:31:51 +00:00
|
|
|
data: {
|
2018-11-02 17:42:57 +00:00
|
|
|
message: 'session authenticated',
|
2018-12-19 17:31:51 +00:00
|
|
|
user: attributes,
|
2018-11-02 17:42:57 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|