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

Legend:

Unmodified
Added
Removed
  • trunk/Modules/User/UUser.pas

    r137 r138  
    55uses
    66  Classes, SysUtils, synacode, USqlDatabase, UCommon, UHTTPServer,
    7   SpecializedDictionary;
     7  UGenerics;
    88
    99const
     
    6262  DbRows: TDbRows;
    6363  Id: Integer;
    64 begin
    65   try
    66     DbRows := TDbRows.Create;
    67     if HandlerData.Request.Cookies.SearchKey('SessionId') <> -1 then begin
     64  SessionId: string;
     65begin
     66  try
     67    DbRows := TDbRows.Create;
     68    if HandlerData.Request.Cookies.TryGetValue('SessionId', SessionId) then begin
    6869    Database.Query(DbRows, 'SELECT * FROM `UserOnline` WHERE `SessionId`="' +
    69       HandlerData.Request.Cookies.Values['SessionId'] + '"');
     70      SessionId + '"');
    7071    if DbRows.Count > 0 then begin
    7172      // Update exited
    72       Id := StrToInt(DbRows[0].Values['Id']);
    73       if DbRows[0].Values['User'] = '' then User := UnknownUser
    74         else User := StrToInt(DbRows[0].Values['User']);
     73      Id := StrToInt(DbRows[0].Items['Id']);
     74      if DbRows[0].Items['User'] = '' then User := UnknownUser
     75        else User := StrToInt(DbRows[0].Items['User']);
    7576      Database.Query(DbRows, 'UPDATE `UserOnline` SET `ActivityTime` = NOW() WHERE `Id`=' + IntToStr(Id));
    7677    end else begin
    7778      // Create new record
    7879      Database.Query(DbRows, 'INSERT INTO `UserOnline` (`User`, `ActivityTime`, `SessionId`, `ScriptName`) ' +
    79         'VALUES (NULL, NOW(), "' + HandlerData.Request.Cookies.Values['SessionId'] + '", "")');
     80        'VALUES (NULL, NOW(), "' + SessionId + '", "")');
    8081      Id := Database.LastInsertId;
    8182      User := UnknownUser;
     
    9091var
    9192  DbRows: TDbRows;
     93  SessionId: string;
    9294begin
    9395  Logout;
     96  if HandlerData.Request.Cookies.TryGetValue('SessionId', SessionId) then
    9497  try
    9598    DbRows := TDbRows.Create;
     
    97100    if DbRows.Count > 0 then begin
    98101      Database.Query(DbRows, 'UPDATE `UserOnline` SET `User` = ' + IntToStr(User) + ', `LoginTime` = NOW() WHERE `SessionId`="' +
    99         HandlerData.Request.Cookies.Values['SessionId'] + '"');
     102        SessionId + '"');
    100103      Self.User := User;
    101104    end else
     
    109112var
    110113  DbRows: TDbRows;
     114  SessionId: string;
    111115begin
    112116  if Id = UnknownUser then Update;
    113117  if User <> UnknownUser then begin
     118    if HandlerData.Request.Cookies.TryGetValue('SessionId', SessionId) then
    114119    try
    115120      DbRows := TDbRows.Create;
    116121      Database.Query(DbRows, 'UPDATE `UserOnline` SET `User` = NULL WHERE `SessionId`="' +
    117         HandlerData.Request.Cookies.Values['SessionId'] + '"');
     122        SessionId + '"');
    118123    finally
    119124      DbRows.Free;
     
    197202    DbRows := TDbRows.Create;
    198203    Database.Query(DbRows, 'SELECT `Id` FROM `User` WHERE `Name`="' + Name + '"');
    199     if DbRows.Count = 1 then Result := StrToInt(DbRows[0].Items[0].Value)
     204    if DbRows.Count = 1 then Result := StrToInt(DbRows[0].Items['Id'])
    200205      else Result := UnknownUser;
    201206  finally
     
    212217    Database.Query(DbRows, 'SELECT `Id` FROM `User` WHERE `Name`="' + Name + '" AND ' +
    213218      '`Password` = SHA1(CONCAT("' + Password + '", Salt))');
    214     if DbRows.Count = 1 then Result := StrToInt(DbRows[0].Items[0].Value)
     219    if DbRows.Count = 1 then Result := StrToInt(DbRows[0].Items['Id'])
    215220      else Result := UnknownUser;
    216221  finally
     
    228233    Database.Query(DbRows, 'SELECT * FROM `User` WHERE `Id`="' + IntToStr(Id) + '"');
    229234    if DbRows.Count = 1 then begin
    230       Name := DbRows[0].Values['Name'];
    231       FullName := DbRows[0].Values['FullName'];
    232       Email := DbRows[0].Values['Email'];
     235      Name := DbRows[0].Items['Name'];
     236      FullName := DbRows[0].Items['FullName'];
     237      Email := DbRows[0].Items['Email'];
    233238    end else
    234239      raise ENotFound.Create(Format(SUserNotFound, [IntToStr(Id)]));
     
    254259    try
    255260      DbRows2 := TDbRows.Create;
    256       OperationId := StrToInt(DbRows[0].Values['Id']);
     261      OperationId := StrToInt(DbRows[0].Items['Id']);
    257262
    258263      // Check user-operation relation
     
    268273        '`User` = ' + IntToStr(Id) + ' AND `AssignedGroup` IS NOT NULL');
    269274      if DbRows2.Count > 0 then begin
    270         if CheckGroupPermission(StrToInt(DbRows2[0].Values['AssignedGroup']), OperationId) then begin
     275        if CheckGroupPermission(StrToInt(DbRows2[0].Items['AssignedGroup']), OperationId) then begin
    271276          Result := True;
    272277          Exit;
     
    301306        '`User` = ' + IntToStr(Id) + ' AND `AssignedGroup` IS NOT NULL');
    302307      if DbRows2.Count > 0 then begin
    303         if CheckGroupPermission(StrToInt(DbRows2[0].Values['AssignedGroup']), Operation) then begin
     308        if CheckGroupPermission(StrToInt(DbRows2[0].Items['AssignedGroup']), Operation) then begin
    304309          Result := True;
    305310          Exit;
Note: See TracChangeset for help on using the changeset viewer.