zoukankan      html  css  js  c++  java
  • 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"加载配置文件参数出错
    {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()
    
            if len(account.encode())<accountMinChar:
                QMessageBox().warning(None, "警告", "账户名称小于5个字符,请重新输入!", QMessageBox.Ok)
                return
            elif len(accountName.encode())<accountNameContainChineseMinChar and isContainChinese: # 中文
                QMessageBox().warning(None, "警告", "姓名不能少于2个汉字!", QMessageBox.Ok)
                return
            elif len(accountName.encode())<accountNameNotContainChineseMinChar and not isContainChinese: # 英文
                QMessageBox().warning(None, "警告", "姓名不能少于5个英文字母!", QMessageBox.Ok)
                return
            elif len(accountPwd)<accountPwdMinChar:
                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()
    
  • 相关阅读:
    第一百一十一节,JavaScript,BOM浏览器对象模型
    第一百一十节,JavaScript匿名函数和闭包
    第一百零九节,JavaScript面向对象与原型
    第一百零八节,JavaScript,内置对象,Global对象字符串编码解码,Math对象数学公式
    第一百零七节,JavaScript基本包装类型,数据类型的方法
    第一百零六节,JavaScript变量作用域及内存
    第一百零五节,JavaScript正则表达式
    第一百零四节,JavaScript时间与日期
    经典的图片上传并绘制缩略图的类的代码
    ecshop判断搜索引擎是否为蜘蛛
  • 原文地址:https://www.cnblogs.com/surpassme/p/12782640.html
Copyright © 2011-2022 走看看