Created
November 14, 2011 03:06
-
-
Save lxfontes/1363142 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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