Создание декоратора kivymd
Подскажите как создать декоратор, который будет проверять уникальность логина, чтобы в бдшке не было одинаковых логинов. Так же декоратор должен проверять пароль (он не должен быть пустым и просто пробелами)
main.py
from kivy.lang import Builder
import mysql.connector
class MainApp(MDApp):
def build(self):
self.theme_cls.theme_style = "Dark"
self.theme_cls.primary_palette = "BlueGray"
return Builder.load_file("login.kv")
mydb = mysql.connector.connect(
host="localhost",
user="root",
passwd="test123",
database="first_db"
)
def trydecotate(self):
logpass=[self.root.ids.login.text,self.root.ids.password]
def wrapper(abob):
for i in logpass:
if len(logpass[i])==0:
return
return wrapper()
MainApp().run()
login.kv
Screen:
MDCard:
size_hint:None,None
size:300,400
pos_hint:{"center_x":0.5,"center_y":0.5}
elevation:10
padding:25
spacing:25
orientation:'vertical'
MDTextFieldRound:
id:login
hint_text:"username"
icon_right:"account"
post_hint:{"center_x": 0.5,"center_y":0.5}
font_size:18
size_hint:1,None
width:200
MDTextFieldRound:
id:password
hint_text:"password"
icon_right:"eye-off"
post_hint:{"center_x": 0.5,"center_y":0.5}
font_size:18
size_hint:1,None
width:200
password:True
MDRoundFlatButton:
text:"Login"
font_size:12
pos_hint:{"center_x":0.5}
on_release:
MDRoundFlatButton:
text:"Register"
font_size:12
pos_hint:{"center_x":0.5}
Widget:
size_hint_y:None
height:10