def loginThread(): username = self.ui.username.text() password = self.ui.password.text() if username == "" or password == "": self.showMessageBox.emit(strings["missingFieldsErrorText"]) return try: if storage.getToken(username) and storage.getKey(username): token = storage.getToken(username) public, private = storage.getKey(username) newSession = Session(username, password, token, public, private) storage.storeKey(newSession.username, newSession.public, newSession.private) else: token, public, private = Session.requestNewToken(username, password) newSession = Session(username, password, token, public, private) storage.storeToken(newSession.username, token) storage.storeKey(newSession.username, newSession.public, newSession.private) self.loginComplete.emit(newSession) except SecureMessagingException as error: if error.message == HTTPStrings.RESPONSE_UNAUTHORIZED: storage.storeKey(username, None, None) storage.storeToken(username, None) loginThread() return self.showMessageBox.emit(strings["errorText"] + responseTranslations[str(error)])
def isAuthorized(device, agreement, token): tok = storage.getToken(agreement, device) if tok is None: return (False, "Token chain wasn't initiated, try logging in.") return ((token == tok[0]), "Session dropped for some reason, try logging in again.")