0

In my application, whenever a user logs in, he is added to a table that stores data about the logged users, but I have nothing implemented to take those users off my table. I need to remove that user from my table when he logs out or loses his session in any other way. Is there a "SessionDestroy" event or something like that, that allows me do implement something upon a destroyed session?

bpromas
  • 684
  • 1
  • 11
  • 25

1 Answers1

2

You can add "session events" (using anonymous methods) to the Session Manager. Since 2009, I guess (but tested on XE). Works for REST sessions and more. Sample code:

 TDSSessionManager.Instance.AddSessionEvent(
procedure (Sender: TObject; const EventType: TDSSessionEventType;
  const session: TDSSession)
begin
  case EventType of
    SessionCreate :
    begin
      session.UserRoles.Add('guest'); // guest role is fixed
      ...
    end;
    SessionClose:
    begin
      FreeAndNil(some_more_data);
    end;
  end;
end);
Marco Cantù
  • 1,195
  • 7
  • 13