diff Lib/IMPL/Web/QueryHandler/PageFormat.pm @ 97:964587c5183c

Added SecureCall to Web QueryHandlers stack many bug fixes to Security and Web Application modules
author wizard
date Tue, 04 May 2010 04:04:37 +0400
parents 9d24db321029
children 0e72ad99eef7
line wrap: on
line diff
--- a/Lib/IMPL/Web/QueryHandler/PageFormat.pm	Fri Apr 30 15:03:38 2010 +0400
+++ b/Lib/IMPL/Web/QueryHandler/PageFormat.pm	Tue May 04 04:04:37 2010 +0400
@@ -5,19 +5,20 @@
 
 use IMPL::Class::Property;
 use IMPL::Web::TT::Document;
+use IMPL::Security::Context;
 use File::Spec;
 use Error qw(:try);
 
 BEGIN {
 	public property templatesCharset => prop_all;
 	public property templatesBase => prop_all;
+	public property defaultTarget => prop_all;
 }
 
 sub CTOR {
 	my ($this) = @_;
 	
 	$this->templatesCharset('utf-8') unless $this->templatesCharset;
-	$this->templatesBase('.') unless $this->templatesBase;
 }
 
 sub Process {
@@ -26,13 +27,25 @@
 	my $doc = new IMPL::Web::TT::Document();
 	
 	try {
-		my @path = split /\//, $ENV{PATH_TRANSLATED};
+
+		$this->templatesBase($ENV{DOCUMENT_ROOT}) unless $this->templatesBase;
+		
+		my $pathInfo = $ENV{PATH_INFO};
+		local $ENV{PATH_INFO} = $pathInfo || $this->defaultTarget; 
+		
+		my @path = split /\//, ($ENV{PATH_INFO} || '') or die new IMPL::Exception("PATH_INFO is empty and no defaultTarget specified" );
 		
 		$doc->LoadFile ( File::Spec->catfile($this->templatesBase,@path), $this->templatesCharset );
+		$doc->AddVar( result => $nextHandler->() );
+		{
+			local $@;
+			$doc->AddVar( user => eval { IMPL::Security::Context->current->principal; } );
+			$doc->AddVar( session => eval { IMPL::Security::Context->current; } );
+			warn $@ if $@;
+		}
 		
 		$action->response->contentType('text/html');
 		my $hOut = $action->response->streamBody;
-		
 		print $hOut $doc->Render();
 	} finally {
 		$doc->Dispose;