Skip to content
Permalink
Browse files

[auth] PG uses the new authentication widget

  • Loading branch information
elpaso committed Oct 2, 2017
1 parent f09e5b1 commit 4e4a660a5164498cb4a79b9f630bd173906c8fbf
@@ -40,8 +40,8 @@ QgsPgNewConnection::QgsPgNewConnection( QWidget *parent, const QString &connName
cbxSSLmode->addItem( tr( "verify-ca" ), QgsDataSourceUri::SslVerifyCa );
cbxSSLmode->addItem( tr( "verify-full" ), QgsDataSourceUri::SslVerifyFull );

mAuthConfigSelect = new QgsAuthConfigSelect( this, QStringLiteral( "postgres" ) );
tabAuthentication->insertTab( 1, mAuthConfigSelect, tr( "Configurations" ) );
mAuthSettings->setDataprovider( QStringLiteral( "postgres" ) );
mAuthSettings->showStoreCheckboxes( true );

if ( !connName.isEmpty() )
{
@@ -72,34 +72,30 @@ QgsPgNewConnection::QgsPgNewConnection( QWidget *parent, const QString &connName

if ( settings.value( key + "/saveUsername" ).toString() == QLatin1String( "true" ) )
{
txtUsername->setText( settings.value( key + "/username" ).toString() );
chkStoreUsername->setChecked( true );
mAuthSettings->setUsername( settings.value( key + "/username" ).toString() );
mAuthSettings->setStoreUsernameChecked( true );
}

if ( settings.value( key + "/savePassword" ).toString() == QLatin1String( "true" ) )
{
txtPassword->setText( settings.value( key + "/password" ).toString() );
chkStorePassword->setChecked( true );
mAuthSettings->setPassword( settings.value( key + "/password" ).toString() );
mAuthSettings->setStorePasswordChecked( true );
}

// Old save setting
if ( settings.contains( key + "/save" ) )
{
txtUsername->setText( settings.value( key + "/username" ).toString() );
chkStoreUsername->setChecked( !txtUsername->text().isEmpty() );
mAuthSettings->setUsername( settings.value( key + "/username" ).toString() );
mAuthSettings->setStoreUsernameChecked( ! mAuthSettings->username().isEmpty() );

if ( settings.value( key + "/save" ).toString() == QLatin1String( "true" ) )
txtPassword->setText( settings.value( key + "/password" ).toString() );
mAuthSettings->setPassword( settings.value( key + "/password" ).toString() );

chkStorePassword->setChecked( true );
mAuthSettings->setStorePasswordChecked( true );
}

QString authcfg = settings.value( key + "/authcfg" ).toString();
mAuthConfigSelect->setConfigId( authcfg );
if ( !authcfg.isEmpty() )
{
tabAuthentication->setCurrentIndex( tabAuthentication->indexOf( mAuthConfigSelect ) );
}
mAuthSettings->setConfigId( authcfg );

txtName->setText( connName );
}
@@ -112,9 +108,9 @@ void QgsPgNewConnection::accept()
QgsSettings settings;
QString baseKey = QStringLiteral( "/PostgreSQL/connections/" );
settings.setValue( baseKey + "selected", txtName->text() );
bool hasAuthConfigID = !mAuthConfigSelect->configId().isEmpty();
bool hasAuthConfigID = !mAuthSettings->configId().isEmpty();

if ( !hasAuthConfigID && chkStorePassword->isChecked() &&
if ( !hasAuthConfigID && mAuthSettings->storePasswordIsChecked( ) &&
QMessageBox::question( this,
tr( "Saving passwords" ),
trUtf8( "WARNING: You have opted to save your password. It will be stored in unsecured plain text in your project files and in your home directory (Unix-like OS) or user profile (Windows). If you want to avoid this, press Cancel and either:\n\na) Don't save a password in the connection settings — it will be requested interactively when needed;\nb) Use the Configuration tab to add your credentials in an HTTP Basic Authentication method and store them in an encrypted database." ),
@@ -147,16 +143,16 @@ void QgsPgNewConnection::accept()
settings.setValue( baseKey + "/host", txtHost->text() );
settings.setValue( baseKey + "/port", txtPort->text() );
settings.setValue( baseKey + "/database", txtDatabase->text() );
settings.setValue( baseKey + "/username", chkStoreUsername->isChecked() && !hasAuthConfigID ? txtUsername->text() : QLatin1String( "" ) );
settings.setValue( baseKey + "/password", chkStorePassword->isChecked() && !hasAuthConfigID ? txtPassword->text() : QLatin1String( "" ) );
settings.setValue( baseKey + "/authcfg", mAuthConfigSelect->configId() );
settings.setValue( baseKey + "/username", mAuthSettings->storeUsernameIsChecked( ) && !hasAuthConfigID ? mAuthSettings->username() : QLatin1String( "" ) );
settings.setValue( baseKey + "/password", mAuthSettings->storePasswordIsChecked( ) && !hasAuthConfigID ? mAuthSettings->password() : QLatin1String( "" ) );
settings.setValue( baseKey + "/authcfg", mAuthSettings->configId() );
settings.setValue( baseKey + "/publicOnly", cb_publicSchemaOnly->isChecked() );
settings.setValue( baseKey + "/geometryColumnsOnly", cb_geometryColumnsOnly->isChecked() );
settings.setValue( baseKey + "/dontResolveType", cb_dontResolveType->isChecked() );
settings.setValue( baseKey + "/allowGeometrylessTables", cb_allowGeometrylessTables->isChecked() );
settings.setValue( baseKey + "/sslmode", cbxSSLmode->currentData().toInt() );
settings.setValue( baseKey + "/saveUsername", chkStoreUsername->isChecked() && !hasAuthConfigID ? "true" : "false" );
settings.setValue( baseKey + "/savePassword", chkStorePassword->isChecked() && !hasAuthConfigID ? "true" : "false" );
settings.setValue( baseKey + "/saveUsername", mAuthSettings->storeUsernameIsChecked( ) && !hasAuthConfigID ? "true" : "false" );
settings.setValue( baseKey + "/savePassword", mAuthSettings->storePasswordIsChecked( ) && !hasAuthConfigID ? "true" : "false" );
settings.setValue( baseKey + "/estimatedMetadata", cb_useEstimatedMetadata->isChecked() );

// remove old save setting
@@ -186,16 +182,16 @@ void QgsPgNewConnection::testConnection()
if ( !txtService->text().isEmpty() )
{
uri.setConnection( txtService->text(), txtDatabase->text(),
txtUsername->text(), txtPassword->text(),
mAuthSettings->username(), mAuthSettings->password(),
( QgsDataSourceUri::SslMode ) cbxSSLmode->currentData().toInt(),
mAuthConfigSelect->configId() );
mAuthSettings->configId() );
}
else
{
uri.setConnection( txtHost->text(), txtPort->text(), txtDatabase->text(),
txtUsername->text(), txtPassword->text(),
mAuthSettings->username(), mAuthSettings->password(),
( QgsDataSourceUri::SslMode ) cbxSSLmode->currentData().toInt(),
mAuthConfigSelect->configId() );
mAuthSettings->configId() );
}

QgsPostgresConn *conn = QgsPostgresConn::connectDb( uri.connectionInfo( false ), true );
@@ -19,7 +19,6 @@
#include "ui_qgspgnewconnectionbase.h"
#include "qgsguiutils.h"
#include "qgshelp.h"
#include "qgsauthconfigselect.h"

/** \class QgsPgNewConnection
* \brief Dialog to allow the user to configure and save connection
@@ -40,7 +39,6 @@ class QgsPgNewConnection : public QDialog, private Ui::QgsPgNewConnectionBase
void on_cb_geometryColumnsOnly_clicked();
private:
QString mOriginalConnName; //store initial name to delete entry in case of rename
QgsAuthConfigSelect *mAuthConfigSelect = nullptr;
void showHelp();

};
@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>447</width>
<height>599</height>
<height>554</height>
</rect>
</property>
<property name="sizePolicy">
@@ -25,15 +25,11 @@
<property name="modal">
<bool>true</bool>
</property>
<layout class="QGridLayout" name="gridLayout3">
<item row="2" column="0">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Help|QDialogButtonBox::Ok</set>
</property>
</widget>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QgsMessageBar" name="bar" native="true"/>
</item>
<item row="1" column="0">
<item>
<widget class="QGroupBox" name="GroupBox1">
<property name="title">
<string>Connection Information</string>
@@ -44,7 +40,7 @@
<item row="0" column="0">
<widget class="QLabel" name="TextLabel1_2">
<property name="text">
<string>Name</string>
<string>&amp;Name</string>
</property>
<property name="buddy">
<cstring>txtName</cstring>
@@ -74,7 +70,7 @@
<item row="2" column="0">
<widget class="QLabel" name="TextLabel1">
<property name="text">
<string>Host</string>
<string>Hos&amp;t</string>
</property>
<property name="buddy">
<cstring>txtHost</cstring>
@@ -104,7 +100,7 @@
<item row="4" column="0">
<widget class="QLabel" name="TextLabel2">
<property name="text">
<string>Database</string>
<string>&amp;Database</string>
</property>
<property name="buddy">
<cstring>txtDatabase</cstring>
@@ -117,7 +113,7 @@
<item row="5" column="0">
<widget class="QLabel" name="TextLabel3_3">
<property name="text">
<string>SSL mode</string>
<string>SSL &amp;mode</string>
</property>
<property name="buddy">
<cstring>cbxSSLmode</cstring>
@@ -130,79 +126,15 @@
</layout>
</item>
<item>
<widget class="QTabWidget" name="tabAuthentication">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
<widget class="QGroupBox" name="mAuthGroupBox">
<property name="title">
<string>Authentication</string>
</property>
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="tabBasic">
<attribute name="title">
<string>Authentication</string>
</attribute>
<layout class="QGridLayout" name="gridLayout">
<property name="leftMargin">
<number>5</number>
</property>
<property name="topMargin">
<number>5</number>
</property>
<property name="rightMargin">
<number>5</number>
</property>
<property name="bottomMargin">
<number>5</number>
</property>
<item row="0" column="0">
<widget class="QLabel" name="TextLabel3">
<property name="text">
<string>Username</string>
</property>
<property name="buddy">
<cstring>txtUsername</cstring>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QgsPasswordLineEdit" name="txtPassword">
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QCheckBox" name="chkStoreUsername">
<property name="text">
<string>Save</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="TextLabel3_2">
<property name="text">
<string>Password</string>
</property>
<property name="buddy">
<cstring>txtPassword</cstring>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="txtUsername"/>
</item>
<item row="1" column="2">
<widget class="QCheckBox" name="chkStorePassword">
<property name="text">
<string>Save</string>
</property>
</widget>
</item>
</layout>
</widget>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QgsAuthSettingsWidget" name="mAuthSettings" native="true"/>
</item>
</layout>
</widget>
</item>
<item>
@@ -292,44 +224,30 @@
</layout>
</widget>
</item>
<item row="0" column="0">
<widget class="QgsMessageBar" name="bar" native="true"/>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Help|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<layoutdefault spacing="6" margin="11"/>
<customwidgets>
<customwidget>
<class>QgsPasswordLineEdit</class>
<extends>QLineEdit</extends>
<header>qgspasswordlineedit.h</header>
</customwidget>
<customwidget>
<class>QgsMessageBar</class>
<extends>QWidget</extends>
<header>qgsmessagebar.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>QgsAuthSettingsWidget</class>
<extends>QWidget</extends>
<header>auth/qgsauthsettingswidget.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>txtName</tabstop>
<tabstop>txtService</tabstop>
<tabstop>txtHost</tabstop>
<tabstop>txtPort</tabstop>
<tabstop>txtDatabase</tabstop>
<tabstop>cbxSSLmode</tabstop>
<tabstop>tabAuthentication</tabstop>
<tabstop>txtUsername</tabstop>
<tabstop>chkStoreUsername</tabstop>
<tabstop>txtPassword</tabstop>
<tabstop>chkStorePassword</tabstop>
<tabstop>btnConnect</tabstop>
<tabstop>cb_geometryColumnsOnly</tabstop>
<tabstop>cb_dontResolveType</tabstop>
<tabstop>cb_publicSchemaOnly</tabstop>
<tabstop>cb_allowGeometrylessTables</tabstop>
<tabstop>cb_useEstimatedMetadata</tabstop>
</tabstops>
<resources/>
<connections>
<connection>

0 comments on commit 4e4a660

Please sign in to comment.
You can’t perform that action at this time.