QGIS API Documentation 3.41.0-Master (fda2aa46e9a)
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 "qgslogger.h"
26#include "qgsapplication.h"
27
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::leMasterPassCurrent_textChanged );
43 connect( leMasterPassNew, &QgsPasswordLineEdit::textChanged, this, &QgsMasterPasswordResetDialog::leMasterPassNew_textChanged );
44 }
45}
46
47bool QgsMasterPasswordResetDialog::requestMasterPasswordReset( QString *newpass, QString *oldpass, bool *keepbackup )
48{
49 if ( !QgsApplication::authManager()->isDisabled() )
50 {
51 validatePasswords();
52 leMasterPassCurrent->setFocus();
53
54 const bool ok = ( exec() == QDialog::Accepted );
55 //QgsDebugMsgLevel( QStringLiteral( "exec(): %1" ).arg( ok ? "true" : "false" ), 2 );
56
57 if ( ok )
58 {
59 *newpass = leMasterPassNew->text();
60 *oldpass = leMasterPassCurrent->text();
61 *keepbackup = chkKeepBackup->isChecked();
62 return true;
63 }
64 }
65 return false;
66}
67
68void QgsMasterPasswordResetDialog::leMasterPassCurrent_textChanged( const QString &pass )
69{
70 // since this is called on every keystroke, block signals emitted during verification of password
71 QgsApplication::authManager()->blockSignals( true );
72 mPassCurOk = !pass.isEmpty();
73 QgsApplication::authManager()->blockSignals( false );
74 validatePasswords();
75}
76
77void QgsMasterPasswordResetDialog::leMasterPassNew_textChanged( const QString &pass )
78{
79 mPassNewOk = !pass.isEmpty();
80 validatePasswords();
81}
82
83void QgsMasterPasswordResetDialog::validatePasswords()
84{
85 const QString ss1 = mPassCurOk ? QgsAuthGuiUtils::greenTextStyleSheet( QStringLiteral( "QLineEdit" ) )
86 : QgsAuthGuiUtils::redTextStyleSheet( QStringLiteral( "QLineEdit" ) );
87 leMasterPassCurrent->setStyleSheet( ss1 );
88 const QString ss2 = mPassNewOk ? QgsAuthGuiUtils::greenTextStyleSheet( QStringLiteral( "QLineEdit" ) )
89 : QgsAuthGuiUtils::redTextStyleSheet( QStringLiteral( "QLineEdit" ) );
90 leMasterPassNew->setStyleSheet( ss2 );
91 buttonBox->button( QDialogButtonBox::Ok )->setEnabled( mPassCurOk && mPassNewOk );
92}
93
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.
QgsMasterPasswordResetDialog(QWidget *parent=nullptr)
bool requestMasterPasswordReset(QString *newpass, QString *oldpass, bool *keepbackup)