--- loncom/auth/restrictedaccess.pm 2006/07/17 19:49:14 1.3 +++ loncom/auth/restrictedaccess.pm 2013/06/02 02:20:33 1.9 @@ -1,6 +1,8 @@ # The LearningOnline Network # Passphrase Entry and Validation for Portfolio files # +# $Id: restrictedaccess.pm,v 1.9 2013/06/02 02:20:33 raeburn Exp $ +# # Copyright Michigan State University Board of Trustees # # This file is part of the LearningOnline Network with CAPA (LON-CAPA). @@ -45,32 +47,42 @@ sub handler { if (!defined($origurl)) { $origurl = $r->uri; } + my $msg=''; if (exists($env{'form.pass1'})) { my ($result,$end) = &check_pass($r,$origurl); if ($result eq 'ok') { - &Apache::lonnet::appenv(('user.passphrase_access_'.$origurl => - $end)); + &Apache::lonnet::allowuploaded('/adm/restrictedaccess', + $origurl); $env{'request.state'} = "published"; $env{'request.filename'} = $origurl; - $r->header_out(Location => 'http://'.$ENV{'HTTP_HOST'}.$origurl); + my $newurl = &Apache::lonnet::absolute_url($ENV{'HTTP_HOST'}).$origurl; + $r->header_out(Location => $newurl); return REDIRECT; } else { - &print_entryform($r,$origurl,"Invalid passphrase"); - } - } else { - &print_entryform($r,$origurl); + $msg = 'Invalid passphrase'; + } } - return OK; -} -sub print_entryform { - my ($r,$origurl,$msg) = @_; - &Apache::lonlocal::get_language_handle($r); &Apache::loncommon::content_type($r,'text/html'); $r->send_http_header; return OK if $r->header_only; $r->print(&Apache::loncommon::start_page('Passphrase protected file')); + &print_entryform($r,$origurl,$msg); + + return OK; +} + +sub setup_handler { + my ($r) = @_; + $r->set_handlers('PerlHandler'=> + [\&Apache::restrictedaccess::handler]); + $r->handler('perl-script'); +} + +sub print_entryform { + my ($r,$origurl,$msg) = @_; + $r->print(''); - $r->print(''.$msg.''); + if ($msg ne '') { + $r->print(''.$msg.''); + } $r->print('
'); $r->print('


'); $r->print(&Apache::loncommon::start_data_table()); $r->print(&Apache::loncommon::start_data_table_row()); - $r->print(''.&mt('Passphrase: ').''. - ''); + $r->print(''.&mt('Passphrase: ').''. + ''); $r->print(&Apache::loncommon::end_data_table_row()); $r->print(&Apache::loncommon::start_data_table_row()); $r->print('
'. @@ -103,7 +117,7 @@ function verify() { sub check_pass { my ($r,$origurl) = @_; my (undef,$udom,$unum,$file_name,$group) = - &Apache::lonacc::parse_portfolio_url($origurl); + &Apache::lonnet::parse_portfolio_url($origurl); my $curr_perms = &Apache::lonnet::get_portfile_permissions($udom,$unum); my %acc_controls = &Apache::lonnet::get_access_controls($curr_perms,