Merge pull request #60441 from nyalldawson/auth_manager_ux_tweaks

Auth manager ux tweaks
This commit is contained in:
Alessandro Pasotti 2025-02-05 16:13:50 +01:00 committed by GitHub
commit e381be985b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 154 additions and 86 deletions

View File

@ -4,10 +4,11 @@ QgsAuthManager.WARNING = QgsAuthManager.MessageLevel.WARNING
QgsAuthManager.CRITICAL = QgsAuthManager.MessageLevel.CRITICAL
QgsAuthManager.MessageLevel.baseClass = QgsAuthManager
try:
QgsAuthManager.__attribute_docs__ = {'AUTH_PASSWORD_HELPER_DISPLAY_NAME': 'The display name of the password helper (platform dependent)', 'AUTH_MAN_TAG': 'The display name of the Authentication Manager', 'passwordHelperFailure': 'Signals emitted on password helper failure,\nmainly used in the tests to exit main application loop\n', 'passwordHelperSuccess': 'Signals emitted on password helper success,\nmainly used in the tests to exit main application loop\n', 'messageOut': 'Custom logging signal to relay to console output and :py:class:`QgsMessageLog`\n\n:param message: Message to send\n:param tag: Associated tag (title)\n:param level: Message log level\n\n.. seealso:: :py:class:`QgsMessageLog`\n\n.. deprecated:: 3.40\n\n Use :py:func:`~QgsAuthManager.messageLog` instead.\n', 'messageLog': 'Custom logging signal to relay to console output and :py:class:`QgsMessageLog`\n\n:param message: Message to send\n:param tag: Associated tag (title)\n:param level: Message log level\n\n.. seealso:: :py:class:`QgsMessageLog`\n\n.. versionadded:: 3.40\n', 'passwordHelperMessageOut': 'Custom logging signal to inform the user about master password <-> password manager interactions\n\n:param message: Message to send\n:param tag: Associated tag (title)\n:param level: Message log level\n\n.. seealso:: :py:class:`QgsMessageLog`\n\n.. deprecated:: 3.40\n\n Use :py:func:`~QgsAuthManager.passwordHelperMessageLog` instead.\n', 'passwordHelperMessageLog': 'Custom logging signal to inform the user about master password <-> password manager interactions\n\n:param message: Message to send\n:param tag: Associated tag (title)\n:param level: Message log level\n\n.. seealso:: :py:class:`QgsMessageLog`\n\n.. versionadded:: 3.40\n', 'masterPasswordVerified': "Emitted when a password has been verify (or not)\n\n:param verified: The state of password's verification\n", 'authDatabaseEraseRequested': 'Emitted when a user has indicated they may want to erase the authentication db.\n', 'authDatabaseChanged': 'Emitted when the authentication db is significantly changed, e.g. large record removal, erased, etc.\n'}
QgsAuthManager.__attribute_docs__ = {'AUTH_PASSWORD_HELPER_DISPLAY_NAME': 'The display name of the password helper (platform dependent).\n\nThis is deprecated, use :py:func:`~QgsAuthManager.passwordHelperDisplayName` instead.', 'AUTH_MAN_TAG': 'The display name of the Authentication Manager', 'passwordHelperFailure': 'Signals emitted on password helper failure,\nmainly used in the tests to exit main application loop\n', 'passwordHelperSuccess': 'Signals emitted on password helper success,\nmainly used in the tests to exit main application loop\n', 'messageOut': 'Custom logging signal to relay to console output and :py:class:`QgsMessageLog`\n\n:param message: Message to send\n:param tag: Associated tag (title)\n:param level: Message log level\n\n.. seealso:: :py:class:`QgsMessageLog`\n\n.. deprecated:: 3.40\n\n Use :py:func:`~QgsAuthManager.messageLog` instead.\n', 'messageLog': 'Custom logging signal to relay to console output and :py:class:`QgsMessageLog`\n\n:param message: Message to send\n:param tag: Associated tag (title)\n:param level: Message log level\n\n.. seealso:: :py:class:`QgsMessageLog`\n\n.. versionadded:: 3.40\n', 'passwordHelperMessageOut': 'Custom logging signal to inform the user about master password <-> password manager interactions\n\n:param message: Message to send\n:param tag: Associated tag (title)\n:param level: Message log level\n\n.. seealso:: :py:class:`QgsMessageLog`\n\n.. deprecated:: 3.40\n\n Use :py:func:`~QgsAuthManager.passwordHelperMessageLog` instead.\n', 'passwordHelperMessageLog': 'Custom logging signal to inform the user about master password <-> password manager interactions\n\n:param message: Message to send\n:param tag: Associated tag (title)\n:param level: Message log level\n\n.. seealso:: :py:class:`QgsMessageLog`\n\n.. versionadded:: 3.40\n', 'masterPasswordVerified': "Emitted when a password has been verify (or not)\n\n:param verified: The state of password's verification\n", 'authDatabaseEraseRequested': 'Emitted when a user has indicated they may want to erase the authentication db.\n', 'authDatabaseChanged': 'Emitted when the authentication db is significantly changed, e.g. large record removal, erased, etc.\n'}
QgsAuthManager.isFilesystemBasedDatabase = staticmethod(QgsAuthManager.isFilesystemBasedDatabase)
QgsAuthManager.hasConfigId = staticmethod(QgsAuthManager.hasConfigId)
QgsAuthManager.passwordHelperEnabled = staticmethod(QgsAuthManager.passwordHelperEnabled)
QgsAuthManager.passwordHelperDisplayName = staticmethod(QgsAuthManager.passwordHelperDisplayName)
QgsAuthManager.__signal_arguments__ = {'passwordHelperMessageLog': ['message: str', 'tag: str = QgsAuthManager.AUTH_MAN_TAG', 'level: Qgis.MessageLevel = Qgis.MessageLevel.Info'], 'masterPasswordVerified': ['verified: bool']}
QgsAuthManager.__group__ = ['auth']
except (NameError, AttributeError):

View File

@ -810,8 +810,19 @@ Store the password manager into the wallet
Available in Python bindings since QGIS 3.8.0
%End
static const QString AUTH_PASSWORD_HELPER_DISPLAY_NAME;
static QString passwordHelperDisplayName( bool titleCase = false );
%Docstring
Returns a translated display name of the password helper (platform dependent).
If ``titleCase`` is ``True`` then a title case version of the string will be returned. Otherwise
a mid-sentence case version will be returned.
.. versionadded:: 3.42
%End
static const QString AUTH_MAN_TAG;

View File

@ -1,10 +1,11 @@
# The following has been generated automatically from src/core/auth/qgsauthmanager.h
QgsAuthManager.MessageLevel.baseClass = QgsAuthManager
try:
QgsAuthManager.__attribute_docs__ = {'AUTH_PASSWORD_HELPER_DISPLAY_NAME': 'The display name of the password helper (platform dependent)', 'AUTH_MAN_TAG': 'The display name of the Authentication Manager', 'passwordHelperFailure': 'Signals emitted on password helper failure,\nmainly used in the tests to exit main application loop\n', 'passwordHelperSuccess': 'Signals emitted on password helper success,\nmainly used in the tests to exit main application loop\n', 'messageOut': 'Custom logging signal to relay to console output and :py:class:`QgsMessageLog`\n\n:param message: Message to send\n:param tag: Associated tag (title)\n:param level: Message log level\n\n.. seealso:: :py:class:`QgsMessageLog`\n\n.. deprecated:: 3.40\n\n Use :py:func:`~QgsAuthManager.messageLog` instead.\n', 'messageLog': 'Custom logging signal to relay to console output and :py:class:`QgsMessageLog`\n\n:param message: Message to send\n:param tag: Associated tag (title)\n:param level: Message log level\n\n.. seealso:: :py:class:`QgsMessageLog`\n\n.. versionadded:: 3.40\n', 'passwordHelperMessageOut': 'Custom logging signal to inform the user about master password <-> password manager interactions\n\n:param message: Message to send\n:param tag: Associated tag (title)\n:param level: Message log level\n\n.. seealso:: :py:class:`QgsMessageLog`\n\n.. deprecated:: 3.40\n\n Use :py:func:`~QgsAuthManager.passwordHelperMessageLog` instead.\n', 'passwordHelperMessageLog': 'Custom logging signal to inform the user about master password <-> password manager interactions\n\n:param message: Message to send\n:param tag: Associated tag (title)\n:param level: Message log level\n\n.. seealso:: :py:class:`QgsMessageLog`\n\n.. versionadded:: 3.40\n', 'masterPasswordVerified': "Emitted when a password has been verify (or not)\n\n:param verified: The state of password's verification\n", 'authDatabaseEraseRequested': 'Emitted when a user has indicated they may want to erase the authentication db.\n', 'authDatabaseChanged': 'Emitted when the authentication db is significantly changed, e.g. large record removal, erased, etc.\n'}
QgsAuthManager.__attribute_docs__ = {'AUTH_PASSWORD_HELPER_DISPLAY_NAME': 'The display name of the password helper (platform dependent).\n\nThis is deprecated, use :py:func:`~QgsAuthManager.passwordHelperDisplayName` instead.', 'AUTH_MAN_TAG': 'The display name of the Authentication Manager', 'passwordHelperFailure': 'Signals emitted on password helper failure,\nmainly used in the tests to exit main application loop\n', 'passwordHelperSuccess': 'Signals emitted on password helper success,\nmainly used in the tests to exit main application loop\n', 'messageOut': 'Custom logging signal to relay to console output and :py:class:`QgsMessageLog`\n\n:param message: Message to send\n:param tag: Associated tag (title)\n:param level: Message log level\n\n.. seealso:: :py:class:`QgsMessageLog`\n\n.. deprecated:: 3.40\n\n Use :py:func:`~QgsAuthManager.messageLog` instead.\n', 'messageLog': 'Custom logging signal to relay to console output and :py:class:`QgsMessageLog`\n\n:param message: Message to send\n:param tag: Associated tag (title)\n:param level: Message log level\n\n.. seealso:: :py:class:`QgsMessageLog`\n\n.. versionadded:: 3.40\n', 'passwordHelperMessageOut': 'Custom logging signal to inform the user about master password <-> password manager interactions\n\n:param message: Message to send\n:param tag: Associated tag (title)\n:param level: Message log level\n\n.. seealso:: :py:class:`QgsMessageLog`\n\n.. deprecated:: 3.40\n\n Use :py:func:`~QgsAuthManager.passwordHelperMessageLog` instead.\n', 'passwordHelperMessageLog': 'Custom logging signal to inform the user about master password <-> password manager interactions\n\n:param message: Message to send\n:param tag: Associated tag (title)\n:param level: Message log level\n\n.. seealso:: :py:class:`QgsMessageLog`\n\n.. versionadded:: 3.40\n', 'masterPasswordVerified': "Emitted when a password has been verify (or not)\n\n:param verified: The state of password's verification\n", 'authDatabaseEraseRequested': 'Emitted when a user has indicated they may want to erase the authentication db.\n', 'authDatabaseChanged': 'Emitted when the authentication db is significantly changed, e.g. large record removal, erased, etc.\n'}
QgsAuthManager.isFilesystemBasedDatabase = staticmethod(QgsAuthManager.isFilesystemBasedDatabase)
QgsAuthManager.hasConfigId = staticmethod(QgsAuthManager.hasConfigId)
QgsAuthManager.passwordHelperEnabled = staticmethod(QgsAuthManager.passwordHelperEnabled)
QgsAuthManager.passwordHelperDisplayName = staticmethod(QgsAuthManager.passwordHelperDisplayName)
QgsAuthManager.__signal_arguments__ = {'passwordHelperMessageLog': ['message: str', 'tag: str = QgsAuthManager.AUTH_MAN_TAG', 'level: Qgis.MessageLevel = Qgis.MessageLevel.Info'], 'masterPasswordVerified': ['verified: bool']}
QgsAuthManager.__group__ = ['auth']
except (NameError, AttributeError):

View File

@ -810,8 +810,19 @@ Store the password manager into the wallet
Available in Python bindings since QGIS 3.8.0
%End
static const QString AUTH_PASSWORD_HELPER_DISPLAY_NAME;
static QString passwordHelperDisplayName( bool titleCase = false );
%Docstring
Returns a translated display name of the password helper (platform dependent).
If ``titleCase`` is ``True`` then a title case version of the string will be returned. Otherwise
a mid-sentence case version will be returned.
.. versionadded:: 3.42
%End
static const QString AUTH_MAN_TAG;

View File

@ -71,6 +71,7 @@ const QLatin1String QgsAuthManager::AUTH_PASSWORD_HELPER_FOLDER_NAME( "QGIS" );
Q_NOWARN_DEPRECATED_PUSH
#if defined(Q_OS_MAC)
const QString QgsAuthManager::AUTH_PASSWORD_HELPER_DISPLAY_NAME( "Keychain" );
#elif defined(Q_OS_WIN)
@ -80,6 +81,7 @@ const QString QgsAuthManager::AUTH_PASSWORD_HELPER_DISPLAY_NAME( QStringLiteral(
#else
const QString QgsAuthManager::AUTH_PASSWORD_HELPER_DISPLAY_NAME( "Password Manager" );
#endif
Q_NOWARN_DEPRECATED_POP
QgsAuthManager *QgsAuthManager::instance()
{
@ -399,7 +401,7 @@ const QString QgsAuthManager::disabledMessage() const
}
const QString QgsAuthManager::sqliteDatabasePath() const
QString QgsAuthManager::sqliteDatabasePath() const
{
if ( !QgsAuthManager::isFilesystemBasedDatabase( mAuthDatabaseConnectionUri ) )
{
@ -3074,6 +3076,29 @@ bool QgsAuthManager::passwordHelperSync()
return false;
}
QString QgsAuthManager::passwordHelperDisplayName( bool titleCase )
{
#if defined(Q_OS_MAC)
return titleCase ? QObject::tr( "Keychain" ) : QObject::tr( "keychain" );
#elif defined(Q_OS_WIN)
return titleCase ? QObject::tr( "Password Manager" ) : QObject::tr( "password manager" );
#elif defined(Q_OS_LINUX)
const QString desktopSession = qgetenv( "DESKTOP_SESSION" );
const QString currentDesktop = qgetenv( "XDG_CURRENT_DESKTOP" );
const QString gdmSession = qgetenv( "GDMSESSION" );
// lets use a more precise string if we're running on KDE!
if ( desktopSession.contains( QLatin1String( "kde" ), Qt::CaseInsensitive ) || currentDesktop.contains( QLatin1String( "kde" ), Qt::CaseInsensitive ) || gdmSession.contains( QLatin1String( "kde" ), Qt::CaseInsensitive ) )
{
return titleCase ? QObject::tr( "Wallet" ) : QObject::tr( "wallet" );
}
return titleCase ? QObject::tr( "Wallet/Key Ring" ) : QObject::tr( "wallet/key ring" );
#else
return titleCase ? QObject::tr( "Password Manager" ) : QObject::tr( "password manager" );
#endif
}
////////////////// Certificate calls - end ///////////////////////
@ -3234,7 +3259,7 @@ bool QgsAuthManager::passwordHelperDelete()
{
ensureInitialized();
passwordHelperLog( tr( "Opening %1 for DELETE…" ).arg( AUTH_PASSWORD_HELPER_DISPLAY_NAME ) );
passwordHelperLog( tr( "Opening %1 for DELETE…" ).arg( passwordHelperDisplayName() ) );
bool result;
QKeychain::DeletePasswordJob job( AUTH_PASSWORD_HELPER_FOLDER_NAME );
QgsSettings settings;
@ -3269,7 +3294,7 @@ QString QgsAuthManager::passwordHelperRead()
// Retrieve it!
QString password;
passwordHelperLog( tr( "Opening %1 for READ…" ).arg( AUTH_PASSWORD_HELPER_DISPLAY_NAME ) );
passwordHelperLog( tr( "Opening %1 for READ…" ).arg( passwordHelperDisplayName() ) );
QKeychain::ReadPasswordJob job( AUTH_PASSWORD_HELPER_FOLDER_NAME );
QgsSettings settings;
job.setInsecureFallback( settings.value( QStringLiteral( "password_helper_insecure_fallback" ), false, QgsSettings::Section::Auth ).toBool() );
@ -3282,7 +3307,7 @@ QString QgsAuthManager::passwordHelperRead()
if ( job.error() )
{
mPasswordHelperErrorCode = job.error();
mPasswordHelperErrorMessage = tr( "Retrieving password from your %1 failed: %2." ).arg( AUTH_PASSWORD_HELPER_DISPLAY_NAME, job.errorString() );
mPasswordHelperErrorMessage = tr( "Retrieving password from your %1 failed: %2." ).arg( passwordHelperDisplayName(), job.errorString() );
// Signals used in the tests to exit main application loop
emit passwordHelperFailure();
}
@ -3293,7 +3318,7 @@ QString QgsAuthManager::passwordHelperRead()
if ( password.isEmpty() )
{
mPasswordHelperErrorCode = QKeychain::EntryNotFound;
mPasswordHelperErrorMessage = tr( "Empty password retrieved from your %1." ).arg( AUTH_PASSWORD_HELPER_DISPLAY_NAME );
mPasswordHelperErrorMessage = tr( "Empty password retrieved from your %1." ).arg( passwordHelperDisplayName( true ) );
// Signals used in the tests to exit main application loop
emit passwordHelperFailure();
}
@ -3313,7 +3338,7 @@ bool QgsAuthManager::passwordHelperWrite( const QString &password )
Q_ASSERT( !password.isEmpty() );
bool result;
passwordHelperLog( tr( "Opening %1 for WRITE…" ).arg( AUTH_PASSWORD_HELPER_DISPLAY_NAME ) );
passwordHelperLog( tr( "Opening %1 for WRITE…" ).arg( passwordHelperDisplayName() ) );
QKeychain::WritePasswordJob job( AUTH_PASSWORD_HELPER_FOLDER_NAME );
QgsSettings settings;
job.setInsecureFallback( settings.value( QStringLiteral( "password_helper_insecure_fallback" ), false, QgsSettings::Section::Auth ).toBool() );
@ -3327,7 +3352,7 @@ bool QgsAuthManager::passwordHelperWrite( const QString &password )
if ( job.error() )
{
mPasswordHelperErrorCode = job.error();
mPasswordHelperErrorMessage = tr( "Storing password in your %1 failed: %2." ).arg( AUTH_PASSWORD_HELPER_DISPLAY_NAME, job.errorString() );
mPasswordHelperErrorMessage = tr( "Storing password in your %1 failed: %2." ).arg( passwordHelperDisplayName(), job.errorString() );
// Signals used in the tests to exit main application loop
emit passwordHelperFailure();
result = false;
@ -3355,9 +3380,9 @@ void QgsAuthManager::setPasswordHelperEnabled( const bool enabled )
QgsSettings settings;
settings.setValue( QStringLiteral( "use_password_helper" ), enabled, QgsSettings::Section::Auth );
emit messageLog( enabled ? tr( "Your %1 will be <b>used from now</b> on to store and retrieve the master password." )
.arg( AUTH_PASSWORD_HELPER_DISPLAY_NAME ) :
.arg( passwordHelperDisplayName() ) :
tr( "Your %1 will <b>not be used anymore</b> to store and retrieve the master password." )
.arg( AUTH_PASSWORD_HELPER_DISPLAY_NAME ) );
.arg( passwordHelperDisplayName() ) );
}
bool QgsAuthManager::passwordHelperLoggingEnabled()
@ -3395,12 +3420,12 @@ void QgsAuthManager::passwordHelperProcessError()
mPasswordHelperErrorMessage = tr( "There was an error and integration with your %1 system has been disabled. "
"You can re-enable it at any time through the \"Utilities\" menu "
"in the Authentication pane of the options dialog. %2" )
.arg( AUTH_PASSWORD_HELPER_DISPLAY_NAME, mPasswordHelperErrorMessage );
.arg( passwordHelperDisplayName(), mPasswordHelperErrorMessage );
}
if ( mPasswordHelperErrorCode != QKeychain::NoError )
{
// We've got an error from the wallet
passwordHelperLog( tr( "Error in %1: %2" ).arg( AUTH_PASSWORD_HELPER_DISPLAY_NAME, mPasswordHelperErrorMessage ) );
passwordHelperLog( tr( "Error in %1: %2" ).arg( passwordHelperDisplayName(), mPasswordHelperErrorMessage ) );
emit passwordHelperMessageLog( mPasswordHelperErrorMessage, authManTag(), Qgis::MessageLevel::Critical );
}
passwordHelperClearErrors();
@ -3429,11 +3454,11 @@ bool QgsAuthManager::masterPasswordInput()
{
ok = true;
storedPasswordIsValid = true;
emit passwordHelperMessageLog( tr( "Master password has been successfully read from your %1" ).arg( AUTH_PASSWORD_HELPER_DISPLAY_NAME ), authManTag(), Qgis::MessageLevel::Info );
emit passwordHelperMessageLog( tr( "Master password has been successfully read from your %1" ).arg( passwordHelperDisplayName() ), authManTag(), Qgis::MessageLevel::Info );
}
else
{
emit passwordHelperMessageLog( tr( "Master password stored in your %1 is not valid" ).arg( AUTH_PASSWORD_HELPER_DISPLAY_NAME ), authManTag(), Qgis::MessageLevel::Warning );
emit passwordHelperMessageLog( tr( "Master password stored in your %1 is not valid" ).arg( passwordHelperDisplayName() ), authManTag(), Qgis::MessageLevel::Warning );
}
}
}
@ -3451,11 +3476,11 @@ bool QgsAuthManager::masterPasswordInput()
{
if ( passwordHelperWrite( pass ) )
{
emit passwordHelperMessageLog( tr( "Master password has been successfully written to your %1" ).arg( AUTH_PASSWORD_HELPER_DISPLAY_NAME ), authManTag(), Qgis::MessageLevel::Info );
emit passwordHelperMessageLog( tr( "Master password has been successfully written to your %1" ).arg( passwordHelperDisplayName() ), authManTag(), Qgis::MessageLevel::Info );
}
else
{
emit passwordHelperMessageLog( tr( "Master password could not be written to your %1" ).arg( AUTH_PASSWORD_HELPER_DISPLAY_NAME ), authManTag(), Qgis::MessageLevel::Warning );
emit passwordHelperMessageLog( tr( "Master password could not be written to your %1" ).arg( passwordHelperDisplayName() ), authManTag(), Qgis::MessageLevel::Warning );
}
}
return true;

View File

@ -756,12 +756,34 @@ class CORE_EXPORT QgsAuthManager : public QObject
*/
bool passwordHelperSync();
//! The display name of the password helper (platform dependent)
// TODO QGIS 4.0 -- remove
/**
* The display name of the password helper (platform dependent).
*
* This is deprecated, use passwordHelperDisplayName() instead.
*/
static const QString AUTH_PASSWORD_HELPER_DISPLAY_NAME;
/**
* Returns a translated display name of the password helper (platform dependent).
*
* If \a titleCase is TRUE then a title case version of the string will be returned. Otherwise
* a mid-sentence case version will be returned.
*
* \since QGIS 3.42
*/
static QString passwordHelperDisplayName( bool titleCase = false );
//! The display name of the Authentication Manager
static const QString AUTH_MAN_TAG;
/**
* Returns the path to the authentication database file or an empty string if the database is not SQLite.
*
* \note Not available in Python bindings
*/
QString sqliteDatabasePath() const SIP_SKIP;
signals:
@ -933,11 +955,6 @@ class CORE_EXPORT QgsAuthManager : public QObject
*/
QgsAuthConfigurationStorage *firstStorageWithCapability( Qgis::AuthConfigurationStorageCapability capability ) const;
/**
* Returns the path to the authentication database file or an empty string if the database is not SQLite.
*/
const QString sqliteDatabasePath() const;
static QgsAuthManager *sInstance;
static const QString AUTH_CONFIG_TABLE;
static const QString AUTH_SERVERS_TABLE;

View File

@ -164,9 +164,9 @@ void QgsAuthEditorWidgets::setupUtilitiesMenu()
mActionAutoClearAccessCache->setCheckable( true );
mActionAutoClearAccessCache->setChecked( QgsSettings().value( QStringLiteral( "clear_auth_cache_on_errors" ), true, QgsSettings::Section::Auth ).toBool() );
mActionPasswordHelperSync = new QAction( tr( "Store/update the Master Password in your %1" ).arg( QgsAuthManager::AUTH_PASSWORD_HELPER_DISPLAY_NAME ), this );
mActionPasswordHelperDelete = new QAction( tr( "Clear the Master Password from your %1…" ).arg( QgsAuthManager::AUTH_PASSWORD_HELPER_DISPLAY_NAME ), this );
mActionPasswordHelperEnable = new QAction( tr( "Integrate Master Password with your %1" ).arg( QgsAuthManager::AUTH_PASSWORD_HELPER_DISPLAY_NAME ), this );
mActionPasswordHelperSync = new QAction( tr( "Store/update the Master Password in your %1" ).arg( QgsAuthManager::passwordHelperDisplayName( true ) ), this );
mActionPasswordHelperDelete = new QAction( tr( "Clear the Master Password from your %1…" ).arg( QgsAuthManager::passwordHelperDisplayName( true ) ), this );
mActionPasswordHelperEnable = new QAction( tr( "Integrate Master Password with your %1" ).arg( QgsAuthManager::passwordHelperDisplayName( true ) ), this );
mActionPasswordHelperLoggingEnable = new QAction( tr( "Enable Password Helper Debug Log" ), this );
mActionPasswordHelperEnable->setCheckable( true );

View File

@ -331,7 +331,7 @@ QString QgsAuthGuiUtils::getOpenFileName( QWidget *parent, const QString &title,
void QgsAuthGuiUtils::passwordHelperDelete( QgsMessageBar *msgbar, QWidget *parent )
{
if ( QMessageBox::warning( parent, QObject::tr( "Delete Password" ), QObject::tr( "Do you really want to delete the master password from your %1?" ).arg( QgsAuthManager::AUTH_PASSWORD_HELPER_DISPLAY_NAME ), QMessageBox::Ok | QMessageBox::Cancel, QMessageBox::Cancel ) == QMessageBox::Cancel )
if ( QMessageBox::warning( parent, QObject::tr( "Delete Password" ), QObject::tr( "Do you really want to delete the master password from your %1?" ).arg( QgsAuthManager::passwordHelperDisplayName() ), QMessageBox::Ok | QMessageBox::Cancel, QMessageBox::Cancel ) == QMessageBox::Cancel )
{
return;
}
@ -345,7 +345,7 @@ void QgsAuthGuiUtils::passwordHelperDelete( QgsMessageBar *msgbar, QWidget *pare
else
{
msg = QObject::tr( "Master password was successfully deleted from your %1" )
.arg( QgsAuthManager::AUTH_PASSWORD_HELPER_DISPLAY_NAME );
.arg( QgsAuthManager::passwordHelperDisplayName() );
level = Qgis::MessageLevel::Info;
}
@ -360,7 +360,7 @@ void QgsAuthGuiUtils::passwordHelperSync( QgsMessageBar *msgbar )
if ( !QgsApplication::authManager()->masterPasswordIsSet() )
{
msg = QObject::tr( "Master password is not set and cannot be stored in your %1." )
.arg( QgsAuthManager::AUTH_PASSWORD_HELPER_DISPLAY_NAME );
.arg( QgsAuthManager::passwordHelperDisplayName() );
level = Qgis::MessageLevel::Warning;
}
else if ( !QgsApplication::authManager()->passwordHelperSync() )
@ -371,7 +371,7 @@ void QgsAuthGuiUtils::passwordHelperSync( QgsMessageBar *msgbar )
else
{
msg = QObject::tr( "Master password has been successfully stored in your %1." )
.arg( QgsAuthManager::AUTH_PASSWORD_HELPER_DISPLAY_NAME );
.arg( QgsAuthManager::passwordHelperDisplayName() );
level = Qgis::MessageLevel::Info;
}
@ -383,9 +383,9 @@ void QgsAuthGuiUtils::passwordHelperEnable( bool enabled, QgsMessageBar *msgbar
{
QgsApplication::authManager()->setPasswordHelperEnabled( enabled );
const QString msg = enabled ? QObject::tr( "Your %1 will be <b>used from now</b> on to store and retrieve the master password." )
.arg( QgsAuthManager::AUTH_PASSWORD_HELPER_DISPLAY_NAME )
.arg( QgsAuthManager::passwordHelperDisplayName() )
: QObject::tr( "Your %1 will <b>not be used anymore</b> to store and retrieve the master password." )
.arg( QgsAuthManager::AUTH_PASSWORD_HELPER_DISPLAY_NAME );
.arg( QgsAuthManager::passwordHelperDisplayName() );
msgbar->clearWidgets();
msgbar->pushMessage( QObject::tr( "Password helper write" ), msg, Qgis::MessageLevel::Info );
}

View File

@ -39,8 +39,14 @@ QgsMasterPasswordResetDialog::QgsMasterPasswordResetDialog( QWidget *parent )
else
{
setupUi( this );
connect( leMasterPassCurrent, &QgsPasswordLineEdit::textChanged, this, &QgsMasterPasswordResetDialog::leMasterPassCurrent_textChanged );
connect( leMasterPassNew, &QgsPasswordLineEdit::textChanged, this, &QgsMasterPasswordResetDialog::leMasterPassNew_textChanged );
connect( leMasterPassCurrent, &QgsPasswordLineEdit::textChanged, this, &QgsMasterPasswordResetDialog::validatePasswords );
connect( leMasterPassNew, &QgsPasswordLineEdit::textChanged, this, &QgsMasterPasswordResetDialog::validatePasswords );
connect( leMasterPassNew2, &QgsPasswordLineEdit::textChanged, this, &QgsMasterPasswordResetDialog::validatePasswords );
if ( QgsApplication::authManager()->sqliteDatabasePath().isEmpty() )
{
chkKeepBackup->hide();
}
}
}
@ -58,35 +64,31 @@ bool QgsMasterPasswordResetDialog::requestMasterPasswordReset( QString *newpass,
{
*newpass = leMasterPassNew->text();
*oldpass = leMasterPassCurrent->text();
*keepbackup = chkKeepBackup->isChecked();
*keepbackup = !chkKeepBackup->isHidden() && chkKeepBackup->isChecked();
return true;
}
}
return false;
}
void QgsMasterPasswordResetDialog::leMasterPassCurrent_textChanged( const QString &pass )
{
// since this is called on every keystroke, block signals emitted during verification of password
QgsApplication::authManager()->blockSignals( true );
mPassCurOk = !pass.isEmpty();
QgsApplication::authManager()->blockSignals( false );
validatePasswords();
}
void QgsMasterPasswordResetDialog::leMasterPassNew_textChanged( const QString &pass )
{
mPassNewOk = !pass.isEmpty();
validatePasswords();
}
void QgsMasterPasswordResetDialog::validatePasswords()
{
const QString ss1 = mPassCurOk ? QgsAuthGuiUtils::greenTextStyleSheet( QStringLiteral( "QLineEdit" ) )
: QgsAuthGuiUtils::redTextStyleSheet( QStringLiteral( "QLineEdit" ) );
const QString currentPassword = leMasterPassCurrent->text();
const QString newPassword = leMasterPassNew->text();
const QString confirmPassword = leMasterPassNew2->text();
const bool currentPasswordOk = !currentPassword.isEmpty();
const bool newPasswordOk = !newPassword.isEmpty();
const bool confirmPasswordOk = !confirmPassword.isEmpty() && confirmPassword == newPassword;
const QString ss1 = currentPasswordOk ? QgsAuthGuiUtils::greenTextStyleSheet( QStringLiteral( "QLineEdit" ) )
: QgsAuthGuiUtils::redTextStyleSheet( QStringLiteral( "QLineEdit" ) );
leMasterPassCurrent->setStyleSheet( ss1 );
const QString ss2 = mPassNewOk ? QgsAuthGuiUtils::greenTextStyleSheet( QStringLiteral( "QLineEdit" ) )
: QgsAuthGuiUtils::redTextStyleSheet( QStringLiteral( "QLineEdit" ) );
const QString ss2 = newPasswordOk ? QgsAuthGuiUtils::greenTextStyleSheet( QStringLiteral( "QLineEdit" ) )
: QgsAuthGuiUtils::redTextStyleSheet( QStringLiteral( "QLineEdit" ) );
leMasterPassNew->setStyleSheet( ss2 );
buttonBox->button( QDialogButtonBox::Ok )->setEnabled( mPassCurOk && mPassNewOk );
const QString ss3 = confirmPasswordOk ? QgsAuthGuiUtils::greenTextStyleSheet( QStringLiteral( "QLineEdit" ) )
: QgsAuthGuiUtils::redTextStyleSheet( QStringLiteral( "QLineEdit" ) );
leMasterPassNew2->setStyleSheet( ss3 );
buttonBox->button( QDialogButtonBox::Ok )->setEnabled( currentPasswordOk && newPasswordOk && confirmPasswordOk );
}

View File

@ -45,14 +45,9 @@ class GUI_EXPORT QgsMasterPasswordResetDialog : public QDialog, private Ui::QgsM
bool requestMasterPasswordReset( QString *newpass, QString *oldpass, bool *keepbackup );
private slots:
void leMasterPassCurrent_textChanged( const QString &pass );
void leMasterPassNew_textChanged( const QString &pass );
private:
void validatePasswords();
bool mPassCurOk = false;
bool mPassNewOk = false;
private:
QVBoxLayout *mAuthNotifyLayout = nullptr;
QLabel *mAuthNotify = nullptr;
};

View File

@ -106,7 +106,7 @@ QgsCredentialDialog::QgsCredentialDialog( QWidget *parent, Qt::WindowFlags fl )
leMasterPass->setPlaceholderText( tr( "Required" ) );
chkbxPasswordHelperEnable->setText( tr( "Store/update the master password in your %1" )
.arg( QgsAuthManager::AUTH_PASSWORD_HELPER_DISPLAY_NAME ) );
.arg( QgsAuthManager::passwordHelperDisplayName() ) );
leUsername->setFocus();
}

View File

@ -18,7 +18,6 @@
<widget class="QLabel" name="label_6">
<property name="font">
<font>
<weight>75</weight>
<italic>false</italic>
<bold>true</bold>
</font>
@ -42,7 +41,6 @@
<widget class="QLabel" name="label_7">
<property name="font">
<font>
<weight>75</weight>
<italic>false</italic>
<bold>true</bold>
</font>
@ -63,28 +61,34 @@
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>12</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QCheckBox" name="chkKeepBackup">
<property name="text">
<string>Keep backup of current database</string>
</property>
</widget>
</item>
</layout>
<widget class="QLabel" name="label_8">
<property name="font">
<font>
<italic>false</italic>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Re-enter NEW password</string>
</property>
</widget>
</item>
<item>
<widget class="QgsPasswordLineEdit" name="leMasterPassNew2">
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
<property name="placeholderText">
<string>Required</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="chkKeepBackup">
<property name="text">
<string>Keep backup of current database</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_4">
@ -140,6 +144,7 @@ and re-encrypted using new password</string>
<tabstops>
<tabstop>leMasterPassCurrent</tabstop>
<tabstop>leMasterPassNew</tabstop>
<tabstop>leMasterPassNew2</tabstop>
<tabstop>chkKeepBackup</tabstop>
</tabstops>
<resources/>