Changeset 98 for trunk/Packages/CoolWeb
- Timestamp:
- Oct 2, 2012, 12:24:00 PM (12 years ago)
- Location:
- trunk/Packages/CoolWeb
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Packages/CoolWeb/Modules/UUser.pas
r97 r98 6 6 7 7 uses 8 Classes, SysUtils, synacode, USqlDatabase, UCommon, UHTTPServer; 8 Classes, SysUtils, synacode, USqlDatabase, UCommon, UHTTPServer, 9 SpecializedDictionary; 9 10 10 11 const … … 24 25 Database: TSqlDatabase; 25 26 HandlerData: THTTPHandlerData; 27 procedure Save; 26 28 procedure Delete(Id: Integer); 27 29 procedure Add(Name, Password, Email: string); … … 112 114 { TUser } 113 115 116 procedure TWebUser.Save; 117 var 118 DbRows: TDbRows; 119 Data: TDictionaryStringString; 120 begin 121 try 122 DbRows := TDbRows.Create; 123 Data := TDictionaryStringString.Create; 124 Data.Add('FullName', FullName); 125 Data.Add('Email', Email); 126 Data.Add('Name', Name); 127 //Data.Add('Password', 'SHA1(CONCAT("' + Password + '", "' + Salt + '"))'); 128 Database.Update('User', Data, '`Id`=' + IntToStr(Id)); 129 finally 130 Data.Free; 131 DbRows.Free; 132 end; 133 end; 134 114 135 procedure TWebUser.Delete(Id: Integer); 115 136 var … … 129 150 DbRows: TDbRows; 130 151 begin 131 if (Name = '') or (Password = '') or (Email = '') then raise Exception.Create(SEmptyUserParameters); 152 if (Name = '') or (Password = '') or (Email = '') then 153 raise Exception.Create(SEmptyUserParameters); 132 154 try 133 155 DbRows := TDbRows.Create; … … 135 157 if DbRows.Count = 0 then begin 136 158 Salt := EncodeBase64(Copy(BinToHexString(SHA1(FloatToStr(Now))), 1, 8)); 137 Database.Query(DbRows, 'INSERT INTO `User` (`Name`, `Password`, `Salt`, `Email`, `RegistrationTime` ) VALUES ("' +159 Database.Query(DbRows, 'INSERT INTO `User` (`Name`, `Password`, `Salt`, `Email`, `RegistrationTime`, `FullName`) VALUES ("' + 138 160 Name + '", SHA1(CONCAT("' + Password + '", "' + Salt + '")), "' + Salt + 139 '", "' + Email + '", NOW() )');161 '", "' + Email + '", NOW(), "")'); 140 162 end else raise EDuplicateItem.Create(Format(SDuplicateUserItem, [Name])); 141 163 finally … … 152 174 Database.Query(DbRows, 'SELECT `Id` FROM `User` WHERE `Name`="' + Name + '"'); 153 175 if DbRows.Count = 1 then Result := StrToInt(DbRows[0].Items[0].Value) 154 else raise ENotFound.Create(Format(SUserNotFound, [Name]));176 else Result := -1; 155 177 finally 156 178 DBRows.Free; … … 167 189 '`Password` = SHA1(CONCAT("' + Password + '", Salt))'); 168 190 if DbRows.Count = 1 then Result := StrToInt(DbRows[0].Items[0].Value) 169 else raise ENotFound.Create(Format(SUserNotFound, [Name]));191 else Result := -1; 170 192 finally 171 193 DBRows.Free; … … 184 206 FullName := DbRows[0].Values['FullName']; 185 207 Email := DbRows[0].Values['Email']; 186 end else raise ENotFound.Create(Format(SUserNotFound, [IntToStr(Id)]));208 end; // else raise ENotFound.Create(Format(SUserNotFound, [IntToStr(Id)])); 187 209 finally 188 210 DBRows.Free; -
trunk/Packages/CoolWeb/WebServer/UHTTPServerTCP.pas
r96 r98 42 42 HandlerData: THTTPHandlerData; 43 43 I: Integer; 44 ContentLength: Integer; 44 45 begin 45 46 with TTCPClientThread(Sender), Socket do begin … … 81 82 Inc(LineIndex); 82 83 until Line = ''; 84 85 if Request.Method = 'POST' then begin 86 ContentLength := StrToInt(Request.Headers.Values['Content-Length']); 87 SetLength(Line, ContentLength); 88 RecvBufferEx(PByte(Line), ContentLength, 1000); 89 Request.Post.Parse(Line); 90 end; 83 91 finally 84 92 LineParts.Free; 85 93 end; 94 95 86 96 87 97 // Process cookies … … 95 105 Response.Content.Clear; 96 106 Response.Headers.Add('Content-Type', 'text/html'); 107 108 97 109 98 110 if Assigned(OnRequest) then OnRequest(HandlerData)
Note:
See TracChangeset
for help on using the changeset viewer.