03 November 2006
This post may be outdated due to it was written on 2006. The links may be broken. The code may be not working anymore. Leave comments if needed.
say, u have a "return $c->res->redirect('/login') unless ($c->user_exists);" in one sub(means one url like "/forum/1/topic/new"). and u tried to get "/forum/1/topic/new" as $c->req->referer; but Catalyst is somehow different, u don't get "/forum/1/topic/new" as your HTTP_REFERER. Catalyst treats $c->res->redirect inside.

mm, maybe you will get this problem when you code in Catalyst.
Here comes my solution:
sub end : Private {
my ( $self, $c ) = @_;

# for login using!
if ($c->res->location and $c->res->location eq '/login') {
$c->res->location('/login?referer=/' . $c->req->path);
return if ($c->res->body || $c->res->redirect);
Logon.pm after $c->login OK, use
# redirect
my $referer = $c->req->param('referer');
if ($referer) {
} else {
and in Template: try to put "<input type='hidden' name='referer' value='[% c.req.param('referer') %]' />" in your action='/login' form.

OK, maybe I forget the '$c->req->uri->query' or '$c->req->body_parameters', but you can improve it, right?

Have fun!

blog comments powered by Disqus