From cc075a95fb36cdd94813608fff560ded0d0a60b2 Mon Sep 17 00:00:00 2001 From: erickson Date: Fri, 23 Sep 2005 16:23:41 +0000 Subject: [PATCH] passing stage dir added method to verify the login session git-svn-id: svn://svn.open-ils.org/ILS/trunk@1864 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/src/perlmods/OpenILS/WWW/Reporter.pm | 47 ++++++++++++++++--- 1 file changed, 40 insertions(+), 7 deletions(-) diff --git a/Open-ILS/src/perlmods/OpenILS/WWW/Reporter.pm b/Open-ILS/src/perlmods/OpenILS/WWW/Reporter.pm index 67b6947018..d85f7df75d 100644 --- a/Open-ILS/src/perlmods/OpenILS/WWW/Reporter.pm +++ b/Open-ILS/src/perlmods/OpenILS/WWW/Reporter.pm @@ -8,12 +8,15 @@ use APR::Const -compile => qw(:error SUCCESS); use Apache2::RequestRec (); use Apache2::RequestIO (); use Apache2::RequestUtil; +use CGI; use Template qw(:template); use OpenSRF::EX qw(:try); use OpenSRF::System; +use XML::LibXML; +use OpenSRF::Utils::SettingsParser; @@ -21,10 +24,13 @@ use OpenSRF::System; # this module is loaded my $bootstrap; my $includes = []; +my $base_xml; +#my $base_xml_doc; sub import { - my( $self, $bs_config, $tdir ) = @_; + my( $self, $bs_config, $tdir, $core_xml ) = @_; $bootstrap = $bs_config; + $base_xml = $core_xml; $includes = [ $tdir ]; } @@ -33,22 +39,35 @@ sub import { my $plugin_base = 'OpenILS::Template::Plugin'; sub child_init { - warn "Initing child with bootstrap $bootstrap\n"; OpenSRF::System->bootstrap_client( config_file => $bootstrap ); + + #parse the base xml file + #my $parser = XML::LibXML->new; + #$base_xml_doc = $parser->parse_file($base_xml); + } sub handler { - warn "TEST\n"; my $apache = shift; + my $cgi = CGI->new; + my $path = $apache->path_info; (my $ttk = $path) =~ s{^/?([a-zA-Z0-9_]+).*?$}{$1}o; + $ttk = "s1" unless $ttk; + + # if the user is not logged in via cookie, route them to the login page + if(!(verify_login( $cgi->cookie("ses") ))) { + $ttk = "login"; + } + print "Content-type: text/html; charset=utf-8\n\n"; _process_template( apache => $apache, template => "$ttk.ttk", + params => { stage_dir => $ttk, config_xml => $base_xml }, ); return Apache2::Const::OK; @@ -66,13 +85,13 @@ sub _process_template { $template = Template->new( { OUTPUT => $apache, - ABSOLUTE => 1, - RELATIVE => 1, + ABSOLUTE => 1, + RELATIVE => 1, PLUGIN_BASE => $plugin_base, INCLUDE_PATH => $includes, PRE_CHOMP => 1, POST_CHOMP => 1, - LOAD_PERL => 1, + #LOAD_PERL => 1, } ); @@ -83,7 +102,7 @@ sub _process_template { my $err = $template->error(); $err =~ s/\n/\/g; warn "Error processing template $ttk\n"; - my $string = "
Unable to process template:

" . $err . "!!!
"; + my $string = "
Unable to process template:

" . $err . "
"; print "ERROR: $string"; #$template->process( $error_ttk , { error => $string } ); } @@ -97,5 +116,19 @@ sub _process_template { } +# returns 1 if the session is valid, 0 otherwise +sub verify_login { + my $auth_token = shift; + return 0 unless $auth_token; + + my $session = OpenSRF::AppSession->create("open-ils.auth"); + my $req = $session->request("open-ils.auth.session.retrieve", $auth_token ); + my $user = $req->gather(1); + + return 1 if ref($user); + return 0; +} + + 1; -- 2.43.2