[Catalyst] Re: Calling Controller Methods from inside begin or auto.

J. Shirley jshirley at gmail.com
Wed Sep 30 15:53:26 GMT 2009


On Wed, Sep 30, 2009 at 8:09 AM, Bill Moseley <moseley at hank.org> wrote:

>
>
> On Wed, Sep 30, 2009 at 7:30 AM, Derek Wueppelmann <dwueppel at gmail.com>wr=
ote:
>
>> I'm actually doing forwards to my login page right now. So that when a
>> user logs in they can still see the page they were originally trying to
>> view. I capture the URL they were attempting to view in the login
>> process.
>>
>
> And then redirect back to that original page after login?
>
> I pass that data via the cache or session.
>
> $c->cache->set( $key, {
>     orig_url =3D> $url,
>     message =3D> 'Auhorization is required',
>  });
>
> $c->res->redirect( $c->uri_for( '/login', { info =3D> $key } ) );
>
>
> Catalyst docs show an example using auto.  BTW - shouldn't the redirect be
> an absolute-URI?
>
>            sub auto : Private {
>                my ( $self, $c ) =3D @_;
>                if ( !$c->user_exists ) { # Catalyst::Plugin::Authenticati=
on
>                    $c->res->redirect( '/login' ); # require login
>                    return 0; # abort request and go immediately to end()
>                }
>                return 1; # success; carry on to next action
>            }
>


My typical recipe is via parameter, rather than session.  This is more
flexible, and allows me to pass URLs to people with more definitive results.

You do, however, have to whitelist the URLs prior to redirection.  The very
basic recipe is just something to compare the URI base:

 my $redir =3D URI->new( $redir_url );
 $redir->base eq $c->req->uri->base;

-J
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20090930/c68e4=
0d3/attachment.htm


More information about the Catalyst mailing list