码迷,mamicode.com
首页 > 其他好文 > 详细

验证功能

时间:2019-06-04 14:53:54      阅读:104      评论:0      收藏:0      [点我收藏+]

标签:用户   str   inpu   参数   strip()   判断   passwd   家目录   后端   

#!/user/bin/python
# -*- coding:utf-8 -*-
#1、先定义后端函数功能2、定义装饰器基本实现3、加上参数4、加上返回值5、
user_list = [ #这是用户信息
{"name":"alex","passwd":"123"},
{"name":"linhaifeng","passwd":"123"},
{"name":"wupeiqi","passwd":"123"},
{"name":"yuanhao","passwd":"123"},
]
current_dic = {"username":None,"login":False} #这是记录当前用户的状态
def auth_func(func):
def wrapper(*args,**kwargs):
if current_dic["username"] and current_dic["login"]: #这里定义默认是TRUE
res = func(*args,**kwargs)
return res
username = input("用户名:").strip() #这下面的一大片默认就是else了来进行判断
passwd = input("密码:").strip()
for user_dic in user_list:
if username == user_dic["name"] and passwd == user_dic["passwd"]:
current_dic["username"] = username
current_dic["login"] = True
res = func(*args,**kwargs)
return res
else:
print("用户名或密码错误")
return wrapper
#1、定义京东首页
@auth_func
def index():
print("欢迎来到京东主页")
#2、定义家目录
@auth_func
def home(name):
print("欢迎回家%s" %name)
#3、定义购物车功能
@auth_func
def shopping_car(name):
print("%s的购物车里有[%s,%s,%s]" %(name,"奶茶","妹妹","娃娃"))
#5、
print("before",current_dic)
index()
print("after",current_dic)
home("产品经理")
shopping_car("产品经理")

验证功能

标签:用户   str   inpu   参数   strip()   判断   passwd   家目录   后端   

原文地址:https://www.cnblogs.com/zhang-da/p/10973395.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!