diff --git a/src/ui/createUser.py b/src/ui/createUser.py index 6481aa3..a91c5a4 100644 --- a/src/ui/createUser.py +++ b/src/ui/createUser.py @@ -1,13 +1,17 @@ from .sources.Ui_dialog_createUser import Ui_Dialog from PyQt6 import QtCore, QtGui, QtWidgets +from PyQt6.QtGui import QRegularExpressionValidator from src.logic import Database +from src.utils import Icon, Log from src.schemas import User - +import re class CreateUser(QtWidgets.QDialog, Ui_Dialog): def __init__(self, fieldname, data): super(CreateUser, self).__init__() self.setupUi(self) + self.setWindowTitle("Benutzer erstellen") + self.setWindowIcon(Icon("user").icon) # disable buttonbox save self.db = Database() self.buttonBox.button( @@ -25,12 +29,22 @@ class CreateUser(QtWidgets.QDialog, Ui_Dialog): QtWidgets.QDialogButtonBox.StandardButton.Save ).clicked.connect(self.saveUser) self.userid = None - + self.userno.setMaxLength(20) + self.user_mail.setValidator( + QRegularExpressionValidator( + QtCore.QRegularExpression( + r"[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}" + ) + ) + ) + self.userno.textChanged.connect( + lambda: self.validateInputUserno(self.userno.text(), "int") + ) def checkFields(self): if ( - self.username.text() != "" - and self.userno.text() != "" - and self.user_mail.text() != "" + self.username.hasAcceptableInput() + and self.userno.hasAcceptableInput() + and self.user_mail.hasAcceptableInput() ): self.buttonBox.button( QtWidgets.QDialogButtonBox.StandardButton.Save @@ -46,3 +60,19 @@ class CreateUser(QtWidgets.QDialog, Ui_Dialog): usermail = self.user_mail.text() self.db.insertUser(username, userno, usermail) self.userid = userno + + def validateInputUserno(self, value, type): + lastchar = value[-1] if value else "" + # if lastchar is not of the type, remove it + if type == "int": + if not lastchar.isdigit(): + self.userno.setText(value[:-1]) + + def validateInputMail(self, value): + pass + + +def launch(): + app = QtWidgets.QApplication([]) + window = CreateUser("id", "123456") + window.exec() \ No newline at end of file