Skip to content

Instantly share code, notes, and snippets.

@lxfontes
Created November 14, 2011 03:06
Show Gist options
  • Save lxfontes/1363142 to your computer and use it in GitHub Desktop.
Save lxfontes/1363142 to your computer and use it in GitHub Desktop.
import cyclone.web
import functools
def requiredrole(role):
"""@requiredrole(role_name)
Example:
class Secret(BaseHandler):
@requiredrole("admin")
@cyclone.web.authenticated
def get(self):
self.render('secret.html')
"""
def decorator(method):
@functools.wraps(method)
def wrapper(self,*args,**kwargs):
if self.current_user and self.current_user['role'] != role:
raise cyclone.web.HTTPError(403)
else:
return method(self,*args,**kwargs)
return wrapper
return decorator
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment