Changeset 36 for trunk/Application
- Timestamp:
- Oct 29, 2010, 10:44:13 PM (14 years ago)
- Location:
- trunk/Application
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Application/UCustomApplication.pas
r35 r36 8 8 Classes, SysUtils, UHTTPServerCGI, Contnrs, USqlDatabase, UConfig, DateUtils, 9 9 UXmlClasses, UHtmlClasses, UCore, UStringListEx, UHTTPServer, UHTTPServerTCP, 10 UHTTPSessionMySQL, UHTTPSessionFile ;10 UHTTPSessionMySQL, UHTTPSessionFile, UUser; 11 11 12 12 type … … 46 46 ModuleName: string; 47 47 BaseURL: string; 48 User: TWebUser; 49 UserOnline: TWebOnlineUser; 48 50 procedure Run; 49 51 procedure Execute(HandlerData: THTTPHandlerData); … … 95 97 TitleTag: THtmlString; 96 98 begin 99 User.HandlerData := HandlerData; 100 UserOnline.HandlerData := HandlerData; 101 UserOnline.Update; 97 102 with HandlerData do begin 98 103 Style := ConfigStyle; … … 133 138 Pages := TObjectList.Create; 134 139 HtmlDocument := THtmlDocument.Create; 140 User := TWebUser.Create; 141 User.Database := Database; 142 UserOnline := TWebOnlineUser.Create; 143 UserOnline.Database := Database; 135 144 end; 136 145 … … 141 150 Pages.Free; 142 151 HTTPServer.Free; 152 User.Free; 153 UserOnline.Free; 143 154 inherited Destroy; 144 155 end; … … 230 241 '<li><a href="https://mail.zdechov.net/">Pošta</a></li>' + 231 242 '<li><a href="http://wiki.zdechov.net/">Wiki</a></li>' + 232 '</ul><ul class="MenuItem2"> <li> </li>';233 (* if System.UserOnline.User = System.UserOnline.AnonymousUserId then begin243 '</ul><ul class="MenuItem2">'; //<li> </li>'; 244 if UserOnline.User = AnonymousUserId then begin 234 245 Text := Text + '</ul>' + 235 246 '<ul class="MenuItem2">' + 236 '<li>' + MakeLink('Přihlášení', Navigation MakeLink('User', 'Login')) + '</li>';247 '<li>' + MakeLink('Přihlášení', NavigationLink('/uzivatel/prihlaseni/')) + '</li>'; 237 248 //$Output .= '<li>'.$this->System->HTML->MakeLink($this->System->Translate('UserRegistration'), $this->System->MakeLink('UserList', 'Register')).'</li>'; 238 249 end else begin 239 250 Text := Text + '</ul>' + 240 251 '<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; 247 256 Text := Text + '</ul></div>'; 248 257 end; -
trunk/Application/UUser.pas
r33 r36 8 8 Classes, SysUtils, synacode, USqlDatabase, UCommon, UHTTPServer; 9 9 10 const 11 AnonymousUserId = 1; 12 10 13 type 11 14 EDuplicateItem = class(Exception); … … 15 18 16 19 TWebUser = class 20 FullName: string; 17 21 Database: TSqlDatabase; 18 22 HandlerData: THTTPHandlerData; … … 47 51 Id: Integer; 48 52 begin 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 54 71 DbRows.Free; 55 DbRows := Database.Query('UPDATE `UserOnline` SET `ActivityTime` = NOW() WHERE `Id`=' + IntToStr(Id));56 end else begin57 // Create new record58 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;62 72 end; 63 DbRows.Destroy;64 73 end; 65 74 … … 69 78 begin 70 79 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; 74 86 Self.User := User; 75 87 end; … … 79 91 DbRows: TDbRows; 80 92 begin 81 if Id = 1then Update;82 if User <> 1then begin83 DbRows := Database.Query('UPDATE `UserOnline` SET `User` = 1WHERE `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`="' + 84 96 HandlerData.Request.Cookies.Values['SessionId'] + '"'); 85 97 DbRows.Destroy; 86 User := 1;98 User := AnonymousUserId; 87 99 end; 88 100 end;
Note:
See TracChangeset
for help on using the changeset viewer.