Ignore:
Timestamp:
Dec 30, 2011, 6:00:53 PM (13 years ago)
Author:
chronos
Message:
  • Přidáno: Částečně zprovozněna registrace a přihlašování uživatelů.
Location:
trunk/Components/CoolWeb
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Components/CoolWeb/Modules/UUser.pas

    r61 r69  
    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;
  • trunk/Components/CoolWeb/WebServer/UWebApp.pas

    r68 r69  
    2727  TWebApp = class(TCustomApplication)
    2828  private
     29    FOnBeforePageProduce: TOnProduceEvent;
    2930    FOnInitialize: TNotifyEvent;
    3031    FServerType: THTTPServerType;
     
    4243    constructor Create(AOwner: TComponent); override;
    4344    destructor Destroy; override;
     45    property OnBeforePageProduce: TOnProduceEvent read FOnBeforePageProduce write FOnBeforePageProduce;
    4446    property OnInitialize: TNotifyEvent read FOnInitialize write FOnInitialize;
    4547    property ServerType: THTTPServerType read FServerType write SetServerType;
     
    133135    //Request.QueryParts[0] := 'uzivatel';
    134136    //Request.QueryParts[1] := 'prihlaseni';
     137    if Assigned(FOnBeforePageProduce) then
     138      FOnBeforePageProduce(HandlerData);
    135139
    136140    if Request.QueryParts.Count > 0 then PageName := Request.QueryParts[0]
     
    172176    hstdout := @stderr;
    173177    Writeln(hstdout^, 'An unhandled exception occurred: ' + E.Message + '<br>');
    174     WriteLn(hstdout^, StringReplace(DumpExceptionCallStack(E), LineEnding, '<br>', [rfReplaceAll]));
     178    WriteLn(hstdout^, DumpExceptionCallStack(E));
    175179  end;
    176180end;
Note: See TracChangeset for help on using the changeset viewer.