[Catalyst] Auth tutorial merry-go-round
Dermot
paikkos at googlemail.com
Mon Jul 7 09:40:58 BST 2008
Hi,
I have been following the tutorial and am stuck in a loop. In my Root
controller I have the following
sub auto : Private {
my ($self,$c) = @_;
if ($c->controller eq $c->controller('Login')) {
return 1;
}
if (!$c->user_exists) {
$c->log->debug('***Root::auto User not found, forwarding to /login');
$c->response->redirect($c->uri_for('/login'));
return 0;
}
# user found
return 1;
}
In my Login controller I have
sub index :Path :Args(0) {
my ( $self, $c ) = @_;
# Get the username and password from form
my $username = $c->request->params->{username} || "";
my $password = $c->request->params->{password} || "";
# If the username and password values were found in form
if ($username && $password) {
# Attempt to log the user in
$c->log->debug("User=$username, Password=$password");
if ($c->authenticate({ username => $username,password =>
$password} ) ) {
# If successful, then let them use the application
$c->log->debug("Login Success");
$c->response->redirect($c->uri_for('/books/list'));
return;
} else {
# Set an error message
$c->stash->{error_msg} = "Bad username or password.";
}
}
# If either of above don't work out, send to the login page
$c->stash->{template} = 'login.tt2';
}
When i login I see these debug messages
[debug] Path is "login"
[debug] User=admin, Password=admin
[debug] Created session "0628e51d5825d7309fd64a2404dd907bbea0ae27"
[debug] Login Success
...
.----------------------------------------------------------------+-----------.
| Action | Time |
+----------------------------------------------------------------+-----------+
| /auto | 0.000649s |
| /login/index | 0.032623s |
| /end
...
[debug] "GET" request for "books/list" from "127.0.0.1"
[debug] Path is "books/list"
[debug] ***Root::auto User not found, forwarding to /login
[debug] Redirecting to "http://localhost:3000/login"
So while $c->authenticate can see my login in my Login controller, it
can't in Root/auto !!! Can anyone point tell where I am going wrong?
TIA,
Dp.
More information about the Catalyst
mailing list