Changeset 69 for trunk/Components/CoolWeb/Modules/UUser.pas
- Timestamp:
- Dec 30, 2011, 6:00:53 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Components/CoolWeb/Modules/UUser.pas
r61 r69 18 18 19 19 TWebUser = class 20 Id: Integer; 21 Name: string; 20 22 FullName: string; 23 Email: string; 21 24 Database: TSqlDatabase; 22 25 HandlerData: THTTPHandlerData; … … 25 28 function GetIdByName(Name: string): Integer; 26 29 function GetIdByNamePassword(Name: string; PassWord: string): Integer; 30 procedure Load; 27 31 end; 28 32 … … 42 46 43 47 resourcestring 44 SDuplicateUserItem = 'User name already used.'; 48 SDuplicateUserItem = 'User name "%s" already used.'; 49 SEmptyUserParameters = 'Missing user parameters'; 50 SUserNotFound = 'User "%s" not found'; 45 51 46 52 { TOnlineUser } … … 123 129 DbRows: TDbRows; 124 130 begin 131 if (Name = '') or (Password = '') or (Email = '') then raise Exception.Create(SEmptyUserParameters); 125 132 try 126 133 DbRows := TDbRows.Create; … … 131 138 Name + '", SHA1(CONCAT("' + Password + '", "' + Salt + '")), "' + Salt + 132 139 '", "' + Email + '", NOW())'); 133 end else raise EDuplicateItem.Create( SDuplicateUserItem);140 end else raise EDuplicateItem.Create(Format(SDuplicateUserItem, [Name])); 134 141 finally 135 142 DbRows.Free; … … 145 152 Database.Query(DbRows, 'SELECT `Id` FROM `User` WHERE `Name`="' + Name + '"'); 146 153 if DbRows.Count = 1 then Result := StrToInt(DbRows[0].Items[0].Value) 147 else raise ENotFound.Create( 'User "' + Name + '" not found');154 else raise ENotFound.Create(Format(SUserNotFound, [Name])); 148 155 finally 149 156 DBRows.Free; … … 160 167 '`Password` = SHA1(CONCAT("' + Password + '", Salt))'); 161 168 if DbRows.Count = 1 then Result := StrToInt(DbRows[0].Items[0].Value) 162 else raise ENotFound.Create('User "' + Name + '" not found'); 169 else raise ENotFound.Create(Format(SUserNotFound, [Name])); 170 finally 171 DBRows.Free; 172 end; 173 end; 174 175 procedure TWebUser.Load; 176 var 177 DbRows: TDbRows; 178 begin 179 try 180 DbRows := TDbRows.Create; 181 Database.Query(DbRows, 'SELECT * FROM `User` WHERE `Id`="' + IntToStr(Id) + '"'); 182 if DbRows.Count = 1 then begin 183 Name := DbRows[0].Values['Name']; 184 FullName := DbRows[0].Values['FullName']; 185 Email := DbRows[0].Values['Email']; 186 end else raise ENotFound.Create(Format(SUserNotFound, [IntToStr(Id)])); 163 187 finally 164 188 DBRows.Free;
Note:
See TracChangeset
for help on using the changeset viewer.