FAQ
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

Search Discussions

  • Carl Franks at Dec 4, 2007 at 11:41 am

    On 04/12/2007, Kalman Kiss 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
  • Kalman Kiss at Dec 4, 2007 at 12:25 pm

    Carl Franks wrote:
    ...
    [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 ***
    It was a lot easier to read once I'd deleted the commented out code
    and debugging statements.
    Sorry for that, i try to keep it in mind to strip the comments next time.
    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.
    The problem is gone when i switch to Catalyst::Controller base in Login.pm.
    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).
    As the above debug logs say the objects are the same type and address,
    and the original is from the tutorial (part 4).
    (Its working with FormBuilder btw.)

    Kami
  • Carl Franks at Dec 4, 2007 at 1:48 pm

    On 04/12/2007, Kalman Kiss wrote:

    The problem is gone when i switch to Catalyst::Controller base in Login.pm.
    Okay, that's interesting.
    As the above debug logs say the objects are the same type and address,
    and the original is from the tutorial (part 4).
    (Its working with FormBuilder btw.)
    Your debug statements are showing the output (addresses) of
    controller->path_prefix() - but you're comparing only controller().
    - although I didn't realise controller() within Login.pm returned the
    exact same object as controller('Login') did.
    I've not really used controller() very much, so can't really advise.

    Were you still only comparing ($c->controller eq
    $c->controller('Login')) and not path_prefix() when you switched back
    to Catalyst::Controller, and it worked?

    Carl
  • Kalman Kiss at Dec 4, 2007 at 2:21 pm

    Carl Franks wrote:
    Your debug statements are showing the output (addresses) of
    controller->path_prefix() - but you're comparing only controller().
    No, they show the address of the login controller, prefix is only there
    because I was mistrustful and curious :) :
    ...
    $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->path_prefix($c) eq
    $c->controller('Login')->path_prefix($c)
    ($c->controller eq $c->controller('Register'))
    ($c->controller eq $c->controller('Passremainder'))
    ) {
    $c->log->debug('*** Root: login, reg or passremainder.
    ***');
    return 1;
    }
    ...
    - although I didn't realise controller() within Login.pm returned the
    exact same object as controller('Login') did.
    I've not really used controller() very much, so can't really advise.

    Were you still only comparing ($c->controller eq
    $c->controller('Login')) and not path_prefix() when you switched back
    to Catalyst::Controller, and it worked?
    Im comparing the controllers and it works when C::C the base is.

    Thanx for your efforts so far. :)
    Greetings,
    Kami
  • Carl Franks at Dec 4, 2007 at 3:02 pm
    Could you post the definitions of the actions in Login.pm ?
    the subroutine contents aren't necessary, just the catalyst attributes
    e.g.
    sub login : Chained : Args { }

    thanks,
    Carl
  • Kalman Kiss at Dec 4, 2007 at 3:22 pm

    Carl Franks wrote:
    Could you post the definitions of the actions in Login.pm ?
    the subroutine contents aren't necessary, just the catalyst attributes
    e.g.
    sub login : Chained : Args { }
    sub login : Local : FormConfig('login.yml') {


    Kami

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupcatalyst @
categoriescatalyst, perl
postedDec 4, '07 at 11:07a
activeDec 4, '07 at 3:22p
posts7
users2
websitecatalystframework.org
irc#catalyst

2 users in discussion

Kalman Kiss: 4 posts Carl Franks: 3 posts

People

Translate

site design / logo © 2022 Grokbase