[Catalyst] tutorial - adding "auth" function
Adam Herzog
adam at herzogdesigns.com
Thu Jun 8 00:12:43 CEST 2006
On 6/7/06, Sarah Berry <berry.sarah at gmail.com> wrote:
> "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."
This is correct. Essentially, your auto is redirecting the user to
/users/login, which then causes a new request and auto is run again,
and the user is redirected again. I added some code inline which
should prevent the recursive redirects.
> sub auto : Private {
> my ( $self, $c) = @_;
# Allow unauthenticated users to reach the login page
if ($c->request->path =~ /users/login/) {
return 1;
}
> 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
> }
Hope that helps,
-A
More information about the Catalyst
mailing list