[Catalyst] How to do pass-through login?

Gunnar Strand gunnarstrand at yahoo.com
Thu Jul 9 09:03:16 GMT 2009


Hi,

I am looking for a way to send users to the login screen if they are 
trying to access a restricted path, and if the login is valid, the 
original request should just continue like this:

1. myapp <- GET /member/only
2. myapp -> /login_form
3. myapp <- POST /login
4. myapp -> /member/only

I guess this is what is called "pass-through login (and other actions)" 
in the Cookbook, but I can't understand the description:

"Provide actions for these, but when they're required for something else 
fill e.g. a form variable __login and have a sub begin like so:"

    sub begin : Private {
      my ($self, $c) = @_;
      foreach my $action (qw/login docommand foo bar whatever/) {
        if ($c->req->params->{"__${action}"}) {
          $c->forward($action);
        }
      }
    }


Where is the data from the original request stored? Is everything stored 
in the "__$action" key including any values in a form submission?

An example on how pass-through works would be very helpful.

I would have expected something like this (pseudo-code):

In "begin" for /member/only:
unless ( $c -> user_exists() ) {
  $c -> delay_action();       # Saves state in Flash or Session
  $c -> forward('/login_form');
}

In "login" after authentication:
if ( $c -> restore_action() ) {
  $c -> continue_action();
}

KR,
Gunnar






      



More information about the Catalyst mailing list