Skip to content

Instantly share code, notes, and snippets.

@paultiarks
Created August 28, 2010 21:14
Show Gist options
  • Save paultiarks/555592 to your computer and use it in GitHub Desktop.
Save paultiarks/555592 to your computer and use it in GitHub Desktop.
def require_authentication(function):
INVALID_CREDENTIALS = 0
INVALID_PARAMETERS = 1
def error(errorType):
if errorType == INVALID_CREDENTIALS:
return response(code = '403', message = 'Invalid username or password')
elif errorType == INVALID_PARAMETERS:
return response(code = '100', message = 'Username or password not provided')
def wrap(request, *args, **kwargs):
if ('username' not in request.REQUEST.keys() or 'password' not in request.REQUEST.keys()):
return error(INVALID_PARAMETERS)
elif (not authenticate(username = (True and request.REQUEST.get('username') or request.REQUEST.get('email')), password = request.REQUEST.get('password'))):
return error(INVALID_CREDENTIALS)
return function(request, *args, **kwargs)
return wrap
@require_authentication
def authenticate(request):
getparams = request.GET
return response(code='200', message='Authenticated!')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment