Changeset 78 for trunk/Modules
- Timestamp:
- Jun 18, 2012, 10:44:21 PM (12 years ago)
- Location:
- trunk/Modules
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Modules/UMainModule.lfm
r77 r78 2 2 OldCreateOrder = False 3 3 Height = 278 4 HorizontalOffset = 4185 VerticalOffset = 2 054 HorizontalOffset = 554 5 VerticalOffset = 266 6 6 Width = 431 7 object HTTPSessionStorageMySQL1: THTTPSessionStorageMySQL8 Database = Database9 Timeout = 1080010 SessionIdCookieName = 'SessionId'11 left = 30412 top = 3213 end14 object Database: TSqlDatabase15 Connected = False16 Port = 330617 Encoding = 'utf8'18 left = 8119 top = 8620 end21 7 object WebApp1: TWebApp 22 8 OnPageProduce = WebApp1PageProduce 23 ServerType = st TCP9 ServerType = stCGI 24 10 left = 160 25 11 top = 88 -
trunk/Modules/UMainModule.lrs
r77 r78 3 3 LazarusResources.Add('TMainModule','FORMDATA',[ 4 4 'TPF0'#11'TMainModule'#10'MainModule'#14'OldCreateOrder'#8#6'Height'#3#22#1#16 5 +'HorizontalOffset'#3#162#1#14'VerticalOffset'#3#205#0#5'Width'#3#175#1#0#24 6 +'THTTPSessionStorageMySQL'#24'HTTPSessionStorageMySQL1'#8'Database'#7#8'Data' 7 +'base'#7'Timeout'#3'0*'#19'SessionIdCookieName'#6#9'SessionId'#4'left'#3'0'#1 8 +#3'top'#2' '#0#0#12'TSqlDatabase'#8'Database'#9'Connected'#8#4'Port'#3#234#12 9 +#8'Encoding'#6#4'utf8'#4'left'#2'Q'#3'top'#2'V'#0#0#7'TWebApp'#7'WebApp1'#13 10 +'OnPageProduce'#7#18'WebApp1PageProduce'#10'ServerType'#7#5'stTCP'#4'left'#3 11 +#160#0#3'top'#2'X'#0#0#0 5 +'HorizontalOffset'#3'*'#2#14'VerticalOffset'#3#10#1#5'Width'#3#175#1#0#7'TWe' 6 +'bApp'#7'WebApp1'#13'OnPageProduce'#7#18'WebApp1PageProduce'#10'ServerType'#7 7 +#5'stCGI'#4'left'#3#160#0#3'top'#2'X'#0#0#0 12 8 ]); -
trunk/Modules/UMainModule.pas
r77 r78 15 15 16 16 type 17 TSession = class 18 17 TMainModule = class; 18 19 { TWebSession } 20 21 TWebSession = class(THTTPHandlerData) 22 private 23 procedure TopMenu; 24 procedure Footer; 25 public 26 MainModule: TMainModule; 27 Database: TSqlDatabase; 28 SessionStorage: THTTPSessionStorageMySQL; 29 User: TWebUser; 30 UserOnline: TWebOnlineUser; 31 HtmlDocument: THtmlDocument; 32 GlobalTitle: string; 33 TimeStart: TDateTime; 34 procedure LoadUserInfo; 35 procedure InitDatabase; 36 procedure GeneratePage(Page: TWebPage); 37 constructor Create; override; 38 destructor Destroy; override; 19 39 end; 20 40 … … 22 42 23 43 TMainModule = class(TDataModule) 24 HTTPSessionStorageMySQL1: THTTPSessionStorageMySQL;25 Database: TSqlDatabase;26 44 WebApp1: TWebApp; 27 45 procedure WebApp1PageProduce(HandlerData: THTTPHandlerData); 28 46 private 29 procedure Footer;30 procedure InitDatabase;31 47 procedure Show(Content: string); 32 procedure TopMenu;33 48 public 34 TimeStart: TDateTime;35 49 Load: string; 36 50 Unload: string; 37 GlobalTitle: string;38 51 ShowRuntimeInfo: Boolean; 39 52 Charset: string; 40 53 Admin: string; 41 54 AdminEmail: string; 55 Keywords: string; 42 56 Style: string; 43 Keywords: string;44 HtmlDocument: THtmlDocument;45 57 BaseURL: string; 46 User: TWebUser;47 UserOnline: TWebOnlineUser;48 58 FormatHTML: Boolean; 49 59 NetworkAddress: string; … … 51 61 MaxConnections: Integer; 52 62 Pages: TPageList; 53 procedure LoadUserInfo(HandlerData: THTTPHandlerData); 63 DatabaseHostname: string; 64 DatabaseUserName: string; 65 DatabasePassword: string; 66 DatabaseSchema: string; 54 67 procedure LoadFromRegistry; 55 68 procedure SaveToRegistry; 56 procedure GeneratePage(HandlerData: THTTPHandlerData; Page: TWebPage);57 69 procedure Run; 58 70 constructor Create(AOwner: TComponent); override; … … 71 83 UNetworkPage, UAboutPage, UContactPage; 72 84 73 { TMainModule } 74 75 procedure TMainModule.GeneratePage(HandlerData: THTTPHandlerData; Page: TWebPage); 85 { TWebSession } 86 87 constructor TWebSession.Create; 88 begin 89 inherited; 90 Database := TSqlDatabase.Create(nil); 91 SessionStorage := THTTPSessionStorageMySQL.Create(nil); 92 SessionStorage.Database := Database; 93 HtmlDocument := THtmlDocument.Create; 94 User := TWebUser.Create; 95 User.Database := Database; 96 UserOnline := TWebOnlineUser.Create; 97 UserOnline.Database := Database; 98 end; 99 100 destructor TWebSession.Destroy; 101 begin 102 HtmlDocument.Free; 103 User.Free; 104 UserOnline.Free; 105 SessionStorage.Free; 106 Database.Free; 107 inherited Destroy; 108 end; 109 110 procedure TWebSession.InitDatabase; 111 var 112 DbRows: TDbRows; 113 begin 114 with Database do begin 115 Connect; 116 end; 117 try 118 DbRows := TDbRows.Create; 119 Database.Query(DbRows, 'SET NAMES utf8'); 120 finally 121 DbRows.Free; 122 end; 123 end; 124 125 procedure TWebSession.LoadUserInfo; 126 begin 127 User.HandlerData := Self; 128 UserOnline.HandlerData := Self; 129 UserOnline.Update; 130 User.Id := UserOnline.User; 131 User.Load; 132 end; 133 134 procedure TWebSession.GeneratePage(Page: TWebPage); 76 135 var 77 136 I: Integer; 78 137 TitleTag: THtmlString; 79 138 begin 80 with HandlerData do begin81 139 HtmlDocument.ContentLanguage := 'cs'; 82 140 GlobalTitle := 'ZděchovNET'; 83 HtmlDocument.Styles.Add(NavigationLink('/Style/' + Style + '/Style.css'));84 HtmlDocument.Scripts.Add(NavigationLink('/Style/' + Style + '/Global.js'));85 HtmlDocument.Scripts.Add(NavigationLink('/Style/' + Style + '/jquery.js'));141 HtmlDocument.Styles.Add(NavigationLink('/Style/' + MainModule.Style + '/Style.css')); 142 HtmlDocument.Scripts.Add(NavigationLink('/Style/' + MainModule.Style + '/Global.js')); 143 HtmlDocument.Scripts.Add(NavigationLink('/Style/' + MainModule.Style + '/jquery.js')); 86 144 87 145 TitleTag := THtmlString.Create; … … 95 153 with HtmlDocument.AsXmlDocument do 96 154 try 97 Formated := FormatHTML;155 Formated := MainModule.FormatHTML; 98 156 Response.Content.WriteString(AsString); 99 157 finally 100 158 Free; 101 159 end; 102 end; 103 end; 104 105 procedure TMainModule.InitDatabase; 106 var 107 DbRows: TDbRows; 108 begin 109 with Database do begin 110 Connect; 111 end; 112 try 113 DbRows := TDbRows.Create; 114 Database.Query(DbRows, 'SET NAMES utf8'); 115 finally 116 DbRows.Free; 117 end; 118 end; 160 end; 161 162 163 { TMainModule } 119 164 120 165 constructor TMainModule.Create(AOwner: TComponent); … … 122 167 inherited; 123 168 Pages := TPageList.Create; 124 HtmlDocument := THtmlDocument.Create;125 User := TWebUser.Create;126 User.Database := Database;127 UserOnline := TWebOnlineUser.Create;128 UserOnline.Database := Database;129 169 LoadFromRegistry; 130 170 with Pages do begin … … 156 196 begin 157 197 //SaveToRegistry; 158 HtmlDocument.Free;159 User.Free;160 UserOnline.Free;161 198 Pages.Free; 162 199 inherited Destroy; 163 200 end; 164 201 165 procedure T MainModule.Footer;202 procedure TWebSession.Footer; 166 203 var 167 204 Tag: TXMLTag; … … 178 215 Name := 'li'; 179 216 with TXmlString(SubElements.AddNew(TXmlString.Create)) do begin 180 Text := Admin;217 Text := MainModule.Admin; 181 218 end; 182 219 end; … … 184 221 Name := 'li'; 185 222 with TXmlString(SubElements.AddNew(TXmlString.Create)) do begin 186 Text := AdminEmail;187 end; 188 end; 189 if ShowRuntimeInfo then begin223 Text := MainModule.AdminEmail; 224 end; 225 end; 226 if MainModule.ShowRuntimeInfo then begin 190 227 with TXmlTag(SubElements.AddNew(TXmlTag.Create)) do begin 191 228 Name := 'li'; … … 232 269 end; 233 270 234 procedure T MainModule.TopMenu;271 procedure TWebSession.TopMenu; 235 272 begin 236 273 with THtmlString(HtmlDocument.Body.SubItems.InsertNew(1, THtmlString.Create)) do begin … … 269 306 end; 270 307 271 procedure TMainModule.LoadUserInfo(HandlerData: THTTPHandlerData);272 begin273 User.HandlerData := HandlerData;274 UserOnline.HandlerData := HandlerData;275 UserOnline.Update;276 User.Id := UserOnline.User;277 User.Load;278 end;279 280 308 procedure TMainModule.WebApp1PageProduce(HandlerData: THTTPHandlerData); 281 309 var 282 310 FileName: string; 311 PageName: string; 312 Page: TRegistredPage; 313 NewSession: TWebSession; 314 BaseUrlParts: TListString; 283 315 begin 284 316 with HandlerData do begin 285 if not Pages.ProducePage(HandlerData) then begin 317 try 318 BaseUrlParts := TListString.Create; 319 BaseUrlParts.Explode(BaseURL, '/', StrToStr); 320 while (BaseUrlParts.Count > 0) and (Request.Path.Count > 0) and 321 (BaseUrlParts[0] = Request.Path[0]) do begin 322 BaseUrlParts.Delete(0); 323 Request.Path.Delete(0); 324 end; 325 finally 326 BaseUrlParts.Free; 327 end; 328 if Request.Path.Count > 0 then PageName := Request.Path[0] 329 else PageName := ''; 330 Page := Pages.FindByName(PageName); 331 if Assigned(Page) then begin 332 NewSession := TWebSession.Create; 333 NewSession.MainModule := Self; 334 NewSession.Assign(HandlerData); 335 NewSession.TimeStart := Now; 336 NewSession.Database.HostName := DatabaseHostName; 337 NewSession.Database.Password := DatabasePassword; 338 NewSession.Database.Database := DatabaseSchema; 339 NewSession.Database.UserName := DatabaseUserName; 340 NewSession.InitDatabase; 341 Page.Page.OnProduce(NewSession); 342 HandlerData.Assign(NewSession); 343 end else begin 286 344 WebApp1.HTTPServer.FileResponse(HandlerData) 287 345 end; … … 301 359 Style := ReadString(SectionGeneral, 'Style', 'Basic'); 302 360 BaseURL := ReadString(SectionGeneral, 'BaseURL', 'http://localhost'); 303 Database .Hostname := ReadString(SectionDatabase, 'DatabaseHostName', 'localhost');304 Database .Database:= ReadString(SectionDatabase, 'DatabaseDatabase', 'web');305 Database .UserName := ReadString(SectionDatabase, 'DatabaseUserName', 'user');306 Database .Password := ReadString(SectionDatabase, 'DatabasePassword', 'password');361 DatabaseHostname := ReadString(SectionDatabase, 'DatabaseHostName', 'localhost'); 362 DatabaseSchema := ReadString(SectionDatabase, 'DatabaseDatabase', 'web'); 363 DatabaseUserName := ReadString(SectionDatabase, 'DatabaseUserName', 'user'); 364 DatabasePassword := ReadString(SectionDatabase, 'DatabasePassword', 'password'); 307 365 FormatHTML := ReadBool(SectionGeneral, 'FormatHTML', False); 308 366 //MainModule.WebApp1.LogException := not ReadBool(SectionGeneral, 'ShowException', False); … … 327 385 WriteString(SectionGeneral, 'Style', Style); 328 386 WriteString(SectionGeneral, 'BaseURL', BaseURL); 329 WriteString(SectionDatabase, 'DatabaseHostName', Database .Hostname);330 WriteString(SectionDatabase, 'DatabaseDatabase', Database .Database);331 WriteString(SectionDatabase, 'DatabaseUserName', Database .UserName);332 WriteString(SectionDatabase, 'DatabasePassword', Database .Password);387 WriteString(SectionDatabase, 'DatabaseHostName', DatabaseHostname); 388 WriteString(SectionDatabase, 'DatabaseDatabase', DatabaseSchema); 389 WriteString(SectionDatabase, 'DatabaseUserName', DatabaseUserName); 390 WriteString(SectionDatabase, 'DatabasePassword', DatabasePassword); 333 391 WriteBool(SectionGeneral, 'FormatHTML', FormatHTML); 334 392 //WriteBool(SectionGeneral, 'ShowException', not MainModule.WebApp1.LogException); … … 343 401 procedure TMainModule.Run; 344 402 begin 345 InitDatabase; 346 //Database.Query('SELECT * FROM ssss'); 347 403 WebApp1.HTTPServer.DocumentRoot := ExtractFileDir(ParamStrUTF8(0)); 348 404 WebApp1.Run; 349 405 end;
Note:
See TracChangeset
for help on using the changeset viewer.