import time
user,passwd = 'lian','abc123'
def auth(auth_type):
def outer_wrapper(func):
def wrapper(*args,**kwargs):
if auth_type == "local":
username = input("Username:").strip()
password = input("Password:").strip()
if user == username and passwd == password:
print(' 33[32;1mUser has passed authentication 33[0m')
res = func(*args,**kwargs)
print('=============')
return res
else:
exit(" 33[32;1mInvalid username or password 33[0m")
elif auth_type == "ldap":
print('ldap++++++')
return wrapper
return outer_wrapper
def index():
print('welcome to index page')
@auth(auth_type="local")#home = wraper()
def home():
print('welcome to home page')
return "welcome"
@auth(auth_type="ldap")#
def bbs():
print("welcome to bbs page")
index()
print(home())
bbs()
welcome to index page
Username:lian
Password:abc123
User has passed authentication
welcome to home page
=============
welcome
ldap++++++