From d584a96335bc5564aec9be7a82fec00dc1f7c530 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 28 Aug 2020 22:19:26 +0200 Subject: [PATCH 1/4] [users] Improve naming of widget --- src/modules/users/UsersPage.cpp | 10 +++++----- src/modules/users/page_usersetup.ui | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/modules/users/UsersPage.cpp b/src/modules/users/UsersPage.cpp index 8059b02e1..9141ebb4c 100644 --- a/src/modules/users/UsersPage.cpp +++ b/src/modules/users/UsersPage.cpp @@ -87,8 +87,8 @@ UsersPage::UsersPage( Config* config, QWidget* parent ) ui->checkBoxReusePassword->setVisible( m_config->writeRootPassword() ); ui->checkBoxReusePassword->setChecked( m_config->reuseUserPasswordForRoot() ); - ui->checkBoxValidatePassword->setVisible( m_config->permitWeakPasswords() ); - ui->checkBoxValidatePassword->setChecked( m_config->requireStrongPasswords() ); + ui->checkBoxRequireStrongPassword->setVisible( m_config->permitWeakPasswords() ); + ui->checkBoxRequireStrongPassword->setChecked( m_config->requireStrongPasswords() ); // Connect signals and slots ui->textBoxUserPassword->setText( config->userPassword() ); @@ -107,7 +107,7 @@ UsersPage::UsersPage( Config* config, QWidget* parent ) connect( config, &Config::rootPasswordSecondaryChanged, ui->textBoxVerifiedRootPassword, &QLineEdit::setText ); connect( config, &Config::rootPasswordStatusChanged, this, &UsersPage::reportRootPasswordStatus ); - connect( ui->checkBoxValidatePassword, &QCheckBox::stateChanged, this, [this]( int checked ) { + connect( ui->checkBoxRequireStrongPassword, &QCheckBox::stateChanged, this, [this]( int checked ) { m_config->setRequireStrongPasswords( checked != Qt::Unchecked ); } ); @@ -138,10 +138,10 @@ UsersPage::UsersPage( Config* config, QWidget* parent ) if ( m_config->permitWeakPasswords() ) { - connect( ui->checkBoxValidatePassword, &QCheckBox::stateChanged, this, [this]( int checked ) { + connect( ui->checkBoxRequireStrongPassword, &QCheckBox::stateChanged, this, [this]( int checked ) { m_config->setRequireStrongPasswords( checked != Qt::Unchecked ); } ); - connect( config, &Config::requireStrongPasswordsChanged, ui->checkBoxValidatePassword, &QCheckBox::setChecked ); + connect( config, &Config::requireStrongPasswordsChanged, ui->checkBoxRequireStrongPassword, &QCheckBox::setChecked ); } CALAMARES_RETRANSLATE_SLOT( &UsersPage::retranslate ) diff --git a/src/modules/users/page_usersetup.ui b/src/modules/users/page_usersetup.ui index e03526a11..ba1c0bc7d 100644 --- a/src/modules/users/page_usersetup.ui +++ b/src/modules/users/page_usersetup.ui @@ -450,7 +450,7 @@ SPDX-License-Identifier: GPL-3.0-or-later - + When this box is checked, password-strength checking is done and you will not be able to use a weak password. From 15b5ef467e96356fa0db3c44a2f0aa28e6f813d7 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 28 Aug 2020 22:23:36 +0200 Subject: [PATCH 2/4] [users] Hook up strong- and reuse- password checkboxes - setup the visibility and initial checked-state of the reuse-user- password-for-root near where it gets connected; do similar for the require-strong-password - squash the lambda slot into the regular slot: no sense in connecting twice to the same signal with the same receiver. - only connect config->ui once - only connect at all if the setting is visible (e.g. when weak passwords are allowed for the require-strong checkbox, or when root's password will be written for the reuse-password) --- src/modules/users/UsersPage.cpp | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/src/modules/users/UsersPage.cpp b/src/modules/users/UsersPage.cpp index 9141ebb4c..220b0fa07 100644 --- a/src/modules/users/UsersPage.cpp +++ b/src/modules/users/UsersPage.cpp @@ -84,12 +84,6 @@ UsersPage::UsersPage( Config* config, QWidget* parent ) { ui->setupUi( this ); - ui->checkBoxReusePassword->setVisible( m_config->writeRootPassword() ); - ui->checkBoxReusePassword->setChecked( m_config->reuseUserPasswordForRoot() ); - - ui->checkBoxRequireStrongPassword->setVisible( m_config->permitWeakPasswords() ); - ui->checkBoxRequireStrongPassword->setChecked( m_config->requireStrongPasswords() ); - // Connect signals and slots ui->textBoxUserPassword->setText( config->userPassword() ); connect( ui->textBoxUserPassword, &QLineEdit::textChanged, config, &Config::setUserPassword ); @@ -107,10 +101,6 @@ UsersPage::UsersPage( Config* config, QWidget* parent ) connect( config, &Config::rootPasswordSecondaryChanged, ui->textBoxVerifiedRootPassword, &QLineEdit::setText ); connect( config, &Config::rootPasswordStatusChanged, this, &UsersPage::reportRootPasswordStatus ); - connect( ui->checkBoxRequireStrongPassword, &QCheckBox::stateChanged, this, [this]( int checked ) { - m_config->setRequireStrongPasswords( checked != Qt::Unchecked ); - } ); - connect( ui->textBoxFullName, &QLineEdit::textEdited, config, &Config::setFullName ); connect( config, &Config::fullNameChanged, this, &UsersPage::onFullNameTextEdited ); @@ -127,21 +117,23 @@ UsersPage::UsersPage( Config* config, QWidget* parent ) } ); connect( config, &Config::autoLoginChanged, ui->checkBoxDoAutoLogin, &QCheckBox::setChecked ); + ui->checkBoxReusePassword->setVisible( m_config->writeRootPassword() ); + ui->checkBoxReusePassword->setChecked( m_config->reuseUserPasswordForRoot() ); if ( m_config->writeRootPassword() ) { - connect( ui->checkBoxReusePassword, &QCheckBox::stateChanged, this, [this]( int checked ) { - m_config->setReuseUserPasswordForRoot( checked != Qt::Unchecked ); - } ); connect( config, &Config::reuseUserPasswordForRootChanged, ui->checkBoxReusePassword, &QCheckBox::setChecked ); connect( ui->checkBoxReusePassword, &QCheckBox::stateChanged, this, &UsersPage::onReuseUserPasswordChanged ); } + ui->checkBoxRequireStrongPassword->setVisible( m_config->permitWeakPasswords() ); + ui->checkBoxRequireStrongPassword->setChecked( m_config->requireStrongPasswords() ); if ( m_config->permitWeakPasswords() ) { connect( ui->checkBoxRequireStrongPassword, &QCheckBox::stateChanged, this, [this]( int checked ) { m_config->setRequireStrongPasswords( checked != Qt::Unchecked ); } ); - connect( config, &Config::requireStrongPasswordsChanged, ui->checkBoxRequireStrongPassword, &QCheckBox::setChecked ); + connect( + config, &Config::requireStrongPasswordsChanged, ui->checkBoxRequireStrongPassword, &QCheckBox::setChecked ); } CALAMARES_RETRANSLATE_SLOT( &UsersPage::retranslate ) @@ -241,6 +233,8 @@ UsersPage::reportUserPasswordStatus( int validity, const QString& message ) void UsersPage::onReuseUserPasswordChanged( const int checked ) { + // Pass the change on to config + m_config->setReuseUserPasswordForRoot( checked != Qt::Unchecked ); /* When "reuse" is checked, hide the fields for explicitly * entering the root password. However, if we're going to * disable the root password anyway, hide them all regardless of From d7dc48d201ed7d50b94606764d270d75c4ddc84a Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 28 Aug 2020 23:07:54 +0200 Subject: [PATCH 3/4] [users] Add now-obvious missed initialization - start the checkbox off in the state from config --- src/modules/users/UsersPage.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/modules/users/UsersPage.cpp b/src/modules/users/UsersPage.cpp index 220b0fa07..6ea03f8ef 100644 --- a/src/modules/users/UsersPage.cpp +++ b/src/modules/users/UsersPage.cpp @@ -112,6 +112,7 @@ UsersPage::UsersPage( Config* config, QWidget* parent ) connect( config, &Config::loginNameChanged, ui->textBoxLoginName, &QLineEdit::setText ); connect( config, &Config::loginNameStatusChanged, this, &UsersPage::reportLoginNameStatus ); + ui->checkBoxDoAutoLogin->setChecked( m_config->doAutoLogin() ); connect( ui->checkBoxDoAutoLogin, &QCheckBox::stateChanged, this, [this]( int checked ) { m_config->setAutoLogin( checked != Qt::Unchecked ); } ); From ec0b68084f7dabc3e4e9eef4fdae44453562b484 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 28 Aug 2020 23:20:02 +0200 Subject: [PATCH 4/4] [users] Refactor setting GS - both changing the autologin and changing the user (login) name affect global storage, and both may need to change the autologin username; split it into a free function. - the fullname change was bypassing the login in changing the login name, **but** then it needs a back-workaround to keep the "custom" setting off (when custom is off, auto-fill username and hostname is active). - after loading the config, fill GS already. - when finalizing GS, get the autologin settings again. --- src/modules/users/Config.cpp | 60 +++++++++++++++++++++--------------- 1 file changed, 35 insertions(+), 25 deletions(-) diff --git a/src/modules/users/Config.cpp b/src/modules/users/Config.cpp index 5ce8c8ed1..d0f573286 100644 --- a/src/modules/users/Config.cpp +++ b/src/modules/users/Config.cpp @@ -30,6 +30,30 @@ static const QRegExp HOSTNAME_RX( "^[a-zA-Z0-9][-a-zA-Z0-9_]*$" ); static constexpr const int HOSTNAME_MIN_LENGTH = 2; static constexpr const int HOSTNAME_MAX_LENGTH = 63; +static void +updateGSAutoLogin( bool doAutoLogin, const QString& login ) +{ + Calamares::GlobalStorage* gs = Calamares::JobQueue::instance()->globalStorage(); + + if ( doAutoLogin && !login.isEmpty() ) + { + gs->insert( "autologinUser", login ); + } + else + { + gs->remove( "autologinUser" ); + } + + if ( login.isEmpty() ) + { + gs->remove( "username" ); + } + else + { + gs->insert( "username", login ); + } +} + const NamedEnumTable< HostNameAction >& hostNameActionNames() { @@ -110,15 +134,7 @@ Config::setLoginName( const QString& login ) { if ( login != m_loginName ) { - Calamares::GlobalStorage* gs = Calamares::JobQueue::instance()->globalStorage(); - if ( login.isEmpty() ) - { - gs->remove( "username" ); - } - else - { - gs->insert( "username", login ); - } + updateGSAutoLogin( doAutoLogin(), login ); m_customLoginName = !login.isEmpty(); m_loginName = login; @@ -330,9 +346,9 @@ Config::setFullName( const QString& name ) QString login = makeLoginNameSuggestion( cleanParts ); if ( !login.isEmpty() && login != m_loginName ) { - m_loginName = login; - emit loginNameChanged( login ); - emit loginNameStatusChanged( loginNameStatus() ); + setLoginName( login ); + // It's **still** not custom, though setLoginName() sets that + m_customLoginName = false; } } if ( !m_customHostName ) @@ -340,9 +356,9 @@ Config::setFullName( const QString& name ) QString hostname = makeHostnameSuggestion( cleanParts ); if ( !hostname.isEmpty() && hostname != m_hostName ) { - m_hostName = hostname; - emit hostNameChanged( hostname ); - emit hostNameStatusChanged( hostNameStatus() ); + setHostName( hostname ); + // Still not custom + m_customHostName = false; } } } @@ -353,15 +369,7 @@ Config::setAutoLogin( bool b ) { if ( b != m_doAutoLogin ) { - Calamares::GlobalStorage* gs = Calamares::JobQueue::instance()->globalStorage(); - if ( b ) - { - gs->insert( "autologinUser", loginName() ); - } - else - { - gs->remove( "autologinUser" ); - } + updateGSAutoLogin( b, loginName() ); m_doAutoLogin = b; emit autoLoginChanged( b ); } @@ -700,14 +708,16 @@ Config::setConfigurationMap( const QVariantMap& configurationMap ) } std::sort( m_passwordChecks.begin(), m_passwordChecks.end() ); + updateGSAutoLogin( doAutoLogin(), loginName() ); checkReady(); } void Config::finalizeGlobalStorage() const { - Calamares::GlobalStorage* gs = Calamares::JobQueue::instance()->globalStorage(); + updateGSAutoLogin( doAutoLogin(), loginName() ); + Calamares::GlobalStorage* gs = Calamares::JobQueue::instance()->globalStorage(); if ( writeRootPassword() ) { gs->insert( "reuseRootPassword", reuseUserPasswordForRoot() );