def _decorator(request, *args, **kwargs): if request.META.has_key("HTTP_HOST"): realm = request.META["HTTP_HOST"] else: realm = Site.objects.get_current().name digestor = Digestor(method=request.method, path=request.get_full_path(), realm=realm) if request.META.has_key("HTTP_AUTHORIZATION"): logger.debug("request meta: %s" % request.META["HTTP_AUTHORIZATION"]) try: parsed_header = digestor.parse_authorization_header(request.META["HTTP_AUTHORIZATION"]) if parsed_header["realm"] == realm: odk_access = ODKAccess.objects.get(user_identifier=parsed_header["username"], is_active=True) # interviewer = Interviewer.objects.get(mobile_number=parsed_header['username'], is_blocked=False) authenticator = SimpleHardcodedAuthenticator( server_realm=realm, server_username=odk_access.user_identifier, server_password=odk_access.odk_token, ) if authenticator.secret_passed(digestor): request.user = odk_access.interviewer return func(request, *args, **kwargs) except ODKAccess.DoesNotExist: return OpenRosaResponseNotFound() except ValueError, err: return OpenRosaResponseBadRequest()
def _decorator(request, *args, **kwargs): if request.META.has_key('HTTP_HOST'): realm = request.META['HTTP_HOST'] else: realm = Site.objects.get_current().name digestor = Digestor(method=request.method, path=request.get_full_path(), realm=realm) if request.META.has_key('HTTP_AUTHORIZATION'): logger.debug('request meta: %s' % request.META['HTTP_AUTHORIZATION']) try: parsed_header = digestor.parse_authorization_header( request.META['HTTP_AUTHORIZATION']) if parsed_header['realm'] == realm: odk_access = ODKAccess.objects.get( user_identifier=parsed_header['username'], is_active=True) # interviewer = Interviewer.objects.get(mobile_number=parsed_header['username'], is_blocked=False) authenticator = SimpleHardcodedAuthenticator( server_realm=realm, server_username=odk_access.user_identifier, server_password=odk_access.odk_token) if authenticator.secret_passed(digestor): request.user = odk_access.interviewer return func(request, *args, **kwargs) except ODKAccess.DoesNotExist: return OpenRosaResponseNotFound() except ValueError, err: return OpenRosaResponseBadRequest()
def _decorator(request, *args, **kwargs): if request.META.has_key("HTTP_AUTHORIZATION"): authmeth, auth = request.META["HTTP_AUTHORIZATION"].split(" ", 1) logger.debug("request meta: %s" % request.META["HTTP_AUTHORIZATION"]) if authmeth.lower() == "basic": auth = auth.strip().decode("base64") username, password = auth.split(":", 1) try: request.user = ODKAccess.objects.get( user_identifier=username, odk_token=password, is_active=True ).interviewer # Interviewer.objects.get(mobile_number=username, odk_token=password) return func(request, *args, **kwargs) except ODKAccess.DoesNotExist: return OpenRosaResponseNotFound() return HttpResponseNotAuthorized()
def _decorator(request, *args, **kwargs): if request.META.has_key('HTTP_AUTHORIZATION'): authmeth, auth = request.META['HTTP_AUTHORIZATION'].split(' ', 1) logger.debug('request meta: %s' % request.META['HTTP_AUTHORIZATION']) if authmeth.lower() == 'basic': auth = auth.strip().decode('base64') username, password = auth.split(':', 1) try: request.user = ODKAccess.objects.get( user_identifier=username, odk_token=password, is_active=True).interviewer #Interviewer.objects.get(mobile_number=username, odk_token=password) return func(request, *args, **kwargs) except ODKAccess.DoesNotExist: return OpenRosaResponseNotFound() return HttpResponseNotAuthorized()