Created
August 28, 2010 21:14
-
-
Save paultiarks/555592 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
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