mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-11-02 15:39:26 +01:00
* Moved session cookie up in the class hierarchie, so it can be configured at the session factory level
git-svn-id: trunk@17653 -
This commit is contained in:
parent
0e1f20773a
commit
4492b9b993
@ -147,6 +147,8 @@ Type
|
||||
|
||||
TSessionFactory = Class(TComponent)
|
||||
private
|
||||
FSessionCookie: String;
|
||||
FSessionCookiePath: String;
|
||||
FTimeOut: Integer;
|
||||
FCleanupInterval: Integer;
|
||||
FDoneCount: Integer;
|
||||
@ -167,6 +169,10 @@ Type
|
||||
Property CleanupInterval : Integer read FCleanupInterval Write FCleanUpInterval;
|
||||
// Default timeout for sessions, in minutes.
|
||||
Property DefaultTimeOutMinutes : Integer Read FTimeOut Write FTimeOut;
|
||||
// Default session cookie.
|
||||
property SessionCookie : String Read FSessionCookie Write FSessionCookie;
|
||||
// Default session cookie path
|
||||
Property SessionCookiePath : String Read FSessionCookiePath write FSessionCookiePath;
|
||||
end;
|
||||
TSessionFactoryClass = Class of TSessionFactory;
|
||||
|
||||
@ -242,8 +248,13 @@ end;
|
||||
function TSessionFactory.CreateSession(ARequest: TRequest): TCustomSession;
|
||||
begin
|
||||
Result:=DoCreateSession(ARequest);
|
||||
if (FTimeOut<>0) and Assigned(Result) then
|
||||
Result.TimeoutMinutes:=FTimeOut;
|
||||
if Assigned(Result) then
|
||||
begin
|
||||
if (FTimeOut<>0) then
|
||||
Result.TimeoutMinutes:=FTimeOut;
|
||||
Result.SessionCookie:=Self.SessionCookie;
|
||||
Result.SessionCookiePath:=Self.SessionCookiePath;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TSessionFactory.DoneSession(var ASession: TCustomSession);
|
||||
|
||||
@ -32,6 +32,9 @@ interface
|
||||
uses Classes,Sysutils;
|
||||
|
||||
const
|
||||
DefaultTimeOut = 15;
|
||||
SFPWebSession = 'FPWebSession'; // Cookie name for session.
|
||||
|
||||
fieldAccept = 'Accept';
|
||||
fieldAcceptCharset = 'Accept-Charset';
|
||||
fieldAcceptEncoding = 'Accept-Encoding';
|
||||
@ -355,9 +358,16 @@ type
|
||||
|
||||
TCustomSession = Class(TComponent)
|
||||
Private
|
||||
FSessionCookie: String;
|
||||
FSessionCookiePath: String;
|
||||
FTimeOut: Integer;
|
||||
Protected
|
||||
// Can be overridden to provide custom behaviour.
|
||||
procedure SetSessionCookie(const AValue: String); virtual;
|
||||
procedure SetSessionCookiePath(const AValue: String); virtual;
|
||||
// When called, generates a new GUID. Override to retrieve GUID from cookie/URL/...
|
||||
Function GetSessionID : String; virtual;
|
||||
// These must be overridden to actually store/retrieve variables.
|
||||
Function GetSessionVariable(VarName : String) : String; Virtual; abstract;
|
||||
procedure SetSessionVariable(VarName : String; const AValue: String);Virtual;abstract;
|
||||
Public
|
||||
@ -368,10 +378,19 @@ type
|
||||
Procedure InitResponse(AResponse : TResponse); virtual;
|
||||
// Update response from session (typically, change cookie to response and write session data).
|
||||
Procedure UpdateResponse(AResponse : TResponse); virtual; Abstract;
|
||||
// Remove variable from list of variables.
|
||||
Procedure RemoveVariable(VariableName : String); virtual; abstract;
|
||||
// Terminate session
|
||||
Procedure Terminate; virtual; abstract;
|
||||
Property TimeOutMinutes : Integer Read FTimeOut Write FTimeOut;
|
||||
// Session timeout in minutes
|
||||
Property TimeOutMinutes : Integer Read FTimeOut Write FTimeOut default 15;
|
||||
// ID of this session.
|
||||
Property SessionID : String Read GetSessionID;
|
||||
// Name of cookie used when tracing session. (may or may not be used)
|
||||
property SessionCookie : String Read FSessionCookie Write SetSessionCookie;
|
||||
// Path of cookie used when tracing session. (may or may not be used)
|
||||
Property SessionCookiePath : String Read FSessionCookiePath write SetSessionCookiePath;
|
||||
// Variables, tracked in session.
|
||||
Property Variables[VarName : String] : String Read GetSessionVariable Write SetSessionVariable;
|
||||
end;
|
||||
|
||||
@ -1709,6 +1728,16 @@ end;
|
||||
{ TCustomSession }
|
||||
|
||||
|
||||
procedure TCustomSession.SetSessionCookie(const AValue: String);
|
||||
begin
|
||||
FSessionCookie:=AValue;
|
||||
end;
|
||||
|
||||
procedure TCustomSession.SetSessionCookiePath(const AValue: String);
|
||||
begin
|
||||
FSessionCookiePath:=AValue;
|
||||
end;
|
||||
|
||||
function TCustomSession.GetSessionID: String;
|
||||
|
||||
Var
|
||||
@ -1722,7 +1751,7 @@ end;
|
||||
|
||||
constructor TCustomSession.Create(AOwner: TComponent);
|
||||
begin
|
||||
FTimeOut:=15;
|
||||
FTimeOut:=DefaultTimeOut;
|
||||
inherited Create(AOwner);
|
||||
end;
|
||||
|
||||
@ -1731,7 +1760,8 @@ begin
|
||||
// do nothing
|
||||
end;
|
||||
|
||||
procedure TCustomSession.InitSession(ARequest: TRequest; OnNewSession,OnExpired : TNotifyEvent);
|
||||
procedure TCustomSession.InitSession(ARequest: TRequest; OnNewSession,
|
||||
OnExpired: TNotifyEvent);
|
||||
begin
|
||||
// Do nothing
|
||||
end;
|
||||
|
||||
@ -29,8 +29,6 @@ Type
|
||||
FSessionStarted : Boolean;
|
||||
FCached: Boolean;
|
||||
FIniFile : TMemInifile;
|
||||
FSessionCookie: String;
|
||||
FSessionCookiePath: String;
|
||||
FSessionDir: String;
|
||||
FTerminated :Boolean;
|
||||
SID : String;
|
||||
@ -42,9 +40,7 @@ Type
|
||||
Function GetSessionVariable(VarName : String) : String; override;
|
||||
procedure SetSessionVariable(VarName : String; const AValue: String); override;
|
||||
Property Cached : Boolean Read FCached Write FCached;
|
||||
property SessionCookie : String Read FSessionCookie Write FSessionCookie;
|
||||
Property SessionDir : String Read FSessionDir Write FSessionDir;
|
||||
Property SessionCookiePath : String Read FSessionCookiePath write FSessionCookiePath;
|
||||
Public
|
||||
Destructor Destroy; override;
|
||||
Procedure Terminate; override;
|
||||
@ -99,8 +95,6 @@ Const
|
||||
KeyLast = 'Last'; // Last seen time of session
|
||||
KeyTimeOut = 'Timeout'; // Timeout in seconds;
|
||||
|
||||
SFPWebSession = 'FPWebSession'; // Cookie name for session.
|
||||
|
||||
resourcestring
|
||||
SErrSessionTerminated = 'No web session active: Session was terminated';
|
||||
SErrNoSession = 'No web session active: Session was not started';
|
||||
@ -297,7 +291,6 @@ begin
|
||||
FTerminated := False;
|
||||
// If a exception occured during a prior request FIniFile is still not freed
|
||||
if assigned(FIniFile) then FreeIniFile;
|
||||
|
||||
If (SessionCookie='') then
|
||||
SessionCookie:=SFPWebSession;
|
||||
S:=ARequest.CookieFields.Values[SessionCookie];
|
||||
@ -353,7 +346,7 @@ begin
|
||||
C.Name:=SessionCookie;
|
||||
end;
|
||||
C.Value:=SID;
|
||||
C.Path:=FSessionCookiePath;
|
||||
C.Path:=SessionCookiePath;
|
||||
end
|
||||
else If FTerminated then
|
||||
begin
|
||||
|
||||
Loading…
Reference in New Issue
Block a user