Changeset 36 for trunk/Application/UUser.pas
- Timestamp:
- Oct 29, 2010, 10:44:13 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Application/UUser.pas
r33 r36 8 8 Classes, SysUtils, synacode, USqlDatabase, UCommon, UHTTPServer; 9 9 10 const 11 AnonymousUserId = 1; 12 10 13 type 11 14 EDuplicateItem = class(Exception); … … 15 18 16 19 TWebUser = class 20 FullName: string; 17 21 Database: TSqlDatabase; 18 22 HandlerData: THTTPHandlerData; … … 47 51 Id: Integer; 48 52 begin 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 54 71 DbRows.Free; 55 DbRows := Database.Query('UPDATE `UserOnline` SET `ActivityTime` = NOW() WHERE `Id`=' + IntToStr(Id));56 end else begin57 // Create new record58 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;62 72 end; 63 DbRows.Destroy;64 73 end; 65 74 … … 69 78 begin 70 79 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; 74 86 Self.User := User; 75 87 end; … … 79 91 DbRows: TDbRows; 80 92 begin 81 if Id = 1then Update;82 if User <> 1then begin83 DbRows := Database.Query('UPDATE `UserOnline` SET `User` = 1WHERE `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`="' + 84 96 HandlerData.Request.Cookies.Values['SessionId'] + '"'); 85 97 DbRows.Destroy; 86 User := 1;98 User := AnonymousUserId; 87 99 end; 88 100 end;
Note:
See TracChangeset
for help on using the changeset viewer.