On Sat, Mar 27, 2010 at 2:22 AM, Ovid <[email protected]> wrote:
> Hi all,
>
> What would be the best approach to intercept *everything* when a certain 
> condition occurs and redirect to something like /user/waiting/?  Should I use 
> "before execute" in the lib/MyApp.pm?
>
> I'm working on an app where users must authenticate (via 
> CatalystX::SimpleLogin and a custom ActionRole).  At times, users may engage 
> in activity which temporarily makes it impossible to take any other action. 
> Hypothetical example: users kick off a job which takes 5 minutes to run, so 
> we restrict their ability to do *anything* else for that 5 minutes. Thus, it 
> would be nice if I could globally redirect any authenticated user to 
> something like /user/waiting/ or something like that.
>
> Cheers,
> Ovid

You can do a couple approaches, one is using 'auto' in the Root
controller.  This is not a good solution, but easy to get working.  If
you need to add more controllers to the whitelist, you get a big list
and a poor implementation of an ACL.

sub auto : Private {
    my ( $self, $c ) = @_;
    # Return 1 if the user exists, allowing actions to proceed.
    if ( $c->user_exists ) {
        return 1;
    }
    # Allow this action to go through on the login controller.
    if ( $c->controller == $c->controller('Login') ) {
        return 1;
    }
    # Otherwise, reject!
    return 0;
}

The approach I take, and recommend, is to use Chained for this (though
on an existing application it may be too late).

You can setup chains for auth required that redirects as desired, then
anything that doesn't need authentication can either tie to a
mid-point action that doesn't (for logging?) or simply chain to ("/").
 CatalystX::SimpleLogin simply chains to "/" (See
http://cpansearch.perl.org/src/BOBTFISH/CatalystX-SimpleLogin-0.09/lib/CatalystX/SimpleLogin/Controller/Login.pm)
to not get caught up on any midpoint interceptions, but this is
overridable via configuration.

-J

_______________________________________________
List: [email protected]
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/[email protected]/
Dev site: http://dev.catalyst.perl.org/

Reply via email to