username = 'root'
password = '123456'
# 用於驗證用戶信息的裝飾器
def auth(type):
def deco(func):
def wrapper(*args,**kwargs):
name = input("請輸入用戶名:").strip()
pwd = input("請輸入密碼:").strip()
if name == username and pwd == password:
print("\033[32;1m登錄成功!\033[0m")
return func(*args,**kwargs)
else:
print("\033[35;1m用戶名或者密碼錯誤!\033[0m")
return wrapper;
return deco
# 登錄界面
@auth(type="local")
def login():
print("Welcome to Login")
return "sucess"
# 主界面
@auth(type="ldap")
def home():
print("Welcome to home")
# 評論界面
@auth(type="tourist")
def comment():
print("Welcome to comment")
login()