[Catalyst] tutorial - adding "auth" function

Kieren Diment diment at gmail.com
Thu Jun 8 02:25:51 CEST 2006


At this point in time, it's probably a good idea to use the tutorail docs in
svn which will be in the next release of Catalyst.

You can download a tarball of a snapshot of my working copy at
http://totaldatasolution.com/Cat-Manual.tar.gz

or  download the current svn tutorials with the command:

svn co
http://dev.catalyst.perl.org/repos/Catalyst/branches/Catalyst-docs/lib/Catalyst/Manual

On 08/06/06, Sarah Berry <berry.sarah at gmail.com> wrote:
>
> Hi,
>
> I've been trying to learn Catalyst by going through the tutorial. I'm
> stuck on the "exercise for the reader" in which I'm supposed to add an
> "auto" action in tutorial.pm, to force the user to log in before s/he can
> view any other pages. I searched the list archives, and someone else with a
> similar problem was told,
> "Your auto action redirects *every* access to /users/login, which
> includes calls of /users/login. So a check for action or path should do
> the trick."
> I haven't been able to figure out how to check for the path. Here is what
> I have so far (2 versions of the code):
>
>     sub auto : Private {
>         my ( $self, $c) = @_;
>         if ( !$c->user_exists) {
>             $c->res->redirect( '/users/login' ); # require login
>             $c->res->body("redirecting to login ... ");
>             return 0; # abort request and go immediately to end()
>         }
>         return 1; # success; carry on to next action
>     }
>
>     sub end : Private {
>         my ($self, $c) = @_;
>         $c->forward('tutorial::View::TToolkit') unless $c->res->body();
>     }
>
> Using that code, a call to any page gets redirected to /users/login, but
> the page doesn't display -- just this message:
>
> "The page isn't redirecting properly.
> Firefox has detected that the server is redirecting the request for this
> address in a way that will never complete."
>
> The other code I've tried is this:
>
>     sub auto : Private {
>         my ( $self, $c, $path_args) = @_;
>         if ( !$c->user_exists && $path_args != "/users/login" ) {
>             $c->res->redirect( '/users/login' ); # require login
>             $c->res->body("redirecting to login ... ");
>             return 0; # abort request and go immediately to end()
>         }
>         $c->stash->{message} = $path_args;
>         return 1; # success; carry on to next action
>     }
>
> I can tell from the page that displays the stashed message that $path_args
> is blank. So I can access any page and I am never redirected to a login.
> So, how can I tweak this auto function to force users to log in?
>
> thanks in advance,
> Sarah
>
> _______________________________________________
> Catalyst mailing list
> Catalyst at lists.rawmode.org
> http://lists.rawmode.org/mailman/listinfo/catalyst
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.rawmode.org/pipermail/catalyst/attachments/20060608/85624440/attachment.htm 


More information about the Catalyst mailing list