示例#1
0
 def modify_password(self):
     """
     个人中心 - 修改密码
     :return:
     """
     _not_null_flag = False
     try:
         while not _not_null_flag:
             _new_password = input("输入新密码: ").strip()
             _confirm_password = input("再次输入确认密码:").strip()
             if not _new_password or not _confirm_password:
                 my_Common.show_message("密码不能为空,请重新输入!", "ERROR")
                 continue
             if _new_password != _confirm_password:
                 my_Common.show_message("两次输入密码不一致,请重新输入!", "NOTICE")
                 continue
             _not_null_flag = True
         self.password = _new_password
         _password = my_Common.encrypt(self.password)
         self.dict_user[self.username]["password"] = _password
         self.update_user()
         my_Common.show_message("密码修改成功!", "INFORMATIOM")
         return True
     except Exception as e:
         my_Common.write_error_log(e)
         return False
示例#2
0
    def load_data_from_db(tabename):
        """
		从指定的数据表中获取所有数据,通过 json 方式将数据返回
		:param tabename: 数据文件名
		:return: 返回所有结果
		"""
        try:
            with open(tabename, 'r+') as f:
                return json.load(f)
        except Exception as e:
            my_Common.write_error_log(e)
示例#3
0
    def write_db_json(contant, filename):
        """
		将信息以 json 格式写入数据表文件(覆盖)
		:param contant: 写入的json数据内容
		:param filename: 要写入的文件名
		:return: 无返回结果
		"""
        try:
            with open(filename, 'w+') as fw:
                fw.write(
                    simplejson.dumps(contant))  #,sort_keys=True,indent=4))
        except Exception as e:
            my_Common.write_error_log(e)
示例#4
0
    def append_db_json(contant, filename):
        """
		将信息以 json 格式写入数据表文件(追加)
		:param contant: 要写入的 json 格式内容
		:param filename: 要写入的数据表文件名
		:return: 无返回
		"""
        try:
            with open(filename, 'a+') as fa:
                fa.write(simplejson.dumps(contant, sort_keys=True))
                fa.write("\n")
        except Exception as e:
            my_Common.write_error_log(e)
示例#5
0
	def init_database(self):
		#获取数据文件列表
		tables = list(my_conf.DATABASE['tables'].values())
		#数据表存放路径
		database = my_conf.DATABASE['dbpath']

		for _table in tables:
			if not os.path.exists(os.path.join(database, '{0}.db'.format(_table))):
				if hasattr(self, 'init_db_{0}'.format(_table)): #反射
					init_func = getattr(init_DB, 'init_db_{0}'.format(_table))
					init_func(self)
				else:
					my_Common.write_error_log(
						"Table create Error...." + os.path.join(database, '{0}.db'.format(_table)))
			else:
				my_Common.show_message(os.path.join(database, '{0}.db'.format(_table),
													'表已经存在,数据初始化已完成'), "INFORMATION")
示例#6
0
 def update_user(self):
     """
     用户数据更新方法,用户修改信息、用户账户锁定、解锁等操作之后更新数据库文件
     :return:
     """
     try:
         '''
         _password = my_Common.encrypt(self.password)
         self.dict_user[self.username]["password"] = _password
         self.dict_user[self.username]["islocked"] = self.islocked
         self.dict_user[self.username]["name"] = self.name
         self.dict_user[self.username]["mobile"] = self.mobile
         self.dict_user[self.username]["bindcard"] = self.bindcard
         self.dict_user[self.username]["isdel"] = self.isdel
         self.dict_user[self.username]["role"] = self.role
         '''
         # 写入数据库文件
         my_jsonhelper.write_db_simplejson(self.dict_user, self.__database)
         return True
     except Exception as e:
         my_Common.write_error_log(e)
         return False