[Catalyst] Authentication gotchas

Nigel Metheringham nigel.metheringham at dev.intechnology.co.uk
Fri Dec 16 11:42:46 CET 2005


The authentication documentation examples, including the one in the
advent calendar:-
  http://catalyst.perl.org/calendar/2005/14

pretty much all have the same set of example code, eg:-
        use Catalyst qw/Authentication
                        ...
        
        sub login : Local {
             my ($self, $c) = @_;
        
             if (    my $user = $c->req->param("user")
                 and my $password = $c->req->param("password") )
             {
                 if ( $c->login( $user, $password ) ) {
                      $c->res->body( "hello " . $c->user->name );
                 } else {
                    # login incorrect
                 }
             }
             else {
                 # invalid form input
             }
        }

Unfortunately as written these tend to do interesting and unintended
things if you put them into the main app module.  [Hint: what class is
$c?  What happens when the login method calls $c->login($user,
$pass)?? ]

This stuff is easy to spot when you get an idea of whats happening, but
its bloody confusing for the poor sods trying this for the first time
and finding the example code just goes bang with a very strange error
message (in this case it tries to find a login method in a class named
for the user id you are logging in with).

I have to say the Advent Calendar snippets have been really useful for
me.  We need to pull all of these together to make some more
tutorial/example docs.

	Nigel.
-- 
[ Nigel Metheringham           Nigel.Metheringham at InTechnology.co.uk ]
[ - Comments in this message are my own and not ITO opinion/policy - ]





More information about the Catalyst mailing list