fix: session logout not working

This commit is contained in:
Massimo Melina 2020-05-09 22:53:10 +02:00
parent 6bf82353b8
commit 8ff8a9ca22
2 changed files with 17 additions and 3 deletions

View File

@ -213,6 +213,7 @@ type
function getHeader(h:string):string; // extract the value associated to the specified header field function getHeader(h:string):string; // extract the value associated to the specified header field
function getCookie(k:string):string; function getCookie(k:string):string;
procedure setCookie(k, v:string; pairs:array of string; extra:string=''); procedure setCookie(k, v:string; pairs:array of string; extra:string='');
procedure delCookie(k:string);
function getBuffer():ansistring; function getBuffer():ansistring;
function initInputStream():boolean; function initInputStream():boolean;
property address:string read P_address; // other peer ip address property address:string read P_address; // other peer ip address
@ -1016,6 +1017,9 @@ if request.cookies = NIL then
result:=decodeURL(ansistring(trim(request.cookies.values[k]))); result:=decodeURL(ansistring(trim(request.cookies.values[k])));
end; // getCookie end; // getCookie
procedure ThttpConn.delCookie(k:string);
begin setCookie(k,'', ['expires','Thu, 01-Jan-70 00:00:01 GMT']) end;
procedure ThttpConn.setCookie(k, v:string; pairs:array of string; extra:string=''); procedure ThttpConn.setCookie(k, v:string; pairs:array of string; extra:string='');
var var
i: integer; i: integer;

View File

@ -355,6 +355,7 @@ type
function sessionGet(k:string):string; function sessionGet(k:string):string;
procedure sessionSet(k, v:string); procedure sessionSet(k, v:string);
procedure disconnect(reason:string); procedure disconnect(reason:string);
procedure logout();
end; // Tconndata end; // Tconndata
Tautosave = record Tautosave = record
@ -2300,6 +2301,16 @@ disconnectReason:=reason;
conn.disconnect(); conn.disconnect();
end; // disconnect end; // disconnect
procedure TconnData.logout();
begin
freeAndNIL(session);
sessions.delete(sessions.IndexOf(sessionID));
sessionID:='';
usr:='';
pwd:='';
conn.delCookie(SESSION_COOKIE);
end; // logout
function Tconndata.sessionGet(k:string):string; function Tconndata.sessionGet(k:string):string;
begin begin
try result:=session.values[k]; try result:=session.values[k];
@ -4469,7 +4480,7 @@ else if tplLast <> 0 then
end; // keepTplUpdated end; // keepTplUpdated
function getNewSID():string; function getNewSID():string;
begin result:=floatToStr(random()) end; begin result:=replaceStr(base64encode(str_(now())+str_(random())), '=','') end;
procedure setNewTplFile(fn:string); procedure setNewTplFile(fn:string);
begin begin
@ -5206,8 +5217,7 @@ var
if s = '' then // logout if s = '' then // logout
begin begin
s:='ok'; s:='ok';
data.usr:=''; data.logout();
data.pwd:='';
end end
else else
s:='username not found' s:='username not found'