Ignore:
Timestamp:
Sep 9, 2022, 8:20:25 PM (22 months ago)
Author:
chronos
Message:
  • Modified: Removed TemplateGenerics package. Generics usage replaced by standard Generics.Collections.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Packages/CoolWeb/Modules/UWebUser.pas

    r137 r138  
    55uses
    66  Classes, SysUtils, synacode, USqlDatabase, UCommon, UHTTPServer,
    7   SpecializedDictionary;
     7  UGenerics;
    88
    99const
     
    6060  DbRows: TDbRows;
    6161  Id: Integer;
    62 begin
    63   try
    64     DbRows := TDbRows.Create;
    65     if HandlerData.Request.Cookies.SearchKey('SessionId') <> -1 then begin
     62  Value: string;
     63begin
     64  try
     65    DbRows := TDbRows.Create;
     66    if HandlerData.Request.Cookies.TryGetValue('SessionId', Value) then begin
    6667    Database.Query(DbRows, 'SELECT * FROM `UserOnline` WHERE `SessionId`="' +
    67       HandlerData.Request.Cookies.Values['SessionId'] + '"');
     68      Value + '"');
    6869    if DbRows.Count > 0 then begin
    6970      // Update exited
    70       Id := StrToInt(DbRows[0].Values['Id']);
    71       User := StrToInt(DbRows[0].Values['User']);
     71      Id := StrToInt(DbRows[0].Items['Id']);
     72      User := StrToInt(DbRows[0].Items['User']);
    7273      Database.Query(DbRows, 'UPDATE `UserOnline` SET `ActivityTime` = NOW() WHERE `Id`=' + IntToStr(Id));
    7374    end else begin
    7475      // Create new record
    7576      Database.Query(DbRows, 'INSERT INTO `UserOnline` (`User`, `ActivityTime`, `SessionId`, `ScriptName`) ' +
    76         'VALUES (1, NOW(), "' + HandlerData.Request.Cookies.Values['SessionId'] + '", "")');
     77        'VALUES (1, NOW(), "' + Value + '", "")');
    7778      Id := Database.LastInsertId;
    7879      User := 1;
     
    8889var
    8990  DbRows: TDbRows;
     91  SessionId: string;
    9092begin
    9193  Logout;
     94  if HandlerData.Request.Cookies.TryGetValue('SessionId', SessionId) then
    9295  try
    9396    DbRows := TDbRows.Create;
    9497    Database.Query(DbRows, 'UPDATE `UserOnline` SET `User` = ' + IntToStr(User) + ', `LoginTime` = NOW() WHERE `SessionId`="' +
    95       HandlerData.Request.Cookies.Values['SessionId'] + '"');
     98      SessionId + '"');
    9699  finally
    97100    DbRows.Free;
     
    103106var
    104107  DbRows: TDbRows;
     108  SessionId: string;
    105109begin
    106110  if Id = AnonymousUserId then Update;
    107   if User <> AnonymousUserId then begin
     111  if (User <> AnonymousUserId) and
     112    HandlerData.Request.Cookies.TryGetValue('SessionId', SessionId) then begin
    108113    try
    109114      DbRows := TDbRows.Create;
    110115      Database.Query(DbRows, 'UPDATE `UserOnline` SET `User` = ' + IntToStr(AnonymousUserId) + ' WHERE `SessionId`="' +
    111         HandlerData.Request.Cookies.Values['SessionId'] + '"');
     116        SessionId + '"');
    112117    finally
    113118      DbRows.Free;
     
    178183    DbRows := TDbRows.Create;
    179184    Database.Query(DbRows, 'SELECT `Id` FROM `User` WHERE `Name`="' + Name + '"');
    180     if DbRows.Count = 1 then Result := StrToInt(DbRows[0].Items[0].Value)
     185    if DbRows.Count = 1 then Result := StrToInt(DbRows[0].Items['Id'])
    181186      else Result := -1;
    182187  finally
     
    193198    Database.Query(DbRows, 'SELECT `Id` FROM `User` WHERE `Name`="' + Name + '" AND ' +
    194199      '`Password` = SHA1(CONCAT("' + Password + '", Salt))');
    195     if DbRows.Count = 1 then Result := StrToInt(DbRows[0].Items[0].Value)
     200    if DbRows.Count = 1 then Result := StrToInt(DbRows[0].Items['Id'])
    196201      else Result := -1;
    197202  finally
     
    208213    Database.Query(DbRows, 'SELECT * FROM `User` WHERE `Id`="' + IntToStr(Id) + '"');
    209214    if DbRows.Count = 1 then begin
    210       Name := DbRows[0].Values['Name'];
    211       FullName := DbRows[0].Values['FullName'];
    212       Email := DbRows[0].Values['Email'];
     215      Name := DbRows[0].Items['Name'];
     216      FullName := DbRows[0].Items['FullName'];
     217      Email := DbRows[0].Items['Email'];
    213218    end; // else raise ENotFound.Create(Format(SUserNotFound, [IntToStr(Id)]));
    214219  finally
     
    233238    try
    234239      DbRows2 := TDbRows.Create;
    235       OperationId := StrToInt(DbRows[0].Values['Id']);
     240      OperationId := StrToInt(DbRows[0].Items['Id']);
    236241
    237242      // Check user-operation relation
     
    247252        '`User` = ' + IntToStr(Id) + ' AND `AssignedGroup` IS NOT NULL');
    248253      if DbRows2.Count > 0 then begin
    249         if CheckGroupPermission(StrToInt(DbRows2[0].Values['AssignedGroup']), OperationId) then begin
     254        if CheckGroupPermission(StrToInt(DbRows2[0].Items['AssignedGroup']), OperationId) then begin
    250255          Result := True;
    251256          Exit;
     
    280285      '`User` = ' + IntToStr(Id) + ' AND `AssignedGroup` IS NOT NULL');
    281286    if DbRows2.Count > 0 then begin
    282       if CheckGroupPermission(StrToInt(DbRows2[0].Values['AssignedGroup']), Operation) then begin
     287      if CheckGroupPermission(StrToInt(DbRows2[0].Items['AssignedGroup']), Operation) then begin
    283288        Result := True;
    284289        Exit;
Note: See TracChangeset for help on using the changeset viewer.