首页 > 代码库 > python作业之用户管理程序_未完成

python作业之用户管理程序_未完成

admin|admin123.|28812341026|admin@126.com|1
root|admin123.|134456634887|root@126.com|1
bob|admin123.|1301231576356|bob@126.com|0
Cevin|admin123.|45566778990|Cevin@126.com|0



#Auther Bob
#--*--conding:utf-8 --*--
#1、普通用户
# 登陆,注册,修改密码,查看本用户信息

#2、管理员用户
# 登陆,注册,修改密码,查看本用户信息
# 删除普通虚拟机,添加普通用户信息
# 查看所有的普通用户,按照指定的关键字搜索用户信息
# 提高普通用户的权限

#3、要求
# 权限用装饰器
#用户信息,用文件存储

#4、文件内容
# 用户名|密码|手机号码|邮箱地址|用户类型

login_dict = {"is_login":None,"login_type":None}
login_list = []
user_list = []
tmpe_user_list = []
with open("db","r",encoding="utf-8") as f:
for line in f:
tmpe_user_list = line.strip().split("|")
user_list.append(tmpe_user_list[0])
tmpe_user_list = []


def manage_user(func):
def inner(*args,**kwargs):
if login_dict["is_login"] == "1" and login_dict["login_type"] == "1":
ret = func(*args,**kwargs)
return ret
elif login_dict["is_login"] == None:
print("请先登陆")
login()
elif login_dict["is_login"] == 1 and login_dict["login_type"] == None:
print("请使用管理员账号登陆")
else:
pass
return inner


def common_user(func):
def inner(*args,**kwargs):
if login_dict["is_login"] == None:
print("请先登陆")
login()
elif login_dict["is_login"] == 1:
ret = func()
return ret
return inner


def login():
user_name = input("请输入用户名:")
user_passwd = input("请输入%s的密码:" %(user_name))
if user_name in user_list:
with open("db","r",encoding="utf-8") as f:
for line in f:
login_list = line.strip().split("|")
if user_name == login_list[0] and user_passwd == login_list[1]:
print("欢迎%(name)登陆管理平台" %{"name":user_name})
if login_list[4] == 1:
login_dict["is_login"] = 1
login_dict["login_type"] = 1
else:
login_dict["is_login"] = 1
login_dict["login_type"] = None
break
else:
print("用户名或者密码错误,请重新登陆:")
login_dict["is_login"] = None
login_dict["login_type"] = None
login()
else:
print("用户名或者密码错误,请重新登陆")
login_dict["is_login"] = None
login_dict["login_type"] = None
login()



def regi():
login_name = input("请输入需要注册的用户名:")
if login_name in user_list:
print("该用户名已经存在,请重新输入注册的用户名")
regi()
else:
login_paswd = input("请输入%s的邮箱密码" %(login_name))
login_number = input("请输入%s的电话号码" %(login_name))
login_email = input("请输入%s的邮箱地址" %(login_name))
while True:
if login_dict["is_login"] == 1 and login_dict["login_type"] == 1:
option = input("请输入%s的用户类型\n1:管理员\n2:普通用户\n" %(login_name))
if option == "1":
login_type = 1
break
elif option == "2":
login_type = 0
break
else:
print("无效的输入,请重新输入")
elif login_dict["is_login"] == 1 and login_dict["login_type"] == None:
option = input("请输入%s的用户类型\n1:普通用户\n" % (login_name))
if option == "1":
login_type = 0
break
else:
print("无效的输入,请重新输入")
else:
pass
with open("db","a",encoding="utf-8") as f:
user_info = "\n" + login_name + "|" + login_paswd + "|" + login_number + "|" + login_email + "|" + login_type
f.write(user_info)







def change_password():
pass


def view_user():
pass


def add_user():
pass


def del_user():
pass


def search():
pass

python作业之用户管理程序_未完成