1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
| user_list = [
{"username": "luenci", "pswd": "123"},
{"username": "lynn", "pswd": "456"},
{"username": "lu", "pswd": "789"},
]
current_dic = {"username": None, "login": False}
def verify(func):
def wrapper(*args, **kwargs):
if current_dic['username'] and current_dic['login']:
res = func(*args, **kwargs)
return res
username = input("请输入用户名:").strip()
pswd = input("请输入密码:").strip()
for user in user_list:
if user['username'] == username and user['pswd'] == pswd:
current_dic['username'] = username
current_dic['login'] = True
res = func(*args, **kwargs)
return res
else:
print('用户名或密码错误')
return wrapper
@verify
def shop():
print('我的购物车')
@verify
def user():
print('我的信息')
@verify
def things():
print('我的商品')
print('登录前的状态:%s'%(current_dic))
user()
print('登录后的状态:%s'%(current_dic))
shop()
things()
|