def get(self, request, format=None): partyId = request.COOKIES.get('credentialId') loginKey = request.COOKIES.get('secretKey') ipList = request.GET.get('ipList') url = request.GET.get('url').decode('utf8') partnerId = request.GET.get('partnerId') apiKey = request.COOKIES.get('apiKey') ipList = ipList.split(',') ipResult = '' for ip in ipList: status = Authorization.getAccessStatus( loginKey, ip, partyId, url, partnerId, getHostUrlFromRequest(request), apiKey) ipResult = ip if status == Status.ok: break userIdentifier = None if partyId and partyId.isdigit() and Credential.objects.all().filter( partyId=partyId).exists(): userIdentifier = Credential.objects.all().get( partyId=partyId).userIdentifier isPaidContent = 'T' if AccessType.checkHasAccessRule( url, "Paid", partnerId) else 'F' redirectUri = None # only get redirect uri when user have no access to the page if status != Status.ok: redirectUri = UriPattern.getRedirectUri(url, partnerId) # PWL-847: get organization id for the ip orgId = '' parties = Party.getByIp(ipResult) if len(parties) > 0: orgId = parties[0] response = { "ip": ipResult, "orgId": orgId, "status": status, "userIdentifier": userIdentifier, "isPaidContent": isPaidContent, "redirectUri": redirectUri } ''' authorization access should contain these elements: timestamp (current date and time, required) + IP address (required) + party id (may be null) + user identifier (may be null) partner id (required) complete URI (required) status (required) ''' logger.info("Authorization Access %s%s %s%s %s%s %s%s %s%s %s%s" % ("ip:", ipResult, "partyId:", partyId, "userIdentifier:", userIdentifier, "partnerId:", partnerId, "url:", url, "status:", status)) return HttpResponse(json.dumps(response), content_type="application/json")
def getByIp(ipAddress): subscriptionList = [] parties = Party.getByIp(ipAddress) return Subscription.objects.filter(partyId__in=parties)