Adds more support to begin to deal with updates
authorxray7224 <xray7224@googlemail.com>
Fri, 28 Jun 2013 18:34:56 +0000 (19:34 +0100)
committerxray7224 <jessica@megworld.co.uk>
Thu, 11 Jul 2013 17:21:43 +0000 (18:21 +0100)
mediagoblin/federation/views.py

index bfd58d270e1c2b8d8c8633ec71107788199dc123..f16ae1df0094f2518d2fbdc7701cf58e8fb18d8e 100644 (file)
@@ -38,17 +38,47 @@ def client_register(request):
 
     if "type" not in data:
         return json_response({"error":"No registration type provided"}, status=400)
-   
+
+    if "application_type" not in data or data["application_type"] not in client_types:
+        return json_response({"error":"Unknown application_type."}, status=400)
+    
+    client_type = data["type"]
+
+    if client_type == "client_update":
+        # updating a client
+        if "client_id" not in data:
+            return json_response({"error":"client_id is required to update."}, status=400)
+        elif "client_secret" not in data:
+            return json_response({"error":"client_secret is required to update."}, status=400)
+
+        client = Client.query.filter_by(id=data["client_id"], secret=data["client_secret"]).all()
+
+        if not client:
+            return json_response({"error":"Unauthorized.", status=403)
+
+    elif client_type == "client_associate":
+        # registering
+        if "client_id" in data:
+            return json_response({"error":"Only set client_id for update."}, status=400)
+        elif "access_token" in data:
+            return json_response({"error":"access_token not needed for registration."}, status=400)
+        elif "client_secret" in data:
+            return json_response({"error":"Only set client_secret for update."}, status=400)
+
     # generate the client_id and client_secret
     client_id = random_string(22) # seems to be what pump uses
     client_secret = random_string(43) # again, seems to be what pump uses
     expirey = 0 # for now, lets not have it expire
     expirey_db = None if expirey == 0 else expirey
+    
+    # save it
     client = Client(
         id=client_id, 
         secret=client_secret, 
         expirey=expirey_db,
-        application_type=data["type"]
+        application_type=data["type"],
+        logo_url=data.get("logo_url", None),
+        redirect_uri=data.get("redirect_uri", None)
     )
     client.save()