[Catalyst] tutorial - adding "auth" function
Wade.Stuart at fallon.com
Wade.Stuart at fallon.com
Wed Jun 7 23:10:01 CEST 2006
catalyst-bounces at lists.rawmode.org wrote on 06/07/2006 04:01:56 PM:
> 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."
maybe check to see if the user is logged in before redirecting wholesale to
/users/login?
> 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
More information about the Catalyst
mailing list