Skip to content

Commit

Permalink
QgsCredentials: fix sip bindings
Browse files Browse the repository at this point in the history
dbmanager: QgsCredentials is in core (fixes #8345)
  • Loading branch information
jef-n committed Jul 22, 2013
1 parent 5d32231 commit aa7c428
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 deletions.
2 changes: 1 addition & 1 deletion python/core/qgscredentials.sip
Expand Up @@ -8,7 +8,7 @@ class QgsCredentials
//! virtual destructor
virtual ~QgsCredentials();

bool get( QString realm, QString &username, QString &password, QString message = QString::null );
bool get( QString realm, QString &username /In,Out/, QString &password /In,Out/, QString message = QString::null );
void put( QString realm, QString username, QString password );

//! retrieves instance
Expand Down
17 changes: 5 additions & 12 deletions python/plugins/db_manager/db_plugins/postgis/plugin.py
Expand Up @@ -34,6 +34,8 @@

from ..html_elems import HtmlParagraph, HtmlList, HtmlTable

from qgis.core import QgsCredentials


def classFactory():
return PostGisDBPlugin
Expand Down Expand Up @@ -98,19 +100,10 @@ def connect(self, parent=None):
except ConnectionError, e:
err = str(e)

hasCredentialDlg = True
try:
from qgis.gui import QgsCredentials
except ImportError: # no credential dialog
hasCredentialDlg = False

# ask for valid credentials
max_attempts = 3
for i in range(max_attempts):
if hasCredentialDlg:
(ok, username, password) = QgsCredentials.instance().get(uri.connectionInfo(), username, password, err)
else:
(password, ok) = QInputDialog.getText(parent, self.tr("Enter password"), self.tr('Enter password for connection "%s":') % conn_name, QLineEdit.Password)
(ok, username, password) = QgsCredentials.instance().get(uri.connectionInfo(), username, password, err)

if not ok:
return False
Expand All @@ -128,8 +121,8 @@ def connect(self, parent=None):
err = str(e)
continue

if hasCredentialDlg:
QgsCredentials.instance().put(uri.connectionInfo(), username, password)
QgsCredentials.instance().put(uri.connectionInfo(), username, password)

return True

return False
Expand Down

0 comments on commit aa7c428

Please sign in to comment.