Ok without going into server authentication and everything, I think I have a simple solution to generate the form and allow the user to hit it.
I was looking through the code, and it looks pretty incomplete (based off my quick scanning of the Qt info). The reason this code doesn't find anything is because the children (
loginButton) aren't added to the parent element (
So, without going into laying things out properly, or creating a friendly user interface form, I put together a little snippet that will create a dialog, add children, and on login button click, find the values in the
from PyQt4.QtCore import *
from PyQt4.QtGui import *
#setting global strings
userName = ""
userPass = ""
#this function runs when the button is clicked and finds the values
#get the list of children of the dialog
children = myDialog.findChildren(QLineEdit)
#iterate through list and find out user name and password widgets
for child in children:
if child.Name == "PassField":
userPass = child.text()
elif child.Name == "NameField":
userName = child.text()
print "UN: " + userName
print "PW:" + userPass
#create the global dialog
myDialog = QDialog()
#create a line edit - need to assign a parent so the QLineEdit knows where to go
passField = QLineEdit(myDialog)
passField.Name = "PassField"
#same thing here
nameField = QLineEdit(myDialog)
nameField.Name = "NameField"
#button to login needs a handler when it is clicked
#create the button, assign to the parent, add the click handler
loginButton = QPushButton("Click Me", myDialog)
That is pretty rough and dirty, and there are numerous ways to make it a lot better. However, I have never played with
QT before and didn't want to start a whole learning session for this answer.
buttonHandler function, you can add a check to whatever you want to authenticate the user name and password combination. This sample only shows controls added to a dialog and how to access them there. From what I read in
QT, there are options to layout the form better. One thing to remember, it seems like a lot of these add widgets to collections over and over again. So, unless you declare a
QLineEditin the global namespace, you'll need to iterate through the collections looking for a name.
Other things that will help:
For the password
QLineEdit, it looks like there is an option that'll allow you to hide text that is entered in there. I didn't experiment with it, but it is another level of security.
buttonHandler function, once authenticated, you should be able to fire off some other function or script for your user. In .Net, I use two windows and only show the 2nd one once my user has been authenticated so you may be able to do that. I also store hashes of passwords and compare the hash generated by the user in the login form against the one stored locally. It isn't the most secure, but my users aren't the smartest people and might know how to turn on a computer without help.
Python would be a little trickier since you could invoke the script separately, but you may be able to modify it (like
__name__ checking) or somehow provide a better secure way to let people access sensitive items.
It also depends on where you are running the script. I am not sure if you are able to set up a QGIS project to run a script upon opening. If so, this would be decent there so you can either continue to load the project or exit out of it depending on what happens with the user.
A lot of this will depend on your user base. If they are smart enough to outwit your login script and open things independently, or if they turn away at the first sign of resistance, will greatly influence what you're setting up.