深入理解python之self(谈谈对python的认识)
299
2022-08-20
Python添加用户判断
def saveRegistData(self):
"""用户注册"""
print("保存数据")
saveDataPath=os.path.join(os.getcwd(),"config","accout.json")
accountType=self.accoutTypeComboBox.currentText() # 账户类型
account=self.account_le.text().strip() # 账户名称
accountName=self.accountName_le.text() # 账户姓名
accountPhone=self.accountPhone_le.text() # 账户联系方式
accountPwd=self.password_le.text() # 账户密码
accountConfirePwd=self.confirm_pwd_le.text() # 账户确认密码
# 获取注册用户参数限制条件
configPath = os.path.join(os.getcwd(), "config", "config.json")
# 是否包含中文
isContainChinese=self.isContainChinese(accountName)
# 获取配置文件配置限制参数
try:
dboperate=DBOperate.DBOperate()
querySql="SELECT * FROM config_paras"
paras=dboperate.QueryAsDict(querySql)[0]
except Exception as ex:
print(f"加载配置文件参数出错\n{ex}")
else:
accountMinChar = int(paras.get("accountMinChar", 5))
accountNameContainChineseMinChar = int(paras.get("accountNameContainChineseMinChar", 6))
accountNameNotContainChineseMinChar = int(paras.get("accountNameNotContainChineseMinChar", 5))
accountPwdMinChar = int(paras.get("accountPwdMinChar", 6))
dboperate.CloseDB()
QMessageBox().warning(None, "警告", "账户名称小于5个字符,请重新输入!", QMessageBox.Ok)
return
QMessageBox().warning(None, "警告", "姓名不能少于2个汉字!", QMessageBox.Ok)
return
QMessageBox().warning(None, "警告", "姓名不能少于5个英文字母!", QMessageBox.Ok)
return
QMessageBox().warning(None, "警告", "密码必须大于6位!", QMessageBox.Ok)
return
elif accountPwd != accountConfirePwd:
QMessageBox().warning(None, "警告", "两次输入密码不一致,请重新输入!",QMessageBox.Ok)
self.password_le.setText("")
self.confirm_pwd_le.setText("")
return
registerTime=datetime.datetime.now().strftime("%Y%m%d%H%M%S")
accoutData={
"accountType":accountType,
"account":account,
"accountName":accountName,
"accountPhone":accountPhone,
"accountPwd":self.generateMD5(accountPwd),
"registerTime":registerTime,
"lastLoginTime":"",
# 0:管理人员 1:普通人员
"isAdmin":"0" if accountType == "管理人员" else "1"
}
data=[]
# 所有注册用户列表
allAccoutList=[]
try:
if not os.path.exists(saveDataPath):
data.append(accoutData)
with open(saveDataPath ,"w+" , encoding="utf8") as fw:
json.dump(data,fw,ensure_ascii=False,indent=2)
time.sleep(1)
else:
with open(saveDataPath,"r",encoding="utf8") as fo:
loadData=json.load(fo)
for item in loadData:
allAccoutList.append(item.get("account"))
if account in allAccoutList:
QMessageBox.warning(None, "警告", "您输入的账户名称已经被占用,请重新输入", QMessageBox.Ok)
return
else:
loadData.append(accoutData)
with open(saveDataPath,"w+",encoding="utf8") as fw:
json.dump(loadData,fw,ensure_ascii=False,indent=2)
except:
QMessageBox.warning(None, "错误", "注册失败",QMessageBox.Ok)
else:
result=QMessageBox().information(None , "信息", "注册成功", QMessageBox.Ok)
if result== QMessageBox.Ok:
self.close()
来源: http://jianshu.com/u/28161b7c9995/
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~