[Catalyst] redirect and formfu controller
Kalman Kiss
ssikiss at zalaszam.hu
Tue Dec 4 11:07:49 GMT 2007
Hi,
im seeing some strange behavior using
Catalyst::Controller::HTML::FormFu. The situation is the following.
In my app, when an unathed req comes, it will be redirected to the login
page, except login, register and password remainder.
Root.pm.
...
sub default : Private {
my ( $self, $c ) = @_;
# Hello World
# $c->response->body( $c->welcome_message );
# $c->response->redirect($c->uri_for('/login'));
my $action = $c->controller('Login')->action_for('index');
$c->response->redirect($c->uri_for($action));
}
...
sub auto : Private {
my ($self, $c) = @_;
$c->log->debug('*** Controller: '.$c->controller.',
path_prefix='.$c->controller->path_prefix($c).' ***');
$c->log->debug('*** Login Controller:
'.$c->controller('Login').',
path_prefix='.$c->controller('Login')->path_prefix($c).' ***');
if (
$c->controller eq $c->controller('Login')
|| ($c->controller eq $c->controller('Register'))
|| ($c->controller eq $c->controller('Passremainder'))
) {
$c->log->debug('*** Root: login, reg or passremainder.
***');
return 1;
}
# If a user doesn't exist, force login
if (!$c->user_exists) {
# Dump a log message to the development server debug output
$c->log->debug('***Root::auto User not found, redirecting to
login page');
$c->session->{page_before_login} = $c->request->path;
# Redirect the user to the login page
# $c->response->redirect($c->uri_for('/login'));
my $action = $c->controller('Login')->action_for('login');
$c->response->redirect($c->uri_for($action));
# Return 0 to cancel 'post-auto' processing and prevent use
of application
return 0;
}
# User found, so return 1 to continue with processing after this
'auto'
return 1;
}
This code causes an endless redirect loop - i dont know why. The above
controllermatch is never true,
and my debug logs read:
...
[debug] "GET" request for "/" from "192.168.1.174"
[debug] *** Controller: Foo::Controller::Root=HASH(0x909c07c),
path_prefix= ***
[debug] *** Login Controller: Foo::Controller::Login=HASH(0x997ca98),
path_prefix=login ***
[debug] Found sessionid "621742bcb308d08290e84db9809e8dae808d63f1" in cookie
[debug] Deleting session(session expired)
[debug] ***Root::auto User not found, redirecting to login page
[debug] Created session "8dac0c6ad8cb5aa95d074fdc9add1ee5bc14820c"
[debug] Redirecting to "http://192.168.1.34:3000/login/login"
...
[debug] "GET" request for "login/login" from "192.168.1.174"
[debug] Path is "login/login"
[debug] *** Controller: Foo::Controller::Login=HASH(0x99a9930),
path_prefix=login ***
[debug] *** Login Controller: Foo::Controller::Login=HASH(0x99a9930),
path_prefix=login ***
[debug] Found sessionid "8dac0c6ad8cb5aa95d074fdc9add1ee5bc14820c" in cookie
[debug] Restored session "8dac0c6ad8cb5aa95d074fdc9add1ee5bc14820c"
[debug] ***Root::auto User not found, redirecting to login page
[debug] Redirecting to "http://192.168.1.34:3000/login/login"
The controllers in the second req sould match, but dont. If i use the
path_prefix, its ok.
What im doing wrong?
take care
Kami
More information about the Catalyst
mailing list