QGIS API Documentation 4.1.0-Master (5bf3c20f3c9)
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, [] { QgsHelp::openHelp( u"auth_system/auth_overview.html#master-password"_s ); } );
49
50 if ( QgsApplication::authManager()->sqliteDatabasePath().isEmpty() )
51 {
52 chkKeepBackup->hide();
53 }
54
55 QString warning = tr( "The authentication store will be re-encrypted using the new password." );
56 if ( QgsApplication::authManager()->passwordHelperEnabled() )
57 {
58 warning += u"<p><b>%1</b></p>"_s.arg( tr( "The new password will automatically be stored in the system %1." ).arg( QgsAuthManager::passwordHelperDisplayName() ) );
59 }
60
61 lblWarning->setText( warning );
62 }
63}
64
69
70bool QgsMasterPasswordResetDialog::requestMasterPasswordReset( QString *newpass, QString *oldpass, bool *keepbackup )
71{
72 if ( !QgsApplication::authManager()->isDisabled() )
73 {
74 validatePasswords();
75 leMasterPassCurrent->setFocus();
76
77 const bool ok = ( exec() == QDialog::Accepted );
78 //QgsDebugMsgLevel( u"exec(): %1"_s.arg( ok ? "true" : "false" ), 2 );
79
80 if ( ok )
81 {
82 *newpass = leMasterPassNew->text();
83 *oldpass = leMasterPassCurrent->text();
84 *keepbackup = !chkKeepBackup->isHidden() && chkKeepBackup->isChecked();
85 return true;
86 }
87 }
88 return false;
89}
90
91void QgsMasterPasswordResetDialog::validatePasswords()
92{
93 const QString currentPassword = leMasterPassCurrent->text();
94 const QString newPassword = leMasterPassNew->text();
95 const QString confirmPassword = leMasterPassNew2->text();
96
97 const bool currentPasswordOk = !currentPassword.isEmpty();
98 const bool newPasswordOk = !newPassword.isEmpty();
99 const bool confirmPasswordOk = !confirmPassword.isEmpty() && confirmPassword == newPassword;
100
101 if ( leMasterPassCurrent->isEnabled() )
102 {
103 const QString ss1 = currentPasswordOk ? QgsAuthGuiUtils::greenTextStyleSheet( u"QLineEdit"_s ) : QgsAuthGuiUtils::redTextStyleSheet( u"QLineEdit"_s );
104 leMasterPassCurrent->setStyleSheet( ss1 );
105 }
106 const QString ss2 = newPasswordOk ? QgsAuthGuiUtils::greenTextStyleSheet( u"QLineEdit"_s ) : QgsAuthGuiUtils::redTextStyleSheet( u"QLineEdit"_s );
107 leMasterPassNew->setStyleSheet( ss2 );
108 const QString ss3 = confirmPasswordOk ? QgsAuthGuiUtils::greenTextStyleSheet( u"QLineEdit"_s ) : QgsAuthGuiUtils::redTextStyleSheet( u"QLineEdit"_s );
109 leMasterPassNew2->setStyleSheet( ss3 );
110 buttonBox->button( QDialogButtonBox::Ok )->setEnabled( currentPasswordOk && newPasswordOk && confirmPasswordOk );
111}
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.