[Catalyst] logging in - redirecting

Octavian Rasnita orasnita at gmail.com
Wed Dec 27 07:04:46 GMT 2006


Hi,

I am trying to create a login system, but it gives a 404 Not Found error 
(only when the username and the password are correct).

The program starts by printing an empty login form, with no message. If the 
form is submitted empty, it is printed again and it also prints a message 
telling that the user/password should be typed.
If the user/password are typed but one of them are not correct, the program 
prints again the form, with an error message that tells this. All these work 
fine.

If the user/password are correct, the program gives a 404 Not Found error 
(for /login, the same url that also printed that login form), and I don't 
know why.
I have tried making a redirection, a forward, printing a simple text 
message, but with no success.

This happends with Apache2 and mod_perl. If I run it using Catalyst testing 
server with -k parameter, it works fine.
If I use it without -k, it gives the 404 Not Found error in more situations 
than when running it with Apache.

Please tell me what can I do to make it work.

Here is the content of the sub index : Private, the only subroutine from 
Controller/Login:

sub index : Private {
    my ( $self, $c ) = @_;

my $username = $c->request->params->{username} || "";
my $password = $c->request->params->{password} || "";

if ($username and $password) {
if ($c->login($username, $password)) {
$c->response->body("The login was correct.");
return;
#I have also tried $c->forward and $c->response->redirect with no success.
}
else {
$c->stash->{error_msg} = "The username or password are not correct. Please 
try again.";
$c->stash->{template} = "login.tt";
return;
}
}

$c->stash->{error_msg} = "Please type your username and password." if 
$c->request->params->{submit};

$c->stash->{template} = "login.tt";
}

And here is the content of Controller/Root.pm (only the subroutines):

sub auto : Private {
my ($self, $c) = @_;

if ($c->controller eq $c->controller('Login')) {
return 1;
}

if (!$c->user_exists) {
$c->response->redirect($c->uri_for("/login"));
return 0;
}

$c->stash->{template} = "index.tt";
return 1;
}

sub default : Private {
my ( $self, $c ) = @_;
$c->stash->{template} = "index.tt";
$c->forward($c->view('TT'));
}

sub end : Private {
my ( $self, $c ) = @_;
$c->forward( $c->view('TT'));
}

sub end : ActionClass('RenderView') {}

Thank you very much for any idea.

Octavian




More information about the Catalyst mailing list