Changeset 98 for trunk/Packages


Ignore:
Timestamp:
Oct 2, 2012, 12:24:00 PM (12 years ago)
Author:
chronos
Message:
  • Upraveno: Přihlašování, odhlašování, registrace a nastavení profilu uživatele.
Location:
trunk/Packages/CoolWeb
Files:
2 edited

Legend:

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

    r97 r98  
    66
    77uses
    8   Classes, SysUtils, synacode, USqlDatabase, UCommon, UHTTPServer;
     8  Classes, SysUtils, synacode, USqlDatabase, UCommon, UHTTPServer,
     9  SpecializedDictionary;
    910
    1011const
     
    2425    Database: TSqlDatabase;
    2526    HandlerData: THTTPHandlerData;
     27    procedure Save;
    2628    procedure Delete(Id: Integer);
    2729    procedure Add(Name, Password, Email: string);
     
    112114{ TUser }
    113115
     116procedure TWebUser.Save;
     117var
     118  DbRows: TDbRows;
     119  Data: TDictionaryStringString;
     120begin
     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;
     133end;
     134
    114135procedure TWebUser.Delete(Id: Integer);
    115136var
     
    129150  DbRows: TDbRows;
    130151begin
    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);
    132154  try
    133155    DbRows := TDbRows.Create;
     
    135157    if DbRows.Count = 0 then begin
    136158      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 ("' +
    138160        Name + '", SHA1(CONCAT("' + Password + '", "' + Salt + '")), "' + Salt +
    139         '", "' + Email + '", NOW())');
     161        '", "' + Email + '", NOW(), "")');
    140162    end else raise EDuplicateItem.Create(Format(SDuplicateUserItem, [Name]));
    141163  finally
     
    152174    Database.Query(DbRows, 'SELECT `Id` FROM `User` WHERE `Name`="' + Name + '"');
    153175    if DbRows.Count = 1 then Result := StrToInt(DbRows[0].Items[0].Value)
    154       else raise ENotFound.Create(Format(SUserNotFound, [Name]));
     176      else Result := -1;
    155177  finally
    156178    DBRows.Free;
     
    167189      '`Password` = SHA1(CONCAT("' + Password + '", Salt))');
    168190    if DbRows.Count = 1 then Result := StrToInt(DbRows[0].Items[0].Value)
    169       else raise ENotFound.Create(Format(SUserNotFound, [Name]));
     191      else Result := -1;
    170192  finally
    171193    DBRows.Free;
     
    184206      FullName := DbRows[0].Values['FullName'];
    185207      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)]));
    187209  finally
    188210    DBRows.Free;
  • trunk/Packages/CoolWeb/WebServer/UHTTPServerTCP.pas

    r96 r98  
    4242  HandlerData: THTTPHandlerData;
    4343  I: Integer;
     44  ContentLength: Integer;
    4445begin
    4546  with TTCPClientThread(Sender), Socket do begin
     
    8182          Inc(LineIndex);
    8283        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;
    8391      finally
    8492        LineParts.Free;
    8593      end;
     94
     95
    8696
    8797    // Process cookies
     
    95105    Response.Content.Clear;
    96106    Response.Headers.Add('Content-Type', 'text/html');
     107
     108
    97109
    98110    if Assigned(OnRequest) then OnRequest(HandlerData)
Note: See TracChangeset for help on using the changeset viewer.