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