Question

I am creating a Catalyst application, currently I have a simple login page that I access by going to the url:

http://mydomainname/login

This works perfectly, it fetches the html page and using the css file it references creates a pretty login page.

However, If I also go to the following url:

http://mydomainname/login/login

The login page I created still gets displayed, except this time it just displays the basic buttons, textboxes and so on without the css, as it appears it is not accessing the css file for styling.

This happens all the time 'login' is in the path:

eg.

http://mydomainname/login/login
http://mydomainname/login/login/login
http://mydomainname/login/login/login/login/login

and so on...

What I want is obviously for http://mydomainname/login/login not to work or redirect to just http://mydomainname/login for example.

Im my Login.pm Controller I have:

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

    $c->forward('login');  
}

sub login : Path('/login') {  
        my ( $self, $c ) = @_;

        $c->stash->{title} = 'Login Page';
        $c->stash->{pagetype} = "html";
        $c->stash->{template} = "login.html";
}

Firstly, is this how the controller should look? and what do I need to do to prevent this double url path problem from occurring (eg http://mydomainname/login/login or http://mydomainname/login/login/login/login).

Was it helpful?

Solution

The first /login is being matched from the Controller name, and the second /login is being matched from the Action name (the sub).

You either need to move the entire login sub into your Root controller, or move its logic into the existing default handler. Personally, I prefer to put actions like login and logout into the Root controller. They're unlikely to have anything else chained to them or dependent on them. Does Login.pm have any other actions or methods?

The missing CSS styling is likely to be an issue of relative paths in your login.html, or the configuration of static resources in your main program. You should be able to debug that one with your browser's Dev Tools.

OTHER TIPS

Explicitly say that there should be no arguments:

sub login :Path('/login') :Args(0) {

Then the controller won't match /login/etc/etc/etc

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top