Changeset 36 for trunk/Application


Ignore:
Timestamp:
Oct 29, 2010, 10:44:13 PM (14 years ago)
Author:
george
Message:
  • Přidáno: Neodokončená třída TPageList a TQueryString.
  • Přidáno: Částečná podpora pro přihlašování uživatelů.
Location:
trunk/Application
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Application/UCustomApplication.pas

    r35 r36  
    88  Classes, SysUtils, UHTTPServerCGI, Contnrs, USqlDatabase, UConfig, DateUtils,
    99  UXmlClasses, UHtmlClasses, UCore, UStringListEx, UHTTPServer, UHTTPServerTCP,
    10   UHTTPSessionMySQL, UHTTPSessionFile;
     10  UHTTPSessionMySQL, UHTTPSessionFile, UUser;
    1111
    1212type
     
    4646    ModuleName: string;
    4747    BaseURL: string;
     48    User: TWebUser;
     49    UserOnline: TWebOnlineUser;
    4850    procedure Run;
    4951    procedure Execute(HandlerData: THTTPHandlerData);
     
    9597  TitleTag: THtmlString;
    9698begin
     99  User.HandlerData := HandlerData;
     100  UserOnline.HandlerData := HandlerData;
     101  UserOnline.Update;
    97102  with HandlerData do begin
    98103  Style := ConfigStyle;
     
    133138  Pages := TObjectList.Create;
    134139  HtmlDocument := THtmlDocument.Create;
     140  User := TWebUser.Create;
     141  User.Database := Database;
     142  UserOnline := TWebOnlineUser.Create;
     143  UserOnline.Database := Database;
    135144end;
    136145
     
    141150  Pages.Free;
    142151  HTTPServer.Free;
     152  User.Free;
     153  UserOnline.Free;
    143154  inherited Destroy;
    144155end;
     
    230241      '<li><a href="https://mail.zdechov.net/">Pošta</a></li>' +
    231242      '<li><a href="http://wiki.zdechov.net/">Wiki</a></li>' +
    232       '</ul><ul class="MenuItem2"><li>&nbsp;</li>';
    233 (*    if System.UserOnline.User = System.UserOnline.AnonymousUserId then begin
     243      '</ul><ul class="MenuItem2">'; //<li>&nbsp;</li>';
     244    if UserOnline.User = AnonymousUserId then begin
    234245      Text := Text + '</ul>' +
    235246        '<ul class="MenuItem2">' +
    236         '<li>' + MakeLink('Přihlášení', NavigationMakeLink('User', 'Login')) + '</li>';
     247        '<li>' + MakeLink('Přihlášení', NavigationLink('/uzivatel/prihlaseni/')) + '</li>';
    237248      //$Output .= '<li>'.$this->System->HTML->MakeLink($this->System->Translate('UserRegistration'), $this->System->MakeLink('UserList', 'Register')).'</li>';
    238249    end else begin
    239250      Text := Text + '</ul>' +
    240251        '<ul class="MenuItem2">' +
    241         '<li>' + System.User.FullName + '</li>' +
    242         '<li>' + MakeLink('Odhlášení', NavigationMakeLink('User', 'Logout')) + '</li>' +
    243         '<li>' + MakeLink('Profil', NavigationMakeLink('User', 'View',
    244         array('Id' => $this->System->User->Id))).'</li>';
    245     end;
    246     *)
     252        '<li>' + User.FullName + '</li>' +
     253        '<li>' + MakeLink('Odhlášení', NavigationLink('/uzivatel/odhlaseni/')) + '</li>' +
     254        '<li>' + MakeLink('Profil', NavigationLink('/uzivatel/profil/')) + '</li>';
     255    end;
    247256    Text := Text + '</ul></div>';
    248257  end;
  • trunk/Application/UUser.pas

    r33 r36  
    88  Classes, SysUtils, synacode, USqlDatabase, UCommon, UHTTPServer;
    99
     10const
     11  AnonymousUserId = 1;
     12
    1013type
    1114  EDuplicateItem = class(Exception);
     
    1518
    1619  TWebUser = class
     20    FullName: string;
    1721    Database: TSqlDatabase;
    1822    HandlerData: THTTPHandlerData;
     
    4751  Id: Integer;
    4852begin
    49   DbRows := Database.Query('SELECT * FROM `UserOnline` WHERE `SessionId`="' +
    50     HandlerData.Request.Cookies.Values['SessionId'] + '"');
    51   if DbRows.Count > 0 then begin
    52     // Update exited
    53     Id := StrToInt(DbRows[0].Values['Id']);
     53  try
     54    DbRows := Database.Query('SELECT * FROM `UserOnline` WHERE `SessionId`="' +
     55      HandlerData.Request.Cookies.Values['SessionId'] + '"');
     56    if DbRows.Count > 0 then begin
     57      // Update exited
     58      Id := StrToInt(DbRows[0].Values['Id']);
     59      User := StrToInt(DbRows[0].Values['User']);
     60      DbRows.Free;
     61      DbRows := Database.Query('UPDATE `UserOnline` SET `ActivityTime` = NOW() WHERE `Id`=' + IntToStr(Id));
     62    end else begin
     63      // Create new record
     64      DbRows.Free;
     65      DbRows := Database.Query('INSERT INTO `UserOnline` (`User`, `ActivityTime`, `SessionId`) ' +
     66        'VALUES (1, NOW(), "' + HandlerData.Request.Cookies.Values['SessionId'] + '")');
     67      Id := Database.LastInsertId;
     68      User := 1;
     69    end;
     70  finally
    5471    DbRows.Free;
    55     DbRows := Database.Query('UPDATE `UserOnline` SET `ActivityTime` = NOW() WHERE `Id`=' + IntToStr(Id));
    56   end else begin
    57     // Create new record
    58     DbRows.Free;
    59     DbRows := Database.Query('INSERT INTO `UserOnline` (`User`, `ActivityTime`, `SessionId`) ' +
    60       'VALUES (1, NOW(), "' + HandlerData.Request.Cookies.Values['SessionId'] + '")');
    61     Id := Database.LastInsertId;
    6272  end;
    63   DbRows.Destroy;
    6473end;
    6574
     
    6978begin
    7079  Logout;
    71   DbRows := Database.Query('UPDATE `UserOnline` SET `User` = ' + IntToStr(User) + ', `LoginTime` = NOW() WHERE `SessionId`="' +
    72     HandlerData.Request.Cookies.Values['SessionId'] + '"');
    73   DbRows.Destroy;
     80  try
     81    DbRows := Database.Query('UPDATE `UserOnline` SET `User` = ' + IntToStr(User) + ', `LoginTime` = NOW() WHERE `SessionId`="' +
     82      HandlerData.Request.Cookies.Values['SessionId'] + '"');
     83  finally
     84    DbRows.Free;
     85  end;
    7486  Self.User := User;
    7587end;
     
    7991  DbRows: TDbRows;
    8092begin
    81   if Id = 1 then Update;
    82   if User <> 1 then begin
    83     DbRows := Database.Query('UPDATE `UserOnline` SET `User` = 1 WHERE `SessionId`="' +
     93  if Id = AnonymousUserId then Update;
     94  if User <> AnonymousUserId then begin
     95    DbRows := Database.Query('UPDATE `UserOnline` SET `User` = ' + IntToStr(AnonymousUserId) + ' WHERE `SessionId`="' +
    8496      HandlerData.Request.Cookies.Values['SessionId'] + '"');
    8597    DbRows.Destroy;
    86     User := 1;
     98    User := AnonymousUserId;
    8799  end;
    88100end;
Note: See TracChangeset for help on using the changeset viewer.