Chat box widget: fix an error ocurring when the messages list is empty
Login / logout logic: move the gate behavior to the body element

This change is made in order to allow us to listen the "gate:close"
event.