def load_credentials(self,passphrase=''): ''' Tries to load the credentials from the configuration file and display them to the user. If the credentials in the configuration file are invalid, they will not be loaded. ''' savedPassword = True #a default condition is needed. key = self.gox.config.get_string("gox", "secret_key") secret = self.gox.config.get_string("gox", "secret_secret") if not passphrase: #if password is blank (default NOT stored) savedPassword = False #then change the default condition to False #and grab password from the password tab password box. self.passphrase = str(self.mainWindow.passwordLineEdit.text()) try: utilities.assert_valid_key(key) secret = utilities.decrypt(secret, self.passphrase) except Exception: key = '' secret = '' self.secret.key = key self.secret.secret = secret if not key == '' and not secret == '': #if everything is OK, set the placeholder text to show credentials were loaded OK self.mainWindow.lineEditKey.setPlaceholderText('Loaded Key From File') self.mainWindow.lineEditSecret.setPlaceholderText('Decrypted Secret Using Password') #and switch current tab back to the main Account Balance Tab self.mainWindow.tabWidget_1.setCurrentIndex(0) if not savedPassword: #check for default password. if not, restart the socket. self.status_message("Credentials changed. Restarting MtGox Client") self.restart_gox() #restart the gox socket. else: self.status_message("Key and Secret are blank. Enter them and click Apply.") self.mainWindow.tabWidget_1.setCurrentIndex(1)
def __slot_validate_key(self,key): try: utilities.assert_valid_key(str(key)) self.__set_status('Key is valid.') except Exception as e: self.__disable_ok('Invalid key. %s' % e) return 1
def save_credentials(self): ''' Tries to encrypt the credentials entered by the user and save them to the configuration file. Incomplete or inplausible credentials will not be saved. ''' def error_message(reason): #refactored to be a little cleaner phrase = 'Credentials not saved ' self.status_message(phrase + reason) return 0 key = str(format(self.mainWindow.lineEditKey.text())) secret = str(self.mainWindow.lineEditSecret.text()) if key == '': return error_message("(empty key).") if secret == '': return error_message("(empty secret).") #get the passphrase from Password Tab self.passphrase = str(self.mainWindow.passwordLineEdit.text()) #if the user never filled in the password box, cause an error, and #switch the current tab to the password tab for them to fill it in. if self.passphrase == '': self.mainWindow.tabWidget_1.setCurrentIndex(2) return error_message("(invalid password).") try: utilities.assert_valid_key(key) except Exception: return error_message("(invalid key).") try: secret = utilities.encrypt(secret, self.passphrase) except Exception: return error_message("(invalid secret).") self.gox.config.set("gox", "secret_key", key) self.gox.config.set("gox", "secret_secret", secret) self.gox.config.save() #if everything's OK, trigger a reload of credentials(below) self.load_credentials()
def load_credentials(self): ''' Tries to load the credentials from the configuration file and display them to the user. If the credentials in the configuration file are invalid, they will not be loaded. ''' key = self.gox.config.get_string("gox", "secret_key") secret = self.gox.config.get_string("gox", "secret_secret") try: utilities.assert_valid_key(key) secret = utilities.decrypt(secret, View.PASSPHRASE) except Exception: key = '' secret = '' self.secret.key = key self.mainWindow.lineEditKey.setText(key) self.secret.secret = secret self.mainWindow.lineEditSecret.setText(secret)
def __slot_validate_credentials(self): key = str(self.__ui.lineEditKey.text()) secret = str(self.__ui.lineEditSecret.text()) # empty credentials are allowed if key == '' and secret == '': self.__enable_ok() return try: utilities.assert_valid_key(key) except Exception as e: self.__disable_ok('Invalid key.'.format(str(e))) return try: utilities.assert_valid_secret(secret) except Exception as e: self.__disable_ok('Invalid secret.'.format(str(e))) return self.__enable_ok()
def save_credentials(self): ''' Tries to encrypt the credentials entered by the user and save them to the configuration file. Incomplete or inplausible credentials will not be saved. ''' key = str(format(self.mainWindow.lineEditKey.text())) secret = str(self.mainWindow.lineEditSecret.text()) if key == '': self.status_message("Credentials not saved (empty key).") return if secret == '': self.status_message("Credentials not saved (empty secret).") return try: utilities.assert_valid_key(key) except Exception: self.status_message("Credentials not saved (invalid key).") return try: secret = utilities.encrypt(secret, View.PASSPHRASE) except Exception: self.status_message("Credentials not saved (invalid secret).") return self.gox.config.set("gox", "secret_key", key) self.gox.config.set("gox", "secret_secret", secret) self.gox.config.save() self.status_message("Credentials saved.") self.load_credentials() self.restart_gox()
def test_assert_valid_key_ok(self): utilities.assert_valid_key('fd8484c6-e826-418f-b1ef-2d120a77bb88') utilities.assert_valid_key('25685451-0602-418e-8cee-14f4f01647ed')