Changeset 138 for trunk/Modules/User/UUser.pas
- Timestamp:
- Sep 9, 2022, 8:20:25 PM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Modules/User/UUser.pas
r137 r138 5 5 uses 6 6 Classes, SysUtils, synacode, USqlDatabase, UCommon, UHTTPServer, 7 SpecializedDictionary;7 UGenerics; 8 8 9 9 const … … 62 62 DbRows: TDbRows; 63 63 Id: Integer; 64 begin 65 try 66 DbRows := TDbRows.Create; 67 if HandlerData.Request.Cookies.SearchKey('SessionId') <> -1 then begin 64 SessionId: string; 65 begin 66 try 67 DbRows := TDbRows.Create; 68 if HandlerData.Request.Cookies.TryGetValue('SessionId', SessionId) then begin 68 69 Database.Query(DbRows, 'SELECT * FROM `UserOnline` WHERE `SessionId`="' + 69 HandlerData.Request.Cookies.Values['SessionId']+ '"');70 SessionId + '"'); 70 71 if DbRows.Count > 0 then begin 71 72 // Update exited 72 Id := StrToInt(DbRows[0]. Values['Id']);73 if DbRows[0]. Values['User'] = '' then User := UnknownUser74 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']); 75 76 Database.Query(DbRows, 'UPDATE `UserOnline` SET `ActivityTime` = NOW() WHERE `Id`=' + IntToStr(Id)); 76 77 end else begin 77 78 // Create new record 78 79 Database.Query(DbRows, 'INSERT INTO `UserOnline` (`User`, `ActivityTime`, `SessionId`, `ScriptName`) ' + 79 'VALUES (NULL, NOW(), "' + HandlerData.Request.Cookies.Values['SessionId']+ '", "")');80 'VALUES (NULL, NOW(), "' + SessionId + '", "")'); 80 81 Id := Database.LastInsertId; 81 82 User := UnknownUser; … … 90 91 var 91 92 DbRows: TDbRows; 93 SessionId: string; 92 94 begin 93 95 Logout; 96 if HandlerData.Request.Cookies.TryGetValue('SessionId', SessionId) then 94 97 try 95 98 DbRows := TDbRows.Create; … … 97 100 if DbRows.Count > 0 then begin 98 101 Database.Query(DbRows, 'UPDATE `UserOnline` SET `User` = ' + IntToStr(User) + ', `LoginTime` = NOW() WHERE `SessionId`="' + 99 HandlerData.Request.Cookies.Values['SessionId']+ '"');102 SessionId + '"'); 100 103 Self.User := User; 101 104 end else … … 109 112 var 110 113 DbRows: TDbRows; 114 SessionId: string; 111 115 begin 112 116 if Id = UnknownUser then Update; 113 117 if User <> UnknownUser then begin 118 if HandlerData.Request.Cookies.TryGetValue('SessionId', SessionId) then 114 119 try 115 120 DbRows := TDbRows.Create; 116 121 Database.Query(DbRows, 'UPDATE `UserOnline` SET `User` = NULL WHERE `SessionId`="' + 117 HandlerData.Request.Cookies.Values['SessionId']+ '"');122 SessionId + '"'); 118 123 finally 119 124 DbRows.Free; … … 197 202 DbRows := TDbRows.Create; 198 203 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']) 200 205 else Result := UnknownUser; 201 206 finally … … 212 217 Database.Query(DbRows, 'SELECT `Id` FROM `User` WHERE `Name`="' + Name + '" AND ' + 213 218 '`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']) 215 220 else Result := UnknownUser; 216 221 finally … … 228 233 Database.Query(DbRows, 'SELECT * FROM `User` WHERE `Id`="' + IntToStr(Id) + '"'); 229 234 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']; 233 238 end else 234 239 raise ENotFound.Create(Format(SUserNotFound, [IntToStr(Id)])); … … 254 259 try 255 260 DbRows2 := TDbRows.Create; 256 OperationId := StrToInt(DbRows[0]. Values['Id']);261 OperationId := StrToInt(DbRows[0].Items['Id']); 257 262 258 263 // Check user-operation relation … … 268 273 '`User` = ' + IntToStr(Id) + ' AND `AssignedGroup` IS NOT NULL'); 269 274 if DbRows2.Count > 0 then begin 270 if CheckGroupPermission(StrToInt(DbRows2[0]. Values['AssignedGroup']), OperationId) then begin275 if CheckGroupPermission(StrToInt(DbRows2[0].Items['AssignedGroup']), OperationId) then begin 271 276 Result := True; 272 277 Exit; … … 301 306 '`User` = ' + IntToStr(Id) + ' AND `AssignedGroup` IS NOT NULL'); 302 307 if DbRows2.Count > 0 then begin 303 if CheckGroupPermission(StrToInt(DbRows2[0]. Values['AssignedGroup']), Operation) then begin308 if CheckGroupPermission(StrToInt(DbRows2[0].Items['AssignedGroup']), Operation) then begin 304 309 Result := True; 305 310 Exit;
Note:
See TracChangeset
for help on using the changeset viewer.