QGIS API Documentation 3.41.0-Master (1deb1daf037)
Loading...
Searching...
No Matches
qgsauthmasterpassresetdialog.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsauthmasterpassresetdialog.cpp
3 ---------------------
4 begin : September 10, 2015
5 copyright : (C) 2015 by Boundless Spatial, Inc. USA
6 author : Larry Shaffer
7 email : lshaffer at boundlessgeo dot com
8 ***************************************************************************
9 * *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 ***************************************************************************/
16
18#include "moc_qgsauthmasterpassresetdialog.cpp"
19
20#include <QLineEdit>
21#include <QPushButton>
22
23#include "qgsauthguiutils.h"
24#include "qgsauthmanager.h"
25#include "qgsapplication.h"
26
27
29 : QDialog( parent )
30{
31 if ( QgsApplication::authManager()->isDisabled() )
32 {
33 mAuthNotifyLayout = new QVBoxLayout;
34 this->setLayout( mAuthNotifyLayout );
35 mAuthNotify = new QLabel( QgsApplication::authManager()->disabledMessage(), this );
36 mAuthNotifyLayout->addWidget( mAuthNotify );
37 }
38 else
39 {
40 setupUi( this );
41 connect( leMasterPassCurrent, &QgsPasswordLineEdit::textChanged, this, &QgsMasterPasswordResetDialog::validatePasswords );
42 connect( leMasterPassNew, &QgsPasswordLineEdit::textChanged, this, &QgsMasterPasswordResetDialog::validatePasswords );
43 connect( leMasterPassNew2, &QgsPasswordLineEdit::textChanged, this, &QgsMasterPasswordResetDialog::validatePasswords );
44
45 if ( QgsApplication::authManager()->sqliteDatabasePath().isEmpty() )
46 {
47 chkKeepBackup->hide();
48 }
49
50 QString warning = tr( "The authentication store will be re-encrypted using the new password." );
51 if ( QgsApplication::authManager()->passwordHelperEnabled() )
52 {
53 warning += QStringLiteral( "<p><b>%1</b></p>" ).arg( tr( "The new password will automatically be stored in the system %1." ).arg( QgsAuthManager::passwordHelperDisplayName() ) );
54 }
55
56 lblWarning->setText( warning );
57 }
58}
59
64
65bool QgsMasterPasswordResetDialog::requestMasterPasswordReset( QString *newpass, QString *oldpass, bool *keepbackup )
66{
67 if ( !QgsApplication::authManager()->isDisabled() )
68 {
69 validatePasswords();
70 leMasterPassCurrent->setFocus();
71
72 const bool ok = ( exec() == QDialog::Accepted );
73 //QgsDebugMsgLevel( QStringLiteral( "exec(): %1" ).arg( ok ? "true" : "false" ), 2 );
74
75 if ( ok )
76 {
77 *newpass = leMasterPassNew->text();
78 *oldpass = leMasterPassCurrent->text();
79 *keepbackup = !chkKeepBackup->isHidden() && chkKeepBackup->isChecked();
80 return true;
81 }
82 }
83 return false;
84}
85
86void QgsMasterPasswordResetDialog::validatePasswords()
87{
88 const QString currentPassword = leMasterPassCurrent->text();
89 const QString newPassword = leMasterPassNew->text();
90 const QString confirmPassword = leMasterPassNew2->text();
91
92 const bool currentPasswordOk = !currentPassword.isEmpty();
93 const bool newPasswordOk = !newPassword.isEmpty();
94 const bool confirmPasswordOk = !confirmPassword.isEmpty() && confirmPassword == newPassword;
95
96 if ( leMasterPassCurrent->isEnabled() )
97 {
98 const QString ss1 = currentPasswordOk ? QgsAuthGuiUtils::greenTextStyleSheet( QStringLiteral( "QLineEdit" ) )
99 : QgsAuthGuiUtils::redTextStyleSheet( QStringLiteral( "QLineEdit" ) );
100 leMasterPassCurrent->setStyleSheet( ss1 );
101 }
102 const QString ss2 = newPasswordOk ? QgsAuthGuiUtils::greenTextStyleSheet( QStringLiteral( "QLineEdit" ) )
103 : QgsAuthGuiUtils::redTextStyleSheet( QStringLiteral( "QLineEdit" ) );
104 leMasterPassNew->setStyleSheet( ss2 );
105 const QString ss3 = confirmPasswordOk ? QgsAuthGuiUtils::greenTextStyleSheet( QStringLiteral( "QLineEdit" ) )
106 : QgsAuthGuiUtils::redTextStyleSheet( QStringLiteral( "QLineEdit" ) );
107 leMasterPassNew2->setStyleSheet( ss3 );
108 buttonBox->button( QDialogButtonBox::Ok )->setEnabled( currentPasswordOk && newPasswordOk && confirmPasswordOk );
109}
static QgsAuthManager * authManager()
Returns the application's authentication manager instance.
Utility functions for use by authentication GUI widgets or standalone apps.
static QString greenTextStyleSheet(const QString &selector="*")
Green text stylesheet representing valid, trusted, etc. certificate.
static QString passwordHelperDisplayName(bool titleCase=false)
Returns a translated display name of the password helper (platform dependent).
QgsMasterPasswordResetDialog(QWidget *parent=nullptr)
bool requestMasterPasswordReset(QString *newpass, QString *oldpass, bool *keepbackup)
QgsPasswordLineEdit * oldPasswordLineEdit()
Returns the old password line edit widget.
QLineEdit subclass with built in support for showing/hiding entered password.