* Add Session.States to track new/expired etc.

git-svn-id: trunk@39531 -
This commit is contained in:
michael 2018-07-30 20:05:47 +00:00
parent 66efdeff83
commit 99a83cd392
2 changed files with 49 additions and 0 deletions

View File

@ -519,13 +519,20 @@ type
{ TCustomSession }
TSessionState = (ssNew,ssExpired,ssActive,ssResponseInitialized);
TSessionStates = set of TSessionState;
TCustomSession = Class(TComponent)
Private
FOnSessionStateChange: TNotifyEvent;
FSessionCookie: String;
FSessionCookiePath: String;
FStates: TSessionStates;
FTimeOut: Integer;
Procedure SetSessionState(aValue : TSessionStates);
Protected
Procedure AddToSessionState(aValue : TSessionState);
Procedure RemoveFromSessionState(aValue : TSessionState);
// Can be overridden to provide custom behaviour.
procedure SetSessionCookie(const AValue: String); virtual;
procedure SetSessionCookiePath(const AValue: String); virtual;
@ -556,6 +563,10 @@ type
Property SessionCookiePath : String Read FSessionCookiePath write SetSessionCookiePath;
// Variables, tracked in session.
Property Variables[VarName : String] : String Read GetSessionVariable Write SetSessionVariable;
// Session state
Property SessionState : TSessionStates Read FStates;
// Called when state changes
Property OnSessionStateChange : TNotifyEvent Read FOnSessionStateChange Write FOnSessionStateChange;
end;
TRequestEvent = Procedure (Sender: TObject; ARequest : TRequest) of object;
@ -2261,6 +2272,36 @@ end;
TCustomSession
---------------------------------------------------------------------}
procedure TCustomSession.SetSessionState(aValue: TSessionStates);
begin
if FStates=aValue then exit;
If Assigned(OnSessionStateChange) then
OnSessionStateChange(Self);
FStates:=AValue;
end;
procedure TCustomSession.AddToSessionState(aValue: TSessionState);
Var
S: TSessionStates;
begin
S:=SessionState;
Include(S,AValue);
SetSessionState(S);
end;
procedure TCustomSession.RemoveFromSessionState(aValue: TSessionState);
Var
S: TSessionStates;
begin
S:=SessionState;
Exclude(S,AValue);
SetSessionState(S);
end;
procedure TCustomSession.SetSessionCookie(const AValue: String);
begin
FSessionCookie:=AValue;
@ -2286,6 +2327,7 @@ constructor TCustomSession.Create(AOwner: TComponent);
begin
FTimeOut:=DefaultTimeOut;
inherited Create(AOwner);
FStates:=[];
end;
procedure TCustomSession.InitResponse(AResponse: TResponse);

View File

@ -354,6 +354,9 @@ begin
DeleteFile(Finifile.FileName);
FreeAndNil(FIniFile);
end;
RemoveFromSessionState(ssActive);
RemoveFromSessionState(ssNew);
RemoveFromSessionState(ssExpired);
end;
procedure TIniWebSession.UpdateResponse(AResponse: TResponse);
@ -389,6 +392,7 @@ begin
FIniFile:=CreateIniFile(FN);
if SF.SessionExpired(FIniFile) then
begin
AddToSessionState(ssExpired);
// Expire session.
If Assigned(OnExpired) then
OnExpired(Self);
@ -401,6 +405,7 @@ begin
end;
If (S='') then
begin
AddToSessionState(ssNew);
If Assigned(OnNewSession) then
OnNewSession(Self);
GetSessionID;
@ -414,6 +419,7 @@ begin
FIniFile.WriteDateTime(SSession,KeyLast,Now);
If not FCached then
UpdateIniFile;
AddToSessionState(ssActive);
{$ifdef cgidebug}SendMethodExit('TIniWebSession.InitSession');{$endif}
end;
@ -442,6 +448,7 @@ begin
C.Path:=SessionCookiePath;
end;
{$ifdef cgidebug}SendMethodExit('TIniWebSession.InitResponse');{$endif}
AddToSessionState(ssResponseInitialized);
end;
procedure TIniWebSession.RemoveVariable(VariableName: String);