$logged = $salted eq $passwd;
}
if( $logged ) {
- $req->headers_out->add( 'Set-Cookie' => new CGI::Cookie( -name => 'auth', -value => genAuthToken( $tables, $id, $req, undef, $email ) ) );
- $args->{'action'} = ( defined $args->{'redirectaction'} ) ? $args->{'redirectaction'} : 'list';
- my $prefix = ( !defined( $args->{'action'} ) or ( $args->{'action'} eq '' ) or ( $args->{'action'} eq 'list' ) ) ? 'read' : 'mods';
- my $url = "http://".$req->hostname().setAddrPrefix( $req->uri(), $prefix ).buildExcept( 'redirectaction', $args );
- genHtmlHead( $req, 'Logged in', undef );
- print "<div class='top'>\n";
- print '<h1>Logged in</h1>';
- genPath( $req, PciIds::Address::new( $req->uri() ), 1 );
- print "<div class='clear'></div></div>\n";
- print "<p>You are logged in" . ( defined $args->{'redirectaction'} ? ", continue with your <a href='$url'>action</a>.\n" : ".\n" );
- print '<div class="lastlog"><p>'.encode( $last ).'</div>' if( defined( $last ) );
- genHtmlTail();
- return OK;
+ $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 checkLogin( $$ ) {
my( $req, $tables ) = @_;
my $cookies = fetch CGI::Cookie;
- my( $authed, $id, $regen, $rights, $error, $name ) = checkAuthToken( $tables, $req, defined( $cookies->{'auth'} ) ? $cookies->{'auth'}->value : undef );
+ 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 ) ) );
}