Catalyst response->redirect and login trick
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:
Root.pm
OK, maybe I forget the '$c->req->uri->query' or '$c->req->body_parameters', but you can improve it, right?
Have fun!
mm, maybe you will get this problem when you code in Catalyst.
Here comes my solution:
Root.pm
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# redirectand in Template: try to put "<input type='hidden' name='referer' value='[% c.req.param('referer') %]' />" in your action='/login' form.
my $referer = $c->req->param('referer');
if ($referer) {
$c->res->redirect($referer);
} else {
$c->res->redirect('/');
}
OK, maybe I forget the '$c->req->uri->query' or '$c->req->body_parameters', but you can improve it, right?
Have fun!
Labels: Catalyst
1 Comments:
Not quite catch it.
Maybe need some time to understand it.
BTW. you're not very available on google talk. where r u?
Post a Comment
Links to this post:
Create a Link
<< Home