summary refs log tree commit diff
path: root/synapse/rest/client/v1/login.py
diff options
context:
space:
mode:
authorMark Haines <mjark@negativecurvature.net>2016-03-09 11:26:30 +0000
committerMark Haines <mjark@negativecurvature.net>2016-03-09 11:26:30 +0000
commitb7b899cae617eafc3f7bb9fcf648bb0899ec146a (patch)
treeb8a25b359abf412a692a6f391d142c5cfa9a98bb /synapse/rest/client/v1/login.py
parentEnsure integer is an integer (diff)
parentAdd a parse_json_object function (diff)
downloadsynapse-b7b899cae617eafc3f7bb9fcf648bb0899ec146a.tar.xz
Merge pull request #628 from matrix-org/markjh/parse_json
Add a parse_json_object function

to deduplicate all the copy+pasted _parse_json functions. Also document
the parse_.* functions.
Diffstat (limited to 'synapse/rest/client/v1/login.py')
-rw-r--r--synapse/rest/client/v1/login.py15
1 files changed, 2 insertions, 13 deletions
diff --git a/synapse/rest/client/v1/login.py b/synapse/rest/client/v1/login.py
index f6902a60a8..fe593d07ce 100644
--- a/synapse/rest/client/v1/login.py
+++ b/synapse/rest/client/v1/login.py
@@ -18,6 +18,7 @@ from twisted.internet import defer
 from synapse.api.errors import SynapseError, LoginError, Codes
 from synapse.types import UserID
 from synapse.http.server import finish_request
+from synapse.http.servlet import parse_json_object_from_request
 
 from .base import ClientV1RestServlet, client_path_patterns
 
@@ -79,7 +80,7 @@ class LoginRestServlet(ClientV1RestServlet):
 
     @defer.inlineCallbacks
     def on_POST(self, request):
-        login_submission = _parse_json(request)
+        login_submission = parse_json_object_from_request(request)
         try:
             if login_submission["type"] == LoginRestServlet.PASS_TYPE:
                 if not self.password_enabled:
@@ -400,18 +401,6 @@ class CasTicketServlet(ClientV1RestServlet):
         return (user, attributes)
 
 
-def _parse_json(request):
-    try:
-        content = json.loads(request.content.read())
-        if type(content) != dict:
-            raise SynapseError(
-                400, "Content must be a JSON object.", errcode=Codes.BAD_JSON
-            )
-        return content
-    except ValueError:
-        raise SynapseError(400, "Content not JSON.", errcode=Codes.NOT_JSON)
-
-
 def register_servlets(hs, http_server):
     LoginRestServlet(hs).register(http_server)
     if hs.config.saml2_enabled: