[Catalyst] redirect and formfu controller
Carl Franks
fireartist at gmail.com
Tue Dec 4 11:41:08 GMT 2007
On 04/12/2007, Kalman Kiss <ssikiss at zalaszam.hu> wrote:
>
> 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?
It was a lot easier to read once I'd deleted the commented out code
and debugging statements.
Can you try switching back to Catalyst::Controller, to confirm you
still have the same problem, as there doesn't appear to be anything
there that requires Catalyst::Controller::HTML::FormFu - so that might
be a bit misleading.
As a guess - completely untested - Catalyst::Controller doesn't appear
to provide overloading, so this:
if ( $c->controller eq $c->controller('Login') ) { }
will never be true, as you're comparing 2 different objects' memory
addresses (what objects usually stringify to by default).
Carl
More information about the Catalyst
mailing list