Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5270 from boundlessgeo/auth_widget2
[auth][needs-docs] Authentication widget
- Loading branch information
Showing
13 changed files
with
784 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
/************************************************************************ | ||
* This file has been generated automatically from * | ||
* * | ||
* src/gui/auth/qgsauthsettingswidget.h * | ||
* * | ||
* Do not edit manually ! Edit header and run scripts/sipify.pl again * | ||
************************************************************************/ | ||
|
||
|
||
|
||
|
||
class QgsAuthSettingsWidget : QWidget | ||
{ | ||
%Docstring | ||
Widget for entering authentication credentials both in the form username/password | ||
and by using QGIS Authentication Database and its authentication configurations. | ||
.. versionadded:: 3.0 | ||
%End | ||
|
||
%TypeHeaderCode | ||
#include "qgsauthsettingswidget.h" | ||
%End | ||
public: | ||
|
||
explicit QgsAuthSettingsWidget( QWidget *parent /TransferThis/ = 0, | ||
const QString &configId = QString(), | ||
const QString &username = QString(), | ||
const QString &password = QString(), | ||
const QString &dataprovider = QString() ); | ||
%Docstring | ||
Create a dialog for setting an associated authentication config, either | ||
from existing configs, or creating/removing them from auth database | ||
\param parent Parent widget | ||
\param configId authentication configuration id | ||
\param username | ||
\param password | ||
\param dataprovider The key of the calling layer provider, if applicable | ||
%End | ||
|
||
void setWarningText( const QString &warningText ); | ||
%Docstring | ||
setWarningText set the text of the warning label | ||
\param warningText the text of the warning label | ||
%End | ||
|
||
void setBasicText( const QString &basicText ); | ||
%Docstring | ||
setBasicText set the text of the warning label | ||
\param basicText the text of the basic tab label | ||
%End | ||
|
||
const QString username( ) const; | ||
%Docstring | ||
username | ||
:return: basic authentication username | ||
:rtype: str | ||
%End | ||
|
||
const QString password( ) const; | ||
%Docstring | ||
password | ||
:return: basic authentication password | ||
:rtype: str | ||
%End | ||
|
||
const QString configId( ) const; | ||
%Docstring | ||
configId | ||
:return: authentication configuration id | ||
:rtype: str | ||
%End | ||
|
||
int currentTabIndex( ) const; | ||
%Docstring | ||
currentTabIndex, mainly useful for unit tests | ||
:return: active tab index | ||
:rtype: int | ||
%End | ||
|
||
bool btnConvertToEncryptedIsEnabled( ) const; | ||
%Docstring | ||
convertButtonEnabled, mainly useful for unit tests | ||
:return: true if the convert button is enabled | ||
:rtype: bool | ||
%End | ||
|
||
public slots: | ||
|
||
bool on_btnConvertToEncrypted_clicked( ); | ||
%Docstring | ||
on_btnConvertToEncrypted_clicked create a Basic authentication configuration from | ||
username and password specified in the Basic tab | ||
:return: return true on success | ||
:rtype: bool | ||
%End | ||
|
||
|
||
|
||
|
||
}; | ||
|
||
/************************************************************************ | ||
* This file has been generated automatically from * | ||
* * | ||
* src/gui/auth/qgsauthsettingswidget.h * | ||
* * | ||
* Do not edit manually ! Edit header and run scripts/sipify.pl again * | ||
************************************************************************/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
/*************************************************************************** | ||
qgsauthsettingswidget.cpp - QgsAuthSettingsWidget | ||
--------------------- | ||
begin : 28.9.2017 | ||
copyright : (C) 2017 by Alessandro Pasotti | ||
email : apasotti at boundlessgeo dot com | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
#include "qgsauthsettingswidget.h" | ||
#include "qgsauthmanager.h" | ||
#include "qgsauthconfig.h" | ||
|
||
#include <QDateTime> | ||
|
||
QgsAuthSettingsWidget::QgsAuthSettingsWidget( QWidget *parent, | ||
const QString &configId, | ||
const QString &username, | ||
const QString &password, | ||
const QString &dataprovider ) | ||
: QWidget( parent ) | ||
{ | ||
setupUi( this ); | ||
txtPassword->setText( password ); | ||
txtUserName->setText( username ); | ||
if ( ! dataprovider.isEmpty( ) ) | ||
{ | ||
mAuthConfigSelect->setDataProviderKey( dataprovider ); | ||
} | ||
if ( ! configId.isEmpty( ) ) | ||
{ | ||
mAuthConfigSelect->setConfigId( configId ); | ||
tabAuth->setCurrentIndex( tabAuth->indexOf( tabConfigurations ) ); | ||
} | ||
else if ( !( username.isEmpty() && password.isEmpty( ) ) ) | ||
{ | ||
tabAuth->setCurrentIndex( tabAuth->indexOf( tabBasic ) ); | ||
} | ||
updateConvertBtnState(); | ||
} | ||
|
||
void QgsAuthSettingsWidget::setWarningText( const QString &warningText ) | ||
{ | ||
lblWarning->setText( warningText ); | ||
} | ||
|
||
void QgsAuthSettingsWidget::setBasicText( const QString &basicText ) | ||
{ | ||
lblBasic->setText( basicText ); | ||
} | ||
|
||
const QString QgsAuthSettingsWidget::username() const | ||
{ | ||
return txtUserName->text(); | ||
} | ||
|
||
const QString QgsAuthSettingsWidget::password() const | ||
{ | ||
return txtPassword->text(); | ||
} | ||
|
||
const QString QgsAuthSettingsWidget::configId() const | ||
{ | ||
return mAuthConfigSelect->configId(); | ||
} | ||
|
||
int QgsAuthSettingsWidget::currentTabIndex() const | ||
{ | ||
return tabAuth->currentIndex( ); | ||
} | ||
|
||
bool QgsAuthSettingsWidget::btnConvertToEncryptedIsEnabled() const | ||
{ | ||
return btnConvertToEncrypted->isEnabled( ); | ||
} | ||
|
||
bool QgsAuthSettingsWidget::on_btnConvertToEncrypted_clicked() | ||
{ | ||
tabAuth->setCurrentIndex( tabAuth->indexOf( tabConfigurations ) ); | ||
QgsAuthMethodConfig config( QStringLiteral( "Basic" ) ); | ||
config.setName( tr( "Converted config %1" ).arg( QDateTime::currentDateTime().toString( ) ) ); | ||
config.setConfig( QStringLiteral( "username" ), txtUserName->text() ); | ||
config.setConfig( QStringLiteral( "password" ), txtPassword->text() ); | ||
if ( ! QgsAuthManager::instance()->storeAuthenticationConfig( config ) ) | ||
{ | ||
mAuthConfigSelect->showMessage( tr( "Couldn't create a Basic authentication configuration!" ) ); | ||
return false; | ||
} | ||
else | ||
{ | ||
txtUserName->setText( QString( ) ); | ||
txtPassword->setText( QString( ) ); | ||
mAuthConfigSelect->setConfigId( config.id( ) ); | ||
return true; | ||
} | ||
} | ||
|
||
void QgsAuthSettingsWidget::on_txtUserName_textChanged( const QString &text ) | ||
{ | ||
Q_UNUSED( text ); | ||
updateConvertBtnState(); | ||
} | ||
|
||
void QgsAuthSettingsWidget::on_txtPassword_textChanged( const QString &text ) | ||
{ | ||
Q_UNUSED( text ); | ||
updateConvertBtnState(); | ||
} | ||
|
||
void QgsAuthSettingsWidget::updateConvertBtnState() | ||
{ | ||
btnConvertToEncrypted->setEnabled( ! txtUserName->text().isEmpty() || ! txtPassword->text().isEmpty() ); | ||
} |
Oops, something went wrong.