Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Dancer sessions and before hook

by aaron_baugher (Curate)
on Jul 28, 2012 at 03:57 UTC ( [id://984137]=note: print w/replies, xml ) Need Help??


in reply to Dancer sessions and before hook

This regex:

m{^/login|/}

will match anything starting with /login, OR anything containing a forward slash. So it'll match all your routes, and the second half of your if condition will never be true, and your before hook will never redirect to /login.

If you're trying to match either the /login page OR the home page, you'll need to anchor that part of the pattern, or compare strings directly instead of a regex:

m{^/login|^/$}; # or if($route ne '/login' and $route ne '/'){

Aaron B.
Available for small or large Perl jobs; see my home node.

Replies are listed 'Best First'.
Re^2: Dancer sessions and before hook
by monktopher (Novice) on Jul 28, 2012 at 04:14 UTC

    Aaron

    Thank you for your reply. That fixed the issue.

    I had to type out that if statement in English to fully understand what was going wrong:If the user does not have a session AND they're trying to get to someplace other than /login or /, redirect them to /login. Since my regex was matching anything starting with /, there was no other place where they could go, making the 2nd half fail like you said.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://984137]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2024-04-20 03:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found