1

I've got a stored project that, when opened is connecting to my PostgreSQL DB, and is loading several layers. All good.

I'm using a script that is called from Pre-execution (Processing/Options and configuration) that is using the QgsCredentialDialog to distinguish between admin and regular user.

def LoginCredentials():
  uri = QgsDataSourceURI()
  uri.setConnection("localhost", "5432", "Blah", None, None)
  connInfo = uri.connectionInfo()

  (success, user, passwd) = QgsCredentialDialog.instance().get(connInfo, None, Nones)
  if success:
    uri.setPassword(passwd)
    uri.setUsername(user)
    iface.messageBar().pushMessage("Welcome!", "Welcome "+str(user), level=QgsMessageBar.INFO, duration=3)

def run_script(iface):
  LoginCredentials()

Issues:

  • one of my 7 layers is able to be loaded before the credentials dialog pops up.
  • the credentials dialog is printing a string just above the username/password textboxes with dbname, host, port, user, password and sslmode, all filled out! (I'm guessing the values are read from the .qgs project file, but I rather it didn't show it)
  • if I keep hitting the Cancel button I can see that the layers are loaded one by one until everything is loaded and the credentials dialog just disappear.

I'm very new to Q-GIS (4 days), so it might be that I've overlooked something very essential.

Cheers!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.