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?

1 Answer 1

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);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.