[Catalyst] Use CatalystX::SimpleLogin Globally

Bernhard Graf catalyst4 at augensalat.de
Sat Feb 6 22:22:32 GMT 2010


John Atzger schrieb:
> I use CatalystX::SimpleLogin but I have to use "Does('NeedsLogin')" for
> every method. For controllers which require a login for anything, what I
> want is this:
> 
>   package Some::Controller::Stuff;
>   use Moose;
>   BEGIN { extend 'My::Controller::LoginRequired' }
> 
> I tried something like this:
> 
>   package My::Controller::LoginRequired;
> 
>   use Moose;
>   use namespace::autoclean;
> 
>   BEGIN { extends 'Catalyst::Controller::ActionRole' }
> 
>   sub auto :Private :Does('NeedsLogin') {}
> 
> But that doesn't work.  People can access actions in
> Some::Controller::Suff without logging in.  I think I just don't
> understand Catalyst well enough to know what to do here.

Read this, maybe it helps
http://search.cpan.org/perldoc?Catalyst::Controller::ActionRole

Or look at the source code of
http://search.cpan.org/src/BOBTFISH/CatalystX-SimpleLogin-0.08/lib/Catalyst/ActionRole/NeedsLogin.pm
you could virtually take this code and put it into your auto action.

Or if you use chained actions, you could add the Does(NeedsLogin)
attribute to any action chain link:

  package My::Controller::LoginRequired;

  # everything under /login needs login
  sub root : Chained(/) PathPart(admin) CaptureArgs(0) Does(NeedsLogin)
  {...}

  package Some::Controller::Stuff;

  sub foo : Chained(/admin) PathPart Args(0) {...}

Good luck

Bernhard



More information about the Catalyst mailing list