Skip to content

Instantly share code, notes, and snippets.

@joelsemar
Created January 16, 2012 07:27
Show Gist options
  • Save joelsemar/1619589 to your computer and use it in GitHub Desktop.
Save joelsemar/1619589 to your computer and use it in GitHub Desktop.
auth decorator
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