When a user connects to the application, a listener detects the connection event and updates the last_login_at
field for the user.
The problem appears when the user wants to log out.
When disconnected, the listener's onSecurityAuthenticationSuccess
method is always called.
Problem once disconnected we can no longer recover a user (in the session)
What I would like is to be able to record the date of the last connection in the database called the onSecurityAuthenticationSuccess
method only on login and not on login and logout.
In addition I have an is_in_line
field in the database and I would like to disconnect, I can detect the event "disconnection" and update this field
How can I do this?
Here is my code to list it
public function onSecurityAuthenticationSuccess (AuthenticationEvent $ event) {
$ user = $ event-> getAuthenticationToken () -> getUser ();
if ($ user) {
// dd ($ user);
$ user-> setLastLoginAt (new \ Datetime ('now'));
$ this-> em-> persist ($ user);
$ this-> em-> flush ();
}
}