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