From 70ff29444c4fef1c4422398aafa71d02cd8dd5f9 Mon Sep 17 00:00:00 2001 From: Michal Vaner Date: Sun, 31 Aug 2008 19:35:18 +0200 Subject: [PATCH] Do the login by a redirect --- PciIds/Html/Users.pm | 31 +++++++++++-------------------- 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/PciIds/Html/Users.pm b/PciIds/Html/Users.pm index d105bbe..7783f0c 100644 --- a/PciIds/Html/Users.pm +++ b/PciIds/Html/Users.pm @@ -6,7 +6,6 @@ use PciIds::Html::Forms; use PciIds::Email; use PciIds::Users; use PciIds::Address; -use PciIds::Html::Handler; use CGI; use CGI::Cookie; use Apache2::Const qw(:common); @@ -222,26 +221,25 @@ sub loginSubmit( $$$ ) { $logged = $salted eq $passwd; } if( $logged ) { - my $cookie = new CGI::Cookie( -name => 'auth', -value => genAuthToken( $tables, $id, $req, undef, $email ) ); - $req->headers_out->add( 'Set-Cookie' => $cookie ); - $args->{'action'} = ( defined $args->{'redirectaction'} ) ? $args->{'redirectaction'} : 'list'; - delete $args->{'redirectaction'}; - $args->{'full_links'} = 1; - my $auth = checkLoginInternal( $req, $tables, $cookie ); - return PciIds::Html::Handler::callHandler( $req, $args, $tables, $auth, 1, 'GET' ); + $req->err_headers_out->add( 'Set-Cookie' => new CGI::Cookie( -name => 'auth', -value => genAuthToken( $tables, $id, $req, undef, $email ) ) ); + $args->{'action'} = ( defined $args->{'redirectaction'} && $args->{'redirectaction'} ne '' ) ? $args->{'redirectaction'} : 'list'; + my $url = 'http://'.$req->hostname().setAddrPrefix( $req->uri(), $args->{'action'} eq 'list' ? 'read' : 'mods' ).buildExcept( 'redirectaction', $args ); + return HTTPRedirect( $req, $url ); } else { return genLoginForm( $req, $args, 'Invalid login credetials', $data ); } } sub logout( $$ ) { - my( $req, $args, $tables, $auth ) = @_; - $req->headers_out->add( 'Set-Cookie' => new CGI::Cookie( -name => 'auth', -value => '0' ) ); - return PciIds::Html::List::list( $req, $args, $tables, {} ); + my( $req, $args ) = @_; + $req->err_headers_out->add( 'Set-Cookie' => new CGI::Cookie( -name => 'auth', -value => '0' ) ); + return HTTPRedirect( $req, 'http://'.$req->hostname().setAddrPrefix( $req->uri(), 'read' ).buildExcept( 'action', $args ) ); } -sub checkLoginInternal( $$$ ) { - my( $req, $tables, $cookie ) = @_; +sub checkLogin( $$ ) { + my( $req, $tables ) = @_; + my $cookies = fetch CGI::Cookie; + my $cookie = $cookies->{'auth'}; my( $authed, $id, $regen, $rights, $error, $name ) = checkAuthToken( $tables, $req, defined( $cookie ) ? $cookie->value : undef ); if( $regen ) { $req->headers_out->add( 'Set-Cookie' => new CGI::Cookie( -name => 'auth', -value => genAuthToken( $tables, $id, $req, $rights, $name ) ) ); @@ -250,13 +248,6 @@ sub checkLoginInternal( $$$ ) { return { 'authid' => $authed ? $id : undef, 'accrights' => $rights, 'logerror' => $hterror, 'name' => $authed ? $name : undef }; } -sub checkLogin( $$ ) { - my( $req, $tables ) = @_; - my $cookies = fetch CGI::Cookie; - my $cookie = $cookies->{'auth'}; - return checkLoginInternal( $req, $tables, $cookie ); -} - sub notLoggedComplaint( $$$ ) { my( $req, $args, $auth ) = @_; return HTTPRedirect( $req, 'https://'.$req->hostname().$req->uri().buildArgs( $args ) ) unless $auth->{'ssl'}; -- 2.39.2