From decb04c3bf4b07815e901de64e04b1c1c6754e03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Touceda?= Date: Thu, 4 Jul 2013 18:25:48 -0300 Subject: Refactor methods and emit event when we know uid is not None --- src/leap/crypto/srpauth.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/leap/crypto/srpauth.py b/src/leap/crypto/srpauth.py index 781d67ae..8f5fb3d3 100644 --- a/src/leap/crypto/srpauth.py +++ b/src/leap/crypto/srpauth.py @@ -268,27 +268,29 @@ class SRPAuth(QtCore.QObject): raise SRPAuthenticationError(self.tr("Unknown error (%s)") % (auth_result.status_code,)) - json_content = json.loads(content) + return json.loads(content) + def _extract_data(self, json_content): try: M2 = json_content.get("M2", None) uid = json_content.get("id", None) token = json_content.get("token", None) except Exception as e: logger.error(e) - raise Exception("Something went wrong with the login") - - events_signal(proto.CLIENT_UID, content=uid) + raise SRPAuthenticationError("Something went wrong with the " + "login") self.set_uid(uid) self.set_token(token) if M2 is None or self.get_uid() is None: logger.error("Something went wrong. Content = %r" % - (content,)) + (json_content,)) raise SRPAuthenticationError(self.tr("Problem getting data " "from server")) + events_signal(proto.CLIENT_UID, content=uid) + return M2 def _verify_session(self, M2): @@ -359,6 +361,10 @@ class SRPAuth(QtCore.QObject): partial(self._threader, self._process_challenge), username=username) + d.addCallback( + partial(self._threader, + self._extract_data), + username=username) d.addCallback(partial(self._threader, self._verify_session)) -- cgit v1.2.3