- def load(self):
- """Retrieve account data from cold storage."""
-
- # what the filename for the user account should be
- filename = muffconf.get("files", "accounts") + "/" + self.name
-
- # try to load the password hash and last connection ipa
- try:
- self.record.read(filename)
- self.passhash = self.record.get("account", "passhash")
- self.last_address = self.record.get("account", "last_address", self.address)
-
- # if we can't, that's okay too
- except:
- pass
-
- def get_passhash(self):
- """Retrieve the user's account password hash from storage."""
-
- # what the filename for the user account could be
- filename = muffconf.get("files", "accounts") + "/" + self.proposed_name
-
- # create a temporary account record object
- temporary_record = ConfigParser.SafeConfigParser()
-
- # try to load the indicated account and get a password hash
- try:
- temporary_record.read(filename)
- self.passhash = temporary_record.get("account", "passhash")
- return True
-
- # otherwise, the password hash is empty
- except:
- self.passhash = ""
- return False
-
- def save(self):
- """Record account data to cold storage."""
-
- # the user account must be authenticated to save
- if self.authenticated:
-
- # create an account section if it doesn't exist
- if not self.record.has_section("account"):
- self.record.add_section("account")
-
- # write some in-memory data to the record
- self.record.set("account", "name", self.name)
- self.record.set("account", "passhash", self.passhash)
- self.record.set("account", "last_address", self.address)
-
- # the account files live here
- account_path = muffconf.get("files", "accounts")
- # the filename to which we'll write
- filename = account_path + "/" + self.name.lower()
-
- # open the user account file for writing
- try:
- record_file = file(filename, "w")
-
- # if the directory doesn't exist, create it first
- except IOError:
- os.makedirs(account_path)
- record_file = file(filename, "w")
-
- # dump the account data to it
- self.record.write(record_file)
-
- # close the user account file
- record_file.flush()
- record_file.close()
-
- # set the permissions to 0600
- os.chmod(filename, 0600)
-