user,passwd = "alex","aaaa"
def auth(auth_type):
print("auth func:",auth_type)
def outer_wrapper(func):
def wrapper(*args,**kwargs):
print("wrapper func args:",*args,**kwargs)
if auth_type == "local":
username = input("username:").strip()
password = input("password:").strip()
if user == username and passwd==password:
print("用户名输入正确")
res = func(*args,**kwargs)
print("认证后")
return res
else:
exit("认证错误")
elif auth_type=="ldap":
print("网络认证")
return wrapper
return outer_wrapper
def index():
print("wellcome to index")
@auth(auth_type="local") #home = auth(home)
def home():
print("wellcome to home")
return "from home"
@auth(auth_type="ldap")
def bbs():
print("wellcome to bbs")
home()
bbs()