er)
with open("user.txt", "r") as old_user:
lines = old_user.readlines() # 一次性读取整个文件,感觉这方方式不好1
with open("user.txt", "w") as new_user:
for line in lines: # 将上面读取到的文集一行一行的循环出来
if line.startswith(del_user): # 检查数据库里面是否有我们输入的用户(以输入的用户名开头)
flag = "success"
continue
new_user.write(line)
if flag == "success": # 提示成功
print("删除成功")
else:
print("没有这个用户。。。") # 如果输入的为空格或一些没有的用户,提示没有这个用户
continue
elif user_input == "4":
ret = verifi_passwd() # 得到函数返回值
lines = ret[0] # 获取到返回的整个文件内容
username = ret[1] # 获取到返回的需要修改密码的用户
new_password = input("请输入用户的新密码:")
if len(new_password) < 5: # 判断输入的密码长度是否大于或等于5位数
error_prompt = input("你输入的密码长度小于5位数,由于你是管理员,输入Y继续:").strip("") # 去掉输入的空格
if error_prompt not in ("y", "Y"): # 如果输入的值不为y或Y,就直接退出
print("退出。。。")
continue
user_info_func(username, new_password, 1, lines) # 传入实参到函数,1在列表中的位置代表用户的新密码
elif user_input == "5": # 下面这部分和上面的部分基本相似,其实可以写一个函数用来调用的
ret = verifi_passwd()
lines = ret[0]
username = ret[1] # 获取到输入用户的所有信息
new_power = input("输入Y提升用户权限:")
if new_power not in ("y", "Y"):
print("输入错误。。。")
break
user_info_func(username, "1", 3, lines) # 传入实参:用户名、权限(1代表管理员)、位置、循环的文件内容
elif user_input == "6":
print("返回上一级!!!")
main()
else:
print("输入有误")
@user_login # 调用装饰器
def see(): # 4查询当前用户的基本信息
if USER_LIST[3] == "1": # 数据库里面定义了1代表管理员用户,2代表普通用户
user_level = "管理员用户"
else:
user_level = "普通用户"
user_see = """
----------------------------------------
用户名: 【%s】
密 码: 【%s】
邮 箱: 【%s】
用户等级:【%s】
----------------------------------------
""" % (USER_LIST[0], USER_LIST[1], USER_LIST[2], user_level) # 一个简单的格式化输出
print(user_see)
def error_password():
counter = 3
while True:
counter -= 1
if counter == 0:
print("你输入错误的次数太多,程序自动返回。。。")
main()
else:
print("两次输入的密码不相同。。。")
continue
@user_login # 调用装饰器
def alter(): # 3修改密码
print("当前用户为:【%s】" % USER_LIST[0])
while True:
old_user_password = input("请输入当前用户的旧密码密码:")
if old_user_password == USER_LIST[1]:
flag = True
count = 3
while flag:
count -= 1
new_user_password = input("请输入当前用户的\033[1;31m新密码\033[0m:") # 给新密码字体加颜色
new_user_password1 = input("再次输入当前用户的\033[1;31m新密码\033[0m:")
if len(new_user_password) >= 5:
flag = False
elif count == 0:
print("多次不合法,程序自动返回。。。")
main()
else:
print("输入不合法,请输入大于5位数的密码")
if new_user_password == new_user_password1: # 判断两次输入的密码是否相等
with open("user.txt", "r") as user_info: # 以读的方式打开这个文件
old_user_info = "|".join(USER_LIST) # 获取以前的旧信息
for line in user_info: # 将获取到的每行循环输出
if USER_LIST[0] in line: # 找到当前登录的用户的这个用户名
USER_LIST[1] = new_user_password1 # 如果找到了,就把新密码重新加入到我们全局的用户的信息列表中
new_user_info = "|".join(USER_LIST) # 将用户信息表中的内容用join方法转换为用户数据库里面的格式(新用户信息)
# print(new_user_info)
# print(old_user_info)
break # 跳出当前
with open("user.txt", "r") as old_user:
lines = old_user.readlines() # 一次性读取整个文件,感觉这方方式不好
with open("user.txt", "w") as new_us |