user_info = {}
def check_login(func):
def inner(*args, **kwargs):
if user_info.get("in_login", None):
ret = func(*args, **kwargs)
return ret
else:
print("请登陆")
def check_admin(func):
def inner(*args, **kwargs):
if user_info.get("user_type", None) == 2: #获得用户类型
ret = func(*args, **kwargs)
return ret
else:
print("没有权限")
return inner
@check_login
@check_admin
def index():
print("index")
@check_login
def home():
print("home")
def login():
username = input("请输入用户名:")
if username == "admin":
user_info["is_login"] = True
user_info["user_type"] = 2
else:
user_info["is_login"] = True
user_info["user_type"] = 1
def main():
while True:
inp = input("1:请登陆;2:查看信息;3:超级管理员 \n ")
if inp == "1":
login()
elif inp == "2":
home()
elif inp == "3":
index()
main()