QGIS API Documentation 3.99.0-Master (357b655ed83)
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
19#include "qgsapplication.h"
20#include "qgsauthguiutils.h"
21#include "qgsauthmanager.h"
22#include "qgshelp.h"
23
24#include <QLineEdit>
25#include <QPushButton>
26#include <QString>
27
28#include "moc_qgsauthmasterpassresetdialog.cpp"
29
30using namespace Qt::StringLiterals;
31
33 : QDialog( parent )
34{
35 if ( QgsApplication::authManager()->isDisabled() )
36 {
37 mAuthNotifyLayout = new QVBoxLayout;
38 this->setLayout( mAuthNotifyLayout );
39 mAuthNotify = new QLabel( QgsApplication::authManager()->disabledMessage(), this );
40 mAuthNotifyLayout->addWidget( mAuthNotify );
41 }
42 else
43 {
44 setupUi( this );
45 connect( leMasterPassCurrent, &QgsPasswordLineEdit::textChanged, this, &QgsMasterPasswordResetDialog::validatePasswords );
46 connect( leMasterPassNew, &QgsPasswordLineEdit::textChanged, this, &QgsMasterPasswordResetDialog::validatePasswords );
47 connect( leMasterPassNew2, &QgsPasswordLineEdit::textChanged, this, &QgsMasterPasswordResetDialog::validatePasswords );
48 connect( buttonBox, &QDialogButtonBox::helpRequested, this, [] {
49 QgsHelp::openHelp( u"auth_system/auth_overview.html#master-password"_s );
50 } );
51
52 if ( QgsApplication::authManager()->sqliteDatabasePath().isEmpty() )
53 {
54 chkKeepBackup->hide();
55 }
56
57 QString warning = tr( "The authentication store will be re-encrypted using the new password." );
58 if ( QgsApplication::authManager()->passwordHelperEnabled() )
59 {
60 warning += u"<p><b>%1</b></p>"_s.arg( tr( "The new password will automatically be stored in the system %1." ).arg( QgsAuthManager::passwordHelperDisplayName() ) );
61 }
62
63 lblWarning->setText( warning );
64 }
65}
66
71
72bool QgsMasterPasswordResetDialog::requestMasterPasswordReset( QString *newpass, QString *oldpass, bool *keepbackup )
73{
74 if ( !QgsApplication::authManager()->isDisabled() )
75 {
76 validatePasswords();
77 leMasterPassCurrent->setFocus();
78
79 const bool ok = ( exec() == QDialog::Accepted );
80 //QgsDebugMsgLevel( u"exec(): %1"_s.arg( ok ? "true" : "false" ), 2 );
81
82 if ( ok )
83 {
84 *newpass = leMasterPassNew->text();
85 *oldpass = leMasterPassCurrent->text();
86 *keepbackup = !chkKeepBackup->isHidden() && chkKeepBackup->isChecked();
87 return true;
88 }
89 }
90 return false;
91}
92
93void QgsMasterPasswordResetDialog::validatePasswords()
94{
95 const QString currentPassword = leMasterPassCurrent->text();
96 const QString newPassword = leMasterPassNew->text();
97 const QString confirmPassword = leMasterPassNew2->text();
98
99 const bool currentPasswordOk = !currentPassword.isEmpty();
100 const bool newPasswordOk = !newPassword.isEmpty();
101 const bool confirmPasswordOk = !confirmPassword.isEmpty() && confirmPassword == newPassword;
102
103 if ( leMasterPassCurrent->isEnabled() )
104 {
105 const QString ss1 = currentPasswordOk ? QgsAuthGuiUtils::greenTextStyleSheet( u"QLineEdit"_s )
106 : QgsAuthGuiUtils::redTextStyleSheet( u"QLineEdit"_s );
107 leMasterPassCurrent->setStyleSheet( ss1 );
108 }
109 const QString ss2 = newPasswordOk ? QgsAuthGuiUtils::greenTextStyleSheet( u"QLineEdit"_s )
110 : QgsAuthGuiUtils::redTextStyleSheet( u"QLineEdit"_s );
111 leMasterPassNew->setStyleSheet( ss2 );
112 const QString ss3 = confirmPasswordOk ? QgsAuthGuiUtils::greenTextStyleSheet( u"QLineEdit"_s )
113 : QgsAuthGuiUtils::redTextStyleSheet( u"QLineEdit"_s );
114 leMasterPassNew2->setStyleSheet( ss3 );
115 buttonBox->button( QDialogButtonBox::Ok )->setEnabled( currentPasswordOk && newPasswordOk && confirmPasswordOk );
116}
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).
static void openHelp(const QString &key)
Opens help topic for the given help key using default system web browser.
Definition qgshelp.cpp:41
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 the entered password.