]> mj.ucw.cz Git - pciids.git/blobdiff - PciIds/Html/Users.pm
Do the login by a redirect
[pciids.git] / PciIds / Html / Users.pm
index d105bbe6efd615673a351c44c0a693fa320de07c..7783f0c04ab2e988a4893356c9a8c844975b22a1 100644 (file)
@@ -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'};