pyreqauth - Python web auth decorator (github.com)

1 points by wuster ↗ HN
Ever get sick of this pattern in your web app?

if <user exists>: .. do something with user else: .. show error message or redirect user to login

over and over and over again in your routing handlers?

With a Bottle.py example: what if you could just tag your handler with a decorator like this:

@bottle.get('/magic/resource/<resource_id>') @require_user # <-- this is the awesome magic def user_account(user, resource_id): # <-- the 'user' arg is provided by the decorator ....# notice the user object is automagically available ....return "Hi %s - welcome to resource %s" % (user["name"], resource

Similar to tornado's web.authenticated decorator, but my version has some advantages:

1) framework agnostic 2) the decorator takes arguments to allow for customization 3) you can adapt my pattern to make your own "require resource" helper - (heck I can change my project to simply help with "require resource", but I hate generalizing code so much no one knows what to do with it anymore)

0 comments

[ 5.5 ms ] story [ 12.1 ms ] thread

No comments yet.