All pastes #460796 Raw Edit

Mine

public text v1 · immutable
#460796 ·published 2007-04-27 09:04 UTC
rendered paste body
sub forceAuthentication {
    my $this = shift;
    my $twiki = $this->{twiki};

    unless( $twiki->inContext( 'authenticated' )) {
        my $query = $twiki->{cgiQuery};
        # Redirect with passthrough so we don't lose the original query params
        my $twiki = $this->{twiki};
        my $topic = $twiki->{topicName};
        my $web = $twiki->{webName};
        my $url = $twiki->getScriptUrl( 0, 'login', $web, $topic);
        $query->param( -name=>'origurl', -value=>$ENV{REQUEST_URI} );
        $twiki->redirect( $url, 1 );
        return 1;
    }
    return undef;
}

# Content of a login link
sub loginUrl {
    my $this = shift;
    my $twiki = $this->{twiki};
    my $topic = $twiki->{topicName};
    my $web = $twiki->{webName};
    my $query = $twiki->{cgiQuery};
    return $twiki->getScriptUrl( 0, 'login', $web, $topic,
                                 origurl => $ENV{REQUEST_URI} );
}