Browse Source

CORS on the bind request as well, fix local replication and remove superfluous logging.

David Baker 10 years ago
parent
commit
d7185b8ea2

+ 8 - 0
sydent/http/servlets/__init__.py

@@ -32,3 +32,11 @@ def jsonwrap(f):
     def inner(*args, **kwargs):
         return json.dumps(f(*args, **kwargs)).encode("UTF-8")
     return inner
+
+def send_cors(request):
+    request.setHeader(b"Content-Type", b"application/json")
+    request.setHeader("Access-Control-Allow-Origin", "*")
+    request.setHeader("Access-Control-Allow-Methods",
+                      "GET, POST, PUT, DELETE, OPTIONS")
+    request.setHeader("Access-Control-Allow-Headers",
+                      "Origin, X-Requested-With, Content-Type, Accept")

+ 1 - 10
sydent/http/servlets/emailservlet.py

@@ -19,16 +19,7 @@ from twisted.web.resource import Resource
 from sydent.validators.emailvalidator import EmailAddressException, EmailSendException, SessionExpiredException
 from sydent.validators.emailvalidator import IncorrectClientSecretException
 
-from sydent.http.servlets import require_args, jsonwrap
-
-
-def send_cors(request):
-    request.setHeader(b"Content-Type", b"application/json")
-    request.setHeader("Access-Control-Allow-Origin", "*")
-    request.setHeader("Access-Control-Allow-Methods",
-                      "GET, POST, PUT, DELETE, OPTIONS")
-    request.setHeader("Access-Control-Allow-Headers",
-                      "Origin, X-Requested-With, Content-Type, Accept")
+from sydent.http.servlets import require_args, jsonwrap, send_cors
 
 
 class EmailRequestCodeServlet(Resource):

+ 9 - 2
sydent/http/servlets/threepidbindservlet.py

@@ -16,7 +16,7 @@
 
 from twisted.web.resource import Resource
 
-from sydent.http.servlets import require_args, jsonwrap
+from sydent.http.servlets import require_args, jsonwrap, send_cors
 from sydent.validators import SessionExpiredException, IncorrectClientSecretException, InvalidSessionIdException
 
 class ThreePidBindServlet(Resource):
@@ -25,6 +25,7 @@ class ThreePidBindServlet(Resource):
 
     @jsonwrap
     def render_POST(self, request):
+        send_cors(request)
         err = require_args(request, ('sid', 'clientSecret', 'mxid'))
         if err:
             return err
@@ -44,4 +45,10 @@ class ThreePidBindServlet(Resource):
                     'error': "This validation session has expired: call requestToken again"}
         except InvalidSessionIdException:
             return {'errcode': 'M_INVALID_SESSION_ID',
-                    'error': "Unknown session ID"}
+                    'error': "Unknown session ID"}
+
+    @jsonwrap
+    def render_OPTIONS(self, request):
+        send_cors(request)
+        request.setResponseCode(200)
+        return {}

+ 4 - 3
sydent/replication/peer.py

@@ -62,12 +62,13 @@ class LocalPeer(Peer):
 
     def pushUpdates(self, sgAssocs):
         globalAssocStore = GlobalAssociationStore(self.sydent)
-        for localId, sgAssoc in sgAssocs:
+        for localId in sgAssocs:
             if localId > self.lastId:
-                assocObj = threePidAssocFromDict(sgAssoc)
+                assocObj = threePidAssocFromDict(sgAssocs[localId])
 
                 # We can probably skip verification for the local peer (although it could be good as a sanity check)
-                globalAssocStore.addAssociation(assocObj, json.dumps(sgAssoc), self.sydent.server_name, localId)
+                globalAssocStore.addAssociation(assocObj, json.dumps(sgAssocs[localId]),
+                                                self.sydent.server_name, localId)
 
         d = twisted.internet.defer.succeed(True)
         return d

+ 0 - 1
sydent/validators/emailvalidator.py

@@ -82,7 +82,6 @@ class EmailValidator:
         logger.info("Attempting to mail code %s to %s using mail server %s", valSession.token, rawTo, mailServer)
 
         try:
-            logger.info("Token: %s", valSession.token)
             smtp = smtplib.SMTP(mailServer)
             smtp.sendmail(rawFrom, rawTo, msg.as_string())
             smtp.quit()