Ejemplo n.º 1
0
def api_operation_client_session_init(request):
    print "Client-Session-Init"
    o = api_util.init_request(request, "GET")
    
    if isinstance(o, HttpResponse):
        return o
    
    if request.META["HTTP_UNIT_KEY"]:
        pcuPublicKey = request.META["HTTP_UNIT_KEY"]
    else:
        return api_util.generate_response({ "error": "Missing unit key" }, 400)
    
    sourceIp = request.META["REMOTE_ADDR"]
    
    print "Generating session from %s for PCU pub key %s." % (sourceIp, pcuPublicKey)
    
    try:
        pcu = PCU.objects.get(publicKey = pcuPublicKey)
    except Exception, e:
        print "Error retrieving PCU with public key [%s]: %s" % (pcuPublicKey, e)
        return HttpResponse(status = 401)
Ejemplo n.º 2
0
def api_operation_pcu_list(request):
    print "PCU-List"
    
    o = api_util.init_request(request, "GET")
    if isinstance(o, HttpResponse):
        return o
    
    userProfile = api_util.get_profile(request)
    if userProfile == None:
        return HttpResponse(status = 401)
    
    output = []
    
    profileUnits = PCU.objects.filter(profile = userProfile)
    for pcu in profileUnits:
        output.append({
            "url": pcu.url,
            "pcuIdentifier": pcu.pcuIdentifier,
            "publicKey": pcu.publicKey,
            "created": pcu.created           
        })

    return api_util.generate_response(output, 200)
Ejemplo n.º 3
0
    try:
        guestSession = GuestSession.objects.get(externalIdent = sessionId)
    except Exception, e:
        print "Error retrieving guest session with external ident [%s]: %s" % (sessionId, e)
        return HttpResponse(status = 401)

    if not userProfile:
        try:
            userProfile = ContentProfile.objects.get(pk = guestSession.profile.id)
            print "Retrieved profile %s for guest session ID %s" % (userProfile.id, sessionId)
        except Exception, e:
            print "Error retrieving profile attached to guest session %s: %s" % (sessionId, e)
            return HttpResponse(status = 401)
    
    if pcu.profile.id != userProfile.id:
        return api_util.generate_response({ "error": "PCU not attached to profile" }, 401)
    
    if guestSession.profile != userProfile:
        print "Profile [%s] not attached to guest session [%s]" % (pcu.publicKey, guestSession.externalIdent)
        return HttpResponse(status = 401)
    
    try:
        try:
            action = PCUAction.objects.get(code = actionCode)
        except Exception, e:
            print "Error retrieving action for code [%s]: %s" % (actionCode, e)
            return api_util.generate_response({ "error": "Invalid action: [%s]" % actionCode }, 422)
        
        interaction = PCUInteraction()
        interaction.pcu = pcu
        interaction.action = action