Changeset 310 for Network


Ignore:
Timestamp:
Jan 4, 2012, 2:23:16 PM (13 years ago)
Author:
chronos
Message:
  • Modified: Enhanced TWebUser and TWebOnlineUser classes.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • Network/CoolWeb/Modules/UUser.pas

    r94 r310  
    1818
    1919  TWebUser = class
     20    Id: Integer;
     21    Name: string;
    2022    FullName: string;
     23    Email: string;
    2124    Database: TSqlDatabase;
    2225    HandlerData: THTTPHandlerData;
     
    2528    function GetIdByName(Name: string): Integer;
    2629    function GetIdByNamePassword(Name: string; PassWord: string): Integer;
     30    procedure Load;
    2731  end;
    2832
     
    4246
    4347resourcestring
    44   SDuplicateUserItem = 'User name already used.';
     48  SDuplicateUserItem = 'User name "%s" already used.';
     49  SEmptyUserParameters = 'Missing user parameters';
     50  SUserNotFound = 'User "%s" not found';
    4551
    4652{ TOnlineUser }
     
    123129  DbRows: TDbRows;
    124130begin
     131  if (Name = '') or (Password = '') or (Email = '') then raise Exception.Create(SEmptyUserParameters);
    125132  try
    126133    DbRows := TDbRows.Create;
     
    131138        Name + '", SHA1(CONCAT("' + Password + '", "' + Salt + '")), "' + Salt +
    132139        '", "' + Email + '", NOW())');
    133     end else raise EDuplicateItem.Create(SDuplicateUserItem);
     140    end else raise EDuplicateItem.Create(Format(SDuplicateUserItem, [Name]));
    134141  finally
    135142    DbRows.Free;
     
    145152    Database.Query(DbRows, 'SELECT `Id` FROM `User` WHERE `Name`="' + Name + '"');
    146153    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]));
    148155  finally
    149156    DBRows.Free;
     
    160167      '`Password` = SHA1(CONCAT("' + Password + '", Salt))');
    161168    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;
     173end;
     174
     175procedure TWebUser.Load;
     176var
     177  DbRows: TDbRows;
     178begin
     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)]));
    163187  finally
    164188    DBRows.Free;
Note: See TracChangeset for help on using the changeset viewer.