def is_unlock(CONFIGFILE, DB, LOCKFILE, LOCK_DURATION): lock_time = 0 try: msg, flag = utils.ReadConfigFile(CONFIGFILE, DB, LOCKFILE) if flag: cxt = utils.ReadFile(msg) lock_time = float(cxt) except Exception as e: print(e) logging.warning(e) return time.time() - lock_time > LOCK_DURATION
def is_unlock(): lock_time = 0 LOCK_FILE = utils.ReadConfigFile('conf.ini', 'LOG', 'LOGFILE') try: cxt = utils.ReadFile(LOCK_FILE) lock_time = float(cxt) except Exception as e: pass is_unlock = time.time() - lock_time > LOCK_INTERVAL if not is_unlock: utils.warn_info('锁定用户尝试登录') return is_unlock
def user_list(CONFIGFILE2): list_sql = ''' select * from {};'''.format(USERINFO) users_find, ok = DB.Select(CONFIGFILE2, list_sql) if ok: 'users信息转为字典形式。' userinfo = [] keys = ['uid', 'name', 'age', 'tel', 'address'] for x in users_find: userinfo.append(dict(zip(keys, list(x)))) page_print(userinfo, PAGE_SIZE) # 分页显示 text = input('输入yes可以保存数据到xls文件:') if text == 'yes': filename, ok = utils.ReadConfigFile(CONFIGFILE2, 'DB', 'DBFILE') if ok: utils.WriteExcel(filename, userinfo) print('\033[0;33m导出到xls成功!\033[0m') else: print('数据查询error!')
def lock_user(CONFIGFILE, DB, LOCKFILE): msg, flag = utils.ReadConfigFile(CONFIGFILE, DB, LOCKFILE) # print(msg) if flag: utils.WriteFile(msg, str(time.time()))
def admin_main(): login_count = 0 while True: TOKEN = input('请输入token值:') stat = useradmin.Github_auth(TOKEN) #stat = int(input('输入200:')) if stat == 200: if not useradmin.is_unlock(CONFIGFILE, DB1, LOCKFILE, LOCK_DURATION): print('用户锁定!') else: print(LOGIN_SUCCESS) ''' 此部分可以增加创建数据库和表的操作(省略)... DB.Create_database(DATABASE) DB.Create_table(DATABASE, CREATE_TABLE) ''' while True: text = input('请输入对应操作数字(1-6):') if text.isdigit(): if int(text) == 1: useradmin.user_add(CONFIGFILE2) elif int(text) == 2: useradmin.user_delete(CONFIGFILE2) elif int(text) == 3: useradmin.user_update(CONFIGFILE2) elif int(text) == 4: useradmin.user_query(CONFIGFILE2, *TABLE_FORMAT) elif int(text) == 5: '此部分实现导出到csv文件或xls部分' \ '1.实现从数据库读出所有数据' \ '2.将数据存到xls' users, ok = useradmin.user_list(CONFIGFILE2) # print(users) if ok: # input() 'users信息转为字典形式。' userinfo = [] keys = ['uid', 'name', 'age', 'tel', 'address'] for x in users: userinfo.append(dict(zip(keys, list(x)))) useradmin.user_page(userinfo, PAGE_SIZE, *TABLE_FORMAT) # 分页显示 text = input('输入yes可以保存数据到xls文件:') if text == 'yes': filename, ok = utils.ReadConfigFile( CONFIGFILE, DB1, DBFILE) if ok: utils.WriteExcel(filename, userinfo) print('导出到xls成功!') else: print('数据查询error!') elif int(text) == 6: print('退出系统.....') break else: print('输入有误') else: login_count += 1 if login_count == MAX_LOGINTIMES: print('\033[0;31m认证失败3次,用户锁定!\033[0m') # logging.warning("失败3次,用户锁定!") useradmin.lock_user(CONFIGFILE, DB1, LOCKFILE) break else: print('\033[0;31m认证失败,请重新认证!\033[0m')
def lock_admin(): lock_init_time = time.time() LOCK_FILE = utils.ReadConfigFile('conf.ini', 'LOG', 'LOGFILE') utils.WriteFile(LOCK_FILE,lock_init_time)