Created
January 16, 2012 07:27
-
-
Save joelsemar/1619589 to your computer and use it in GitHub Desktop.
auth decorator
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
def login_required(fn): | |
fn.authentication_required = True | |
@wraps(fn) | |
def inner(*args, **kwargs): | |
from webservice_tools.response_util import ResponseObject | |
response = ResponseObject() | |
try: | |
request = [a for a in args if hasattr(a, 'user')][0] | |
except IndexError: | |
return response.send(errors="Login required method called without request object", status=500) | |
if request.user.is_authenticated(): | |
return fn(*args, **kwargs) | |
return response.send(errors='401 -- Unauthorized', status=401) | |
return inner |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment