[users] Remove most remaining business logic from the Page
- report password status from config - tie config-value of fields to the text-boxes
This commit is contained in:
parent
34946ecdee
commit
5db4195b7e
@ -112,16 +112,25 @@ UsersPage::UsersPage( Config* config, QWidget* parent )
|
|||||||
ui->checkBoxValidatePassword->setChecked( m_config->requireStrongPasswords() );
|
ui->checkBoxValidatePassword->setChecked( m_config->requireStrongPasswords() );
|
||||||
|
|
||||||
// Connect signals and slots
|
// Connect signals and slots
|
||||||
connect( ui->textBoxUserPassword, &QLineEdit::textChanged, this, &UsersPage::onPasswordTextChanged );
|
ui->textBoxUserPassword->setText( config->userPassword() );
|
||||||
connect( ui->textBoxUserVerifiedPassword, &QLineEdit::textChanged, this, &UsersPage::onPasswordTextChanged );
|
connect( ui->textBoxUserPassword, &QLineEdit::textChanged, config, &Config::setUserPassword );
|
||||||
connect( ui->textBoxRootPassword, &QLineEdit::textChanged, this, &UsersPage::onRootPasswordTextChanged );
|
connect( config, &Config::userPasswordChanged, ui->textBoxUserPassword, &QLineEdit::setText );
|
||||||
connect( ui->textBoxVerifiedRootPassword, &QLineEdit::textChanged, this, &UsersPage::onRootPasswordTextChanged );
|
ui->textBoxUserVerifiedPassword->setText( config->userPasswordSecondary() );
|
||||||
connect( ui->checkBoxValidatePassword, &QCheckBox::stateChanged, this, [this]( int ) {
|
connect( ui->textBoxUserVerifiedPassword, &QLineEdit::textChanged, config, &Config::setUserPasswordSecondary );
|
||||||
onPasswordTextChanged( ui->textBoxUserPassword->text() );
|
connect( config, &Config::userPasswordSecondaryChanged, ui->textBoxUserVerifiedPassword, &QLineEdit::setText );
|
||||||
onRootPasswordTextChanged( ui->textBoxRootPassword->text() );
|
connect( config, &Config::userPasswordStatusChanged, this, &UsersPage::reportUserPasswordStatus );
|
||||||
checkReady( isReady() );
|
|
||||||
|
ui->textBoxRootPassword->setText( config->rootPassword() );
|
||||||
|
connect( ui->textBoxRootPassword, &QLineEdit::textChanged, config, &Config::setRootPassword );
|
||||||
|
connect( config, &Config::rootPasswordChanged, ui->textBoxRootPassword, &QLineEdit::setText );
|
||||||
|
ui->textBoxVerifiedRootPassword->setText( config->rootPasswordSecondary() );
|
||||||
|
connect( ui->textBoxVerifiedRootPassword, &QLineEdit::textChanged, config, &Config::setRootPasswordSecondary );
|
||||||
|
connect( config, &Config::rootPasswordSecondaryChanged, ui->textBoxVerifiedRootPassword, &QLineEdit::setText );
|
||||||
|
connect( config, &Config::rootPasswordStatusChanged, this, &UsersPage::reportRootPasswordStatus );
|
||||||
|
|
||||||
|
connect( ui->checkBoxValidatePassword, &QCheckBox::stateChanged, this, [this]( int checked ) {
|
||||||
|
m_config->setRequireStrongPasswords( checked != Qt::Unchecked );
|
||||||
} );
|
} );
|
||||||
connect( ui->checkBoxReusePassword, &QCheckBox::stateChanged, this, &UsersPage::onReuseUserPasswordChanged );
|
|
||||||
|
|
||||||
connect( ui->textBoxFullName, &QLineEdit::textEdited, config, &Config::setFullName );
|
connect( ui->textBoxFullName, &QLineEdit::textEdited, config, &Config::setFullName );
|
||||||
connect( config, &Config::fullNameChanged, this, &UsersPage::onFullNameTextEdited );
|
connect( config, &Config::fullNameChanged, this, &UsersPage::onFullNameTextEdited );
|
||||||
@ -145,6 +154,7 @@ UsersPage::UsersPage( Config* config, QWidget* parent )
|
|||||||
m_config->setReuseUserPasswordForRoot( checked != Qt::Unchecked );
|
m_config->setReuseUserPasswordForRoot( checked != Qt::Unchecked );
|
||||||
} );
|
} );
|
||||||
connect( config, &Config::reuseUserPasswordForRootChanged, ui->checkBoxReusePassword, &QCheckBox::setChecked );
|
connect( config, &Config::reuseUserPasswordForRootChanged, ui->checkBoxReusePassword, &QCheckBox::setChecked );
|
||||||
|
connect( ui->checkBoxReusePassword, &QCheckBox::stateChanged, this, &UsersPage::onReuseUserPasswordChanged );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( m_config->permitWeakPasswords() )
|
if ( m_config->permitWeakPasswords() )
|
||||||
@ -181,11 +191,11 @@ UsersPage::retranslate()
|
|||||||
"use this computer, you can create multiple "
|
"use this computer, you can create multiple "
|
||||||
"accounts after installation.</small>" ) );
|
"accounts after installation.</small>" ) );
|
||||||
}
|
}
|
||||||
// Re-do password checks (with output messages) as well.
|
|
||||||
// .. the password-checking methods get their values from the text boxes,
|
const auto up = m_config->userPasswordStatus();
|
||||||
// not from their parameters.
|
reportUserPasswordStatus( up.first, up.second );
|
||||||
onPasswordTextChanged( QString() );
|
const auto rp = m_config->rootPasswordStatus();
|
||||||
onRootPasswordTextChanged( QString() );
|
reportRootPasswordStatus( rp.first, rp.second );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -221,8 +231,10 @@ void
|
|||||||
UsersPage::onActivate()
|
UsersPage::onActivate()
|
||||||
{
|
{
|
||||||
ui->textBoxFullName->setFocus();
|
ui->textBoxFullName->setFocus();
|
||||||
onPasswordTextChanged( QString() );
|
const auto up = m_config->userPasswordStatus();
|
||||||
onRootPasswordTextChanged( QString() );
|
reportUserPasswordStatus( up.first, up.second );
|
||||||
|
const auto rp = m_config->rootPasswordStatus();
|
||||||
|
reportRootPasswordStatus( rp.first, rp.second );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -247,54 +259,43 @@ UsersPage::reportHostNameStatus( const QString& status )
|
|||||||
emit checkReady( isReady() );
|
emit checkReady( isReady() );
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
static inline void
|
||||||
UsersPage::checkPasswordAcceptance( Password p, QLabel* badge, QLabel* message )
|
passwordStatus( QLabel* iconLabel, QLabel* messageLabel, int validity, const QString& message )
|
||||||
{
|
{
|
||||||
QString pw1 = p == Password::User ? m_config->userPassword() : m_config->rootPassword();
|
switch ( validity )
|
||||||
QString pw2 = p == Password::User ? m_config->userPasswordSecondary() : m_config->rootPasswordSecondary();
|
|
||||||
|
|
||||||
if ( pw1 != pw2 )
|
|
||||||
{
|
{
|
||||||
labelError( badge, message, tr( "Your passwords do not match!" ), Badness::Fatal );
|
case Config::PasswordValidity::Valid:
|
||||||
return false;
|
messageLabel->clear();
|
||||||
}
|
iconLabel->setPixmap(
|
||||||
else
|
CalamaresUtils::defaultPixmap( CalamaresUtils::Yes, CalamaresUtils::Original, messageLabel->size() ) );
|
||||||
{
|
break;
|
||||||
QString s;
|
case Config::PasswordValidity::Weak:
|
||||||
bool ok = m_config->isPasswordAcceptable( pw1, s );
|
messageLabel->setText( message );
|
||||||
if ( !ok )
|
iconLabel->setPixmap( CalamaresUtils::defaultPixmap(
|
||||||
{
|
CalamaresUtils::StatusWarning, CalamaresUtils::Original, messageLabel->size() ) );
|
||||||
labelError( badge, message, s, Badness::Fatal );
|
break;
|
||||||
}
|
case Config::PasswordValidity::Invalid:
|
||||||
else if ( !s.isEmpty() )
|
default:
|
||||||
{
|
messageLabel->setText( message );
|
||||||
labelError( badge, message, s, Badness::Warning );
|
iconLabel->setPixmap( CalamaresUtils::defaultPixmap(
|
||||||
}
|
CalamaresUtils::StatusError, CalamaresUtils::Original, messageLabel->size() ) );
|
||||||
else
|
break;
|
||||||
{
|
|
||||||
labelOk( badge, message );
|
|
||||||
}
|
|
||||||
return ok;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
UsersPage::onPasswordTextChanged( const QString& )
|
UsersPage::reportRootPasswordStatus( int validity, const QString& message )
|
||||||
{
|
{
|
||||||
m_readyPassword = checkPasswordAcceptance( Password::User, ui->labelUserPassword,
|
passwordStatus( ui->labelRootPassword, ui->labelRootPasswordError, validity, message );
|
||||||
ui->labelUserPasswordError );
|
|
||||||
|
|
||||||
emit checkReady( isReady() );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
UsersPage::onRootPasswordTextChanged( const QString& )
|
UsersPage::reportUserPasswordStatus( int validity, const QString& message )
|
||||||
{
|
{
|
||||||
m_readyRootPassword = checkPasswordAcceptance( Password::Root, ui->labelRootPassword,
|
passwordStatus( ui->labelUserPassword, ui->labelUserPasswordError, validity, message );
|
||||||
ui->labelRootPasswordError );
|
|
||||||
emit checkReady( isReady() );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
UsersPage::onReuseUserPasswordChanged( const int checked )
|
UsersPage::onReuseUserPasswordChanged( const int checked )
|
||||||
{
|
{
|
||||||
|
@ -52,24 +52,14 @@ protected slots:
|
|||||||
void onFullNameTextEdited( const QString& );
|
void onFullNameTextEdited( const QString& );
|
||||||
void reportLoginNameStatus( const QString& );
|
void reportLoginNameStatus( const QString& );
|
||||||
void reportHostNameStatus( const QString& );
|
void reportHostNameStatus( const QString& );
|
||||||
void onPasswordTextChanged( const QString& );
|
|
||||||
void onRootPasswordTextChanged( const QString& );
|
|
||||||
void onReuseUserPasswordChanged( const int );
|
void onReuseUserPasswordChanged( const int );
|
||||||
|
void reportUserPasswordStatus( int, const QString& );
|
||||||
|
void reportRootPasswordStatus( int, const QString& );
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void checkReady( bool );
|
void checkReady( bool );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/// @brief Which password are we talking about? (for checkPasswordAcceptance())
|
|
||||||
enum class Password { Root, User };
|
|
||||||
/** @brief Is the password acceptable?
|
|
||||||
*
|
|
||||||
* Checks the two copies of the password and places error messages in the
|
|
||||||
* given QLabels. Returns true (and clears the error messages) if the
|
|
||||||
* password is acceptable.
|
|
||||||
*/
|
|
||||||
bool checkPasswordAcceptance( Password p, QLabel* badge, QLabel* message );
|
|
||||||
|
|
||||||
void retranslate();
|
void retranslate();
|
||||||
|
|
||||||
Ui::Page_UserSetup* ui;
|
Ui::Page_UserSetup* ui;
|
||||||
|
Loading…
Reference in New Issue
Block a user