Ignore:
Timestamp:
Oct 29, 2010, 10:44:13 PM (14 years ago)
Author:
george
Message:
  • Přidáno: Neodokončená třída TPageList a TQueryString.
  • Přidáno: Částečná podpora pro přihlašování uživatelů.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Application/UUser.pas

    r33 r36  
    88  Classes, SysUtils, synacode, USqlDatabase, UCommon, UHTTPServer;
    99
     10const
     11  AnonymousUserId = 1;
     12
    1013type
    1114  EDuplicateItem = class(Exception);
     
    1518
    1619  TWebUser = class
     20    FullName: string;
    1721    Database: TSqlDatabase;
    1822    HandlerData: THTTPHandlerData;
     
    4751  Id: Integer;
    4852begin
    49   DbRows := Database.Query('SELECT * FROM `UserOnline` WHERE `SessionId`="' +
    50     HandlerData.Request.Cookies.Values['SessionId'] + '"');
    51   if DbRows.Count > 0 then begin
    52     // Update exited
    53     Id := StrToInt(DbRows[0].Values['Id']);
     53  try
     54    DbRows := Database.Query('SELECT * FROM `UserOnline` WHERE `SessionId`="' +
     55      HandlerData.Request.Cookies.Values['SessionId'] + '"');
     56    if DbRows.Count > 0 then begin
     57      // Update exited
     58      Id := StrToInt(DbRows[0].Values['Id']);
     59      User := StrToInt(DbRows[0].Values['User']);
     60      DbRows.Free;
     61      DbRows := Database.Query('UPDATE `UserOnline` SET `ActivityTime` = NOW() WHERE `Id`=' + IntToStr(Id));
     62    end else begin
     63      // Create new record
     64      DbRows.Free;
     65      DbRows := Database.Query('INSERT INTO `UserOnline` (`User`, `ActivityTime`, `SessionId`) ' +
     66        'VALUES (1, NOW(), "' + HandlerData.Request.Cookies.Values['SessionId'] + '")');
     67      Id := Database.LastInsertId;
     68      User := 1;
     69    end;
     70  finally
    5471    DbRows.Free;
    55     DbRows := Database.Query('UPDATE `UserOnline` SET `ActivityTime` = NOW() WHERE `Id`=' + IntToStr(Id));
    56   end else begin
    57     // Create new record
    58     DbRows.Free;
    59     DbRows := Database.Query('INSERT INTO `UserOnline` (`User`, `ActivityTime`, `SessionId`) ' +
    60       'VALUES (1, NOW(), "' + HandlerData.Request.Cookies.Values['SessionId'] + '")');
    61     Id := Database.LastInsertId;
    6272  end;
    63   DbRows.Destroy;
    6473end;
    6574
     
    6978begin
    7079  Logout;
    71   DbRows := Database.Query('UPDATE `UserOnline` SET `User` = ' + IntToStr(User) + ', `LoginTime` = NOW() WHERE `SessionId`="' +
    72     HandlerData.Request.Cookies.Values['SessionId'] + '"');
    73   DbRows.Destroy;
     80  try
     81    DbRows := Database.Query('UPDATE `UserOnline` SET `User` = ' + IntToStr(User) + ', `LoginTime` = NOW() WHERE `SessionId`="' +
     82      HandlerData.Request.Cookies.Values['SessionId'] + '"');
     83  finally
     84    DbRows.Free;
     85  end;
    7486  Self.User := User;
    7587end;
     
    7991  DbRows: TDbRows;
    8092begin
    81   if Id = 1 then Update;
    82   if User <> 1 then begin
    83     DbRows := Database.Query('UPDATE `UserOnline` SET `User` = 1 WHERE `SessionId`="' +
     93  if Id = AnonymousUserId then Update;
     94  if User <> AnonymousUserId then begin
     95    DbRows := Database.Query('UPDATE `UserOnline` SET `User` = ' + IntToStr(AnonymousUserId) + ' WHERE `SessionId`="' +
    8496      HandlerData.Request.Cookies.Values['SessionId'] + '"');
    8597    DbRows.Destroy;
    86     User := 1;
     98    User := AnonymousUserId;
    8799  end;
    88100end;
Note: See TracChangeset for help on using the changeset viewer.