Changeset 138 for trunk/Modules/User
- Timestamp:
- Sep 9, 2022, 8:20:25 PM (2 years ago)
- Location:
- trunk/Modules/User
- Files:
-
- 2 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; -
trunk/Modules/User/UUserControlPage.pas
r137 r138 87 87 AddNewAction('Přihlásit', 'Login'); 88 88 end; 89 if HandlerData.Request.Post. SearchKey('Login') <> -1then begin89 if HandlerData.Request.Post.ContainsKey('Login') then begin 90 90 Form.Load(HandlerData.Request.Post); 91 with THtmlString(SubItems.AddNew(THtmlString.Create))do91 with SubItems.AddString do 92 92 Text := 'Přihlášení uživatele: ' + TQueryFormGroup(Form.Groups[0]).Rows.FindByName('UserName').Value.Value; 93 93 UserId := ModuleUser.User.GetIdByNamePassword(TQueryFormGroup(Form.Groups[0]).Rows.FindByName('UserName').Value.Value, 94 94 TQueryFormGroup(Form.Groups[0]).Rows.FindByName('Password').Value.Value); 95 95 if UserId = -1 then begin 96 with THtmlString(SubItems.AddNew(THtmlString.Create))do96 with SubItems.AddString do 97 97 Text := '<br/>Chybné jméno nebo heslo'; 98 98 end else ModuleUser.UserOnline.Login(UserId); 99 99 Form.Free; 100 100 end else 101 SubItems.Add New(Form);101 SubItems.Add(Form); 102 102 end; 103 103 end; … … 144 144 AddNewAction('Registrovat', 'Register'); 145 145 end; 146 if HandlerData.Request.Post. SearchKey('Register') <> -1then146 if HandlerData.Request.Post.ContainsKey('Register') then 147 147 with HandlerData.Request do begin 148 148 Form.Load(HandlerData.Request.Post); 149 with THtmlString(SubItems.AddNew(THtmlString.Create))do149 with SubItems.AddString do 150 150 Text := 'Registrace uživatele: ' + TQueryFormGroup(Form.Groups[0]).Rows.FindByName('UserName').Value.Value; 151 151 ModuleUser.User.Add(TQueryFormGroup(Form.Groups[0]).Rows.FindByName('UserName').Value.Value, … … 156 156 if UserId <> -1 then ModuleUser.UserOnline.Login(UserId); 157 157 Form.Free; 158 end else SubItems.Add New(Form);158 end else SubItems.Add(Form); 159 159 end; 160 160 end; … … 164 164 with TWebSession(HandlerData), Core, HtmlDocument.Body do begin 165 165 ModuleUser.UserOnline.Logout; 166 with THtmlString(SubItems.AddNew(THtmlString.Create))do166 with SubItems.AddString do 167 167 Text := 'Uživatel odhlášen'; 168 168 end; … … 213 213 AddNewAction('Uložit', 'Save'); 214 214 end; 215 if HandlerData.Request.Post. SearchKey('Save') <> -1then215 if HandlerData.Request.Post.ContainsKey('Save') then 216 216 with HandlerData.Request do begin 217 217 Form.Load(HandlerData.Request.Post); 218 with THtmlString(SubItems.AddNew(THtmlString.Create))do218 with SubItems.AddString do 219 219 Text := 'Profil uživatele: ' + TQueryFormGroup(Form.Groups[0]).Rows.FindByName('UserName').Value.Value + ' uložen'; 220 220 ModuleUser.User.Name := TQueryFormGroup(Form.Groups[0]).Rows.FindByName('UserName').Value.Value; … … 223 223 ModuleUser.User.Save; 224 224 Form.Free; 225 end else SubItems.Add New(Form);225 end else SubItems.Add(Form); 226 226 end; 227 227 end;
Note:
See TracChangeset
for help on using the changeset viewer.