From 0a130f0034a77b5bb764a41f4832bcf224c9381f Mon Sep 17 00:00:00 2001 From: liuxinhao Date: Wed, 31 May 2023 14:29:18 +0800 Subject: [PATCH 2/2] fix(polkit-agent): Remove the restriction on polkit-agent authentication errors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 去除polkit-agent认证错误限制,错误时需要点击左下重新认证按钮重新认证.适应部分认证流程不存在prompt消息 Closes #I7961L --- src/polkit-agent/dialog.cpp | 87 +++++++++++++++--------- src/polkit-agent/dialog.h | 11 ++- src/polkit-agent/dialog.ui | 27 +++++++- translations/kiran-polkit-agent.zh_CN.ts | 25 +++++-- 4 files changed, 110 insertions(+), 40 deletions(-) diff --git a/src/polkit-agent/dialog.cpp b/src/polkit-agent/dialog.cpp index 16ca2aa..10fdbc5 100644 --- a/src/polkit-agent/dialog.cpp +++ b/src/polkit-agent/dialog.cpp @@ -58,7 +58,7 @@ Dialog::Dialog(QWidget* parent) : KiranTitlebarWindow(parent), ui(new Ui::Dialog) { -ui->setupUi(getWindowContentWidget()); + ui->setupUi(getWindowContentWidget()); resize(408, 290); initUI(); } @@ -119,24 +119,44 @@ void Dialog::initUI() layout()->setSizeConstraint(QLayout::SetFixedSize); ui->label_tips->setWordWrap(true); Kiran::StylePropertyHelper::setButtonType(ui->btn_ok, Kiran::BUTTON_Default); + Kiran::StylePropertyHelper::setButtonType(ui->btn_reauth, Kiran::BUTTON_Default); + switchButtonLayout(BUTTON_LAYOUT_NORMAL); + m_switcher = new AuthTypeSwitcher(EXPAND_DIRECTION_BOTTOM, 4, this); m_switcher->setAdjustColorToTheme(true); m_switcher->setFixedSize(QSize(42, 36)); m_switcher->setVisible(false); ui->layout_edit->addWidget(m_switcher); - connect(m_switcher, &AuthTypeSwitcher::authTypeChanged, this, &Dialog::onCurrentAuthTypeChanged); + connect(m_switcher, &AuthTypeSwitcher::authTypeChanged, this, &Dialog::onSwitcherAuthTypeChanged); connect(ui->btn_cancel, &QPushButton::clicked, this, &Dialog::onCancelClicked); connect(ui->btn_ok, &QPushButton::clicked, this, &Dialog::onOkClicked); + connect(ui->btn_reauth,&QPushButton::clicked,this,&Dialog::onReauthClicked); connect(ui->edit->lineEdit(), &QLineEdit::returnPressed, this, &Dialog::onOkClicked); connect(ui->combobox_user, QOverload::of(&QComboBox::currentIndexChanged), this, &Dialog::onCurrentUserChanged); } +void Dialog::switchButtonLayout(ButtonLayout layout) +{ + switch (layout) + { + case BUTTON_LAYOUT_NORMAL: + ui->btn_reauth->setVisible(false); + ui->btn_ok->setVisible(true); + break; + case BUTTON_LAYOUT_REAUTH: + ui->btn_reauth->setVisible(true); + ui->btn_ok->setVisible(false); + break; + default: + break; + } +} + void Dialog::startAuth(const QString& userName) { m_havePrompt = false; - m_triesCount++; if (m_authController->inAuthentication()) { @@ -171,29 +191,19 @@ void Dialog::onOkClicked() ui->btn_ok->setEnabled(false); } -void Dialog::onCurrentUserChanged(int idx) +void Dialog::onReauthClicked() { startAuth(ui->combobox_user->currentText()); } -void Dialog::onCurrentAuthTypeChanged(KADAuthType authType) +void Dialog::onCurrentUserChanged(int idx) { - QMap authTypeDesc = { - {KAD_AUTH_TYPE_FINGERPRINT, tr("fingerprint auth")}, - {KAD_AUTH_TYPE_FACE, tr("face auth")}, - {KAD_AUTH_TYPE_FINGERVEIN, tr("fingervein auth")}}; + startAuth(ui->combobox_user->currentText()); +} - ui->label_tips->setText(""); +void Dialog::onSwitcherAuthTypeChanged(KADAuthType authType) +{ m_authController->switchAuthType(authType); - ui->edit->setEnabled(false); - ui->btn_ok->setEnabled(false); - ui->edit->lineEdit()->clear(); - ui->edit->lineEdit()->setPlaceholderText(""); - - if (authTypeDesc.contains(authType)) - { - ui->edit->lineEdit()->setPlaceholderText(authTypeDesc[authType]); - } } void Dialog::onNotifyAuthMode(KADAuthMode mode) @@ -208,7 +218,29 @@ void Dialog::onSupportedAuthTypeChanged(QList authTypes) void Dialog::onNotifyAuthTypeChanged(KADAuthType authType) { - m_switcher->setCurrentAuthType(authType); + if( authType != m_switcher->getCurrentAuthType() ) + { + QSignalBlocker blocker(m_switcher); + m_switcher->setCurrentAuthType(authType); + } + + QMap authTypeDesc = { + {KAD_AUTH_TYPE_FINGERPRINT, tr("fingerprint auth")}, + {KAD_AUTH_TYPE_FACE, tr("face auth")}, + {KAD_AUTH_TYPE_FINGERVEIN, tr("fingervein auth")}, + {KAD_AUTH_TYPE_IRIS,tr("iris auth")}}; + + switchButtonLayout(BUTTON_LAYOUT_NORMAL); + ui->label_tips->setText(""); + ui->edit->setEnabled(false); + ui->btn_ok->setEnabled(false); + ui->edit->lineEdit()->clear(); + ui->edit->lineEdit()->setPlaceholderText(""); + + if (authTypeDesc.contains(authType)) + { + ui->edit->lineEdit()->setPlaceholderText(authTypeDesc[authType]); + } } void Dialog::onAuthComplete(bool success) @@ -219,21 +251,13 @@ void Dialog::onAuthComplete(bool success) this->close(); return; } - - if (m_havePrompt && (m_triesCount < MAX_ERROR_COUNT)) - { - onAuthShowMessage("Authentication error, please authenticate again.", MessageTypeInfo); - startAuth(ui->combobox_user->currentText()); - } else { - if (m_triesCount == MAX_ERROR_COUNT) - { - onAuthShowMessage("Authentication error", MessageTypeError); - } - ui->btn_ok->setEnabled(false); + onAuthShowMessage("Authentication error", MessageTypeError); + ui->edit->lineEdit()->clear(); ui->edit->setEnabled(false); + switchButtonLayout(BUTTON_LAYOUT_REAUTH); } } @@ -256,7 +280,6 @@ void Dialog::onAuthShowMessage(const QString& text, MessageType msgType) ui->label_tips->setText(tips); } - } // namespace PolkitAgent } // namespace SessionGuard } // namespace Kiran \ No newline at end of file diff --git a/src/polkit-agent/dialog.h b/src/polkit-agent/dialog.h index fe56251..7fbb85d 100644 --- a/src/polkit-agent/dialog.h +++ b/src/polkit-agent/dialog.h @@ -64,6 +64,11 @@ public: class Dialog : public KiranTitlebarWindow { Q_OBJECT + enum ButtonLayout + { + BUTTON_LAYOUT_NORMAL, + BUTTON_LAYOUT_REAUTH + }; public: explicit Dialog(QWidget* parent = nullptr); ~Dialog(); @@ -77,14 +82,16 @@ signals: private: void initUI(); + void switchButtonLayout(ButtonLayout layout); bool setAuthInfo(const AuthInfo& authInfo); void startAuth(const QString& userName); private slots: void onCancelClicked(); void onOkClicked(); + void onReauthClicked(); void onCurrentUserChanged(int idx); - void onCurrentAuthTypeChanged(KADAuthType authType); + void onSwitcherAuthTypeChanged(KADAuthType authType); void onNotifyAuthMode(KADAuthMode mode); void onSupportedAuthTypeChanged(QList authTypes); @@ -102,7 +109,7 @@ private: AuthController* m_authController; AuthTypeSwitcher* m_switcher; bool m_havePrompt = false; - int m_triesCount = 0; + ButtonLayout m_buttonLayout = BUTTON_LAYOUT_NORMAL; }; } // namespace PolkitAgent } // namespace SessionGuard diff --git a/src/polkit-agent/dialog.ui b/src/polkit-agent/dialog.ui index 74120eb..b1d4994 100644 --- a/src/polkit-agent/dialog.ui +++ b/src/polkit-agent/dialog.ui @@ -6,7 +6,7 @@ 0 0 - 407 + 410 234 @@ -214,6 +214,31 @@ + + + + + 0 + 0 + + + + + 110 + 40 + + + + + 110 + 40 + + + + Recertification + + + diff --git a/translations/kiran-polkit-agent.zh_CN.ts b/translations/kiran-polkit-agent.zh_CN.ts index 97ce7f8..ae75cc2 100644 --- a/translations/kiran-polkit-agent.zh_CN.ts +++ b/translations/kiran-polkit-agent.zh_CN.ts @@ -41,11 +41,16 @@ + Recertification + 重新认证 + + + Ok 确认 - + Cancel 取消 @@ -69,7 +74,7 @@ Kiran::SessionGuard::AuthController - + Failed to authenticate 认证失败 @@ -96,6 +101,16 @@ finger vein auth 指静脉认证 + + + iris auth + 虹膜认证 + + + + ukey auth + UKey认证 + Kiran::SessionGuard::PolkitAgent::Dialog @@ -105,17 +120,17 @@ 认证 - + fingerprint auth 指纹认证 - + face auth 人脸认证 - + fingervein auth 指静脉认证 -- 2.33.0