Apache2-Controller
view release on metacpan or search on metacpan
lib/Apache2/Controller/Auth/OpenID.pm view on Meta::CPAN
}
=head2 redirect_to
return $self->redirect_to($uri);
If one of the three internal URIs, use C<< redispatch() >>.
Otherwise, use C<< location_redirect >>.
=cut
sub redirect_to {
my ($self, $where_uri) = @_;
a2cx "Undefined redirect" if !defined $where_uri;
my $conf = $self->{conf};
my $current_uri = $self->uri();
return exists $conf->{is_internal}{$where_uri}
? $self->redispatch($where_uri)
: $self->location_redirect($where_uri);
}
=head2 location_redirect
return $self->location_redirect($uri);
Set the Location header and return REDIRECT.
Forces the session to be saved in the cleanup handler.
=cut
sub location_redirect {
my ($self, $uri) = @_;
DEBUG "redirecting with location header to $uri";
$self->err_headers_out->add( Location => $uri );
# set the flag to force the session to be saved
$self->pnotes->{a2c}{session_force_save} = 1;
return Apache2::Const::REDIRECT;
}
=head2 redispatch
return $self->redispatch($uri);
For the internal pages (login, logout, register), if they are
relative, re-dispatch them and return OK, else if absolute,
set location and return redirect.
If where == register or login, and the current uri is not
register or login, stash the current uri in
C<< session->{a2c}{openid}{previous}{uri} >>, and if
C<< A2C_Auth_OpenID_NoPreserveParams >> is NOT set,
then it stashes the get args and post body in C<< ...{previous}{get} >>
and C<< ...{previous}{post} >> for reattaching to the request
after successful authentication on the return from the auth server.
=cut
sub redispatch {
my ($self, $where_uri) = @_;
DEBUG "redispatch uri '$where_uri'?";
# if it's an absolute path or schemed url, use a location redirect
return $self->location_redirect($where_uri)
if $where_uri =~ m{ \A / }mxs
|| $where_uri =~ m{ \A \w+ :// }mxs;
my $conf = $self->{conf};
my $current_uri = $self->uri();
my $current_loc = $self->location();
(my $current_relative_uri = $current_uri) =~ s{ \A \Q$current_loc\E / }{}mxs;
DEBUG "current_relative_uri '$current_relative_uri'";
# save the current uri, get vars and post body in session
my $register_uri = $conf->{register};
my $login_uri = $conf->{login};
if ( ($where_uri eq $register_uri || $where_uri eq $login_uri)
&& $current_relative_uri ne $register_uri
&& $current_relative_uri ne $login_uri
) {
DEBUG "setting session previous_uri to '$current_uri'";
$self->pnotes->{a2c}{session}{a2c}{openid}{previous}{uri} = $current_uri;
$self->preserve_params unless $conf->{nopreserveparams};
}
# now set the new URI and redispatch.
DEBUG "redispatching...";
my $loc = $self->location;
# DEBUG "loc is first '$loc'";
$loc =~ s{ /+ \z }{}mxs;
# DEBUG "loc is now '$loc'";
my $where_full_uri = "$loc/$where_uri";
DEBUG "Trying to redispatch to full uri '$where_full_uri'";
$self->uri($where_full_uri);
my $dispatch_class = $self->pnotes->{a2c}{dispatch_class}
|| a2cx 'No dispatch class saved in $r->pnotes->{a2c}{dispatch_class}';
# # clear the previously set response handler
# redispatch
# we trap errors, but we use a location redirect if we encounter any
# we skip the 'process' subroutine because it uses set_handler,
# which seems like it should work, but in fact stalls the request
# after the last cleanup handler completes, even though it seems
# like everything completed successfully.
my $previously_set_controller = $self->pnotes->{a2c}{controller}
|| a2cx "no controller previously dispatched in pnotes->{a2c}{controller}";
( run in 0.616 second using v1.01-cache-2.11-cpan-e1769b4cff6 )