How can I create a form so the user has to be authenticated to access a project?

المشرف العام

Administrator
طاقم الإدارة
I have a login form in QGIS and when it is loaded, python gives me an error for, apparently, not recognizing the findchild part. This is due to the fact that the form isn't loaded before the script is executed, so there are no "childs". How can I connect the form so that the user has to be authenticated first in order to access the project?

import psycopg2import hashlibfrom PyQt4.QtCore import *from PyQt4.QtGui import *nameField = NonemyDialog = NonepassField = Nonedef formOpen(dialog,layerid,featureid):global myDialogmyDialog = dialogglobal nameFieldnameField = dialog.findChild(QLineEdit,"username")global passFieldpassField = dialog.findChild(QLineEdit,"password")loginButton = dialog.findChild(QPushButton,"btnLogin")loginButton.clicked.connect(authenticate)def authenticate():conn_string = "host='CORFOU' dbname='addisababa' user='addisababa' password=1"conn = psycopg2.connect(conn_string)username = nameField.getText()hashpassword = hashlib.md5(passField.getText())cursor = conn.cursor()cursor.execute('SELECT * FROM users WHERE username=%s AND password=%s', (username, hashpassword))if cursor.rowcount == 1:myDialog.accept()else:msgBox = QMessageBox()msgBox.setText("Wrong username or password")msgBox.exec_()

أكثر...
 
أعلى