def dump_account(account_data): db_path=db_handle.handle(setting.DATABASE) account_file='%s/%s.json'%(db_path,account_data['id']) with open(account_file,'w',encoding='utf-8') as f: json.dump(account_data,f) print('dump success')
def access_auth(account, password, log_obj): db_path = db_handle.handle(setting.DATABASE) print(db_path) account_file = '%s/%s.json' % (db_path, account) if os.path.isfile(account_file): account_data = accounts.load_account(account) print(account_data) if account_data['password'] == password: expire_time = time.mktime( time.strptime(account_data['expire_date'], '%Y-%m-%d')) if time.time() > expire_time: log_obj.error('Account %s had expired,pls contach the bank' % (account)) print('Account %s had expired,pls contach the bank' % (account)) else: log_obj.info('Account %s logging success' % (account)) return account_data else: log_obj.error('Account or Password does not correct!') print('Account or Password does not correct!') else: log_obj.error('Account %s does not exist' % (account)) print('Account %s does not exist' % (account))
def load_account(account_id): """ 将用户信息从文件中load出来 :return: 用户信息的字典 """ #返回路径 ATM/db/accounts db_path = db_handle.handle(settings.DATABASE) account_file = "%s/%s.json" % (db_path, account_id) with open(account_file, "r", encoding="utf-8") as f: account_data = json.load(f) return account_data
def dump_account(account_data): """ 将已更改的用户信息更新到用户文件 :param account_data: 每操作后用户的信息 :return: """ db_path = db_handle.handle(settings.DATABASE) account_file = "%s/%s.json" % (db_path, account_data["id"]) with open(account_file, "w+", encoding="utf-8") as f: json.dump(account_data, f) print("dump success")
def access_auth(account_name, password): db_path = db_handle.handle(setting.DATABASE) account_file = "%s/%s.json" % (db_path, account_name) if os.path.isfile(account_file): account_data = account.load_account(account_name) if password == account_data['password']: expire_time = time.mktime( time.strptime(account_data["expire_date"], "%Y-%m-%d")) if time.time() > expire_time: print('account %s has expired,pls contact the bank' % account_name) exit('exit for expired') else: print('login success') print(account_data) return account_data else: print('password not correct') print('account not exist')
def access_auth(account, password, log_obj): """ 下面的access_login调用access_auth方法,用于登陆 :param acount: 用户名 :param password: 密码 :return:如果未超期,返回字典,超期则打印相应提示 """ db_path = db_handle.handle( settings.DATABASE) #调用db_handle下的handle方法,返回路径/db/accounts print(db_path) account_file = "%s/%s.json" % (db_path, account) #用户文件 print(account_file) if os.path.isfile(account_file): #如果用户文件存在(即用户存在) with open(account_file, "r", encoding="utf-8") as f: #打开文件 account_data = json.load(f) #file_data为字典形式 print(account_data) if account_data["password"] == password: expire_time = time.mktime( time.strptime(account_data["expire_date"], "%Y-%m-%d")) #print(expire_time) #print(time.strptime(account_data["expire_date"],"%Y-%m-%d")) if time.time() > expire_time: #如果信用卡已超期 log_obj.error( "Account [%s] had expired,Please contract the bank" % account) print("Account %s had expired,Please contract the bank" % account) else: #信用卡未超期,返回用户数据的字典 #print("return") log_obj.info("Account [%s] logging success" % account) return account_data else: log_obj.error("Account or Passworddoes not correct!") print("Account or Passworddoes not correct!") else: #用户不存在 log_obj.error("Account [%s] does not exist!" % account) print("Account [%s] does not exist!" % account)
def load_account(account_id): db_path=db_handle.handle(setting.DATABASE) account_file='%s/%s.json'%(db_path,account_id) with open(account_file,'r',encoding='utf-8') as f: account_data=json.load(f) return account_data