授权3.0

This commit is contained in:
liudunfa
2021-08-14 18:35:16 +08:00
parent 972d610b4c
commit 68f90bd2f3
11 changed files with 462 additions and 448 deletions
+6 -4
View File
@@ -33,8 +33,10 @@ BioAuthWidget::BioAuthWidget(QWidget *parent) :
bioAuth(nullptr)
{
ui->setupUi(this);
ui->btnRetry->setFlat(true);
ui->btnRetry->setVisible(false);
ui->btnMore->setVisible(false);
ui->btnRetry->setText(tr("Retry"));
//ui->btnMore->setVisible(false);
}
BioAuthWidget::~BioAuthWidget()
@@ -136,7 +138,7 @@ void BioAuthWidget::onFrameWritten(int deviceId)
void BioAuthWidget::hidePasswdButton()
{
ui->btnPasswdAuth->hide();
//ui->btnPasswdAuth->hide();
}
bool BioAuthWidget::isAuthenticating()
@@ -159,7 +161,7 @@ void BioAuthWidget::startAuth(uid_t uid, const DeviceInfo &device)
this->uid = uid;
this->device = device;
ui->lblBioDevice->setText(tr("Current Device: ") + device.device_shortname);
//ui->lblBioDevice->setText(tr("Current Device: ") + device.device_shortname);
if(bioAuth) {
bioAuth->stopAuth();
@@ -182,5 +184,5 @@ void BioAuthWidget::startAuth(uid_t uid, const DeviceInfo &device)
void BioAuthWidget::setMoreDevices(bool hasMore)
{
ui->btnMore->setVisible(hasMore);
//ui->btnMore->setVisible(hasMore);
}
+40 -72
View File
@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>404</width>
<height>376</height>
<height>282</height>
</rect>
</property>
<property name="windowTitle">
@@ -18,6 +18,12 @@
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<property name="topMargin">
<number>20</number>
</property>
<property name="bottomMargin">
<number>10</number>
</property>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
@@ -41,8 +47,8 @@
</property>
<property name="maximumSize">
<size>
<width>130</width>
<height>130</height>
<width>128</width>
<height>128</height>
</size>
</property>
<property name="text">
@@ -69,33 +75,13 @@
</layout>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::MinimumExpanding</enum>
</property>
<property name="sizeHint" stdset="0">
<widget class="QLabel" name="lblBioNotify">
<property name="minimumSize">
<size>
<width>20</width>
<height>100</height>
<width>0</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="lblBioDevice">
<property name="text">
<string/>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="lblBioNotify">
<property name="text">
<string/>
</property>
@@ -108,70 +94,52 @@
</widget>
</item>
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="bottomMargin">
<number>8</number>
</property>
<property name="sizeType">
<enum>QSizePolicy::MinimumExpanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>30</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="1">
<widget class="QPushButton" name="btnMore">
<property name="maximumSize">
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>50</width>
<height>16777215</height>
<width>40</width>
<height>20</height>
</size>
</property>
<property name="cursor">
<cursorShape>PointingHandCursor</cursorShape>
</property>
<property name="text">
<string>More</string>
</property>
</widget>
</spacer>
</item>
<item row="0" column="2">
<item>
<widget class="QPushButton" name="btnRetry">
<property name="maximumSize">
<size>
<width>50</width>
<height>16777215</height>
<width>80</width>
<height>28</height>
</size>
</property>
<property name="cursor">
<cursorShape>PointingHandCursor</cursorShape>
<property name="styleSheet">
<string notr="true">QPushButton:hover{border:none;color:#3E6CE5;}QPushButton:pressed{border:none;}
QPushButton{font-size:14px;}</string>
</property>
<property name="text">
<string>Retry</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QPushButton" name="btnPasswdAuth">
<property name="maximumSize">
<item>
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>80</width>
<height>16777215</height>
<width>40</width>
<height>20</height>
</size>
</property>
<property name="cursor">
<cursorShape>PointingHandCursor</cursorShape>
</property>
<property name="text">
<string>Password</string>
</property>
</widget>
</spacer>
</item>
</layout>
</item>
+1 -1
View File
@@ -38,7 +38,7 @@ extern int logger(char *format, ...);
static int ukui_biometric_lock = 0;
int enable_biometric_authentication(pam_handle_t *pamh);
int enable_biometric_auth_double();
/* GUI child process alive status */
static int child_alive = 1;
/* Signal handler */
+2
View File
@@ -2,6 +2,8 @@
<qresource prefix="/image">
<file>assets/arrow_down.svg</file>
<file>assets/arrow_right.svg</file>
<file>assets/hide-password.png</file>
<file>assets/show-password.png</file>
</qresource>
<qresource prefix="/qss">
<file>src/main.qss</file>
Binary file not shown.

After

Width:  |  Height:  |  Size: 335 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 582 B

+16 -14
View File
@@ -113,15 +113,17 @@ void PolkitListener::initiateAuthentication(
/* Create the polkit window */
mainWindow = new MainWindow;
mainWindow->setWindowFlags(Qt::WindowCloseButtonHint | Qt::WindowStaysOnTopHint);
mainWindow->setIcon(iconName);
mainWindow->setHeader(message);
mainWindow->setUsers(usersList);
/*
mainWindow->setDetails(subjectPid, callerPid,
actionDesc.actionId(),
actionDesc.description(),
actionDesc.vendorName(),
actionDesc.vendorUrl());
*/
/* set the position of the mainwindow */
QPoint pos = QCursor::pos();
for(auto screen : QGuiApplication::screens())
@@ -211,19 +213,19 @@ void PolkitListener::finishObtainPrivilege()
.arg(mainWindow != NULL);
if (!gainedAuthorization && !wasCancelled && (mainWindow != NULL)) {
// int deny = 0, unlock_time = 0;
// mainWindow->stopDoubleAuth();
// if(!get_pam_tally(&deny, &unlock_time)||(deny == 0 &&unlock_time == 0)) {
// if(!wasSwitchToBiometric){
// mainWindow->setAuthResult(gainedAuthorization, tr("Authentication failure, please try again."));
// }
// startAuthentication();
// return;
// }
// else {
// startAuthentication();
// return;
// }
int deny = 0, unlock_time = 0;
mainWindow->stopDoubleAuth();
if(!get_pam_tally(&deny, &unlock_time)||(deny == 0 &&unlock_time == 0)) {
if(!wasSwitchToBiometric){
mainWindow->setAuthResult(gainedAuthorization, tr("Authentication failure, please try again."));
}
startAuthentication();
return;
}
else {
startAuthentication();
return;
}
startAuthentication();
return;
+40 -2
View File
@@ -1,6 +1,11 @@
#btnCancel, #btnAuth {
min-height: 24px;
min-width: 80px;
min-height: 20px;
min-width: 28px;
font-size:14px;
font-family: PingFangSC-Regular, PingFang SC;
font-weight: 400;
line-height: 20px;
}
#btnDetails {
@@ -12,3 +17,36 @@
#lwDevices::item {
height: 30px;
}
#lblHeader{
font-size: 18px;
font-family: PingFangSC-Medium, PingFang SC;
font-weight: 500;
line-height: 25px;
}
#lblContent{
font-size: 14px;
font-family: PingFangSC-Regular, PingFang SC;
font-weight: 400;
line-height: 20px;
}
#echoModeButton {
background: transparent;
qproperty-flat: true;
margin-right: 4px;
border: none;
border-width: 0;
image: url(:/image/assets/hide-password.png);
max-width: 16px;
max-height: 16px;
margin-right: 5px;
}
#echoModeButton::checked {
image: url(:/image/assets/show-password.png);
}
+147 -21
View File
@@ -32,10 +32,12 @@
#include <pwd.h>
#include <libintl.h>
#include <locale.h>
#include "bioauthwidget.h"
#include <QHBoxLayout>
#include <QAction>
#include "generic.h"
#define _(string) gettext(string)
extern void qt_blurImage(QImage &blurImage, qreal radius, bool quality, int transposed);
MainWindow::MainWindow(QWidget *parent) :
QWidget(parent),
ui(new Ui::MainWindow),
@@ -56,8 +58,12 @@ MainWindow::MainWindow(QWidget *parent) :
widgetBioAuth = new BioAuthWidget(this);
widgetBioDevices = new BioDevicesWidget(this);
ui->formLayout->addWidget(widgetBioAuth);
ui->formLayout->addWidget(widgetBioDevices);
//ui->formLayout->addWidget(widgetBioAuth);
//ui->formLayout->addWidget(widgetBioDevices);
ui->bioAuthLayout->addWidget(widgetBioAuth);
ui->bioAuthLayout->addWidget(widgetBioDevices);
maxFailedTimes = bioDevices.getFailedTimes();
isHiddenSwitchButton = bioDevices.GetHiddenSwitchButton();
@@ -129,12 +135,15 @@ MainWindow::MainWindow(QWidget *parent) :
setStyleSheet(qssFile.readAll());
qssFile.close();
ui->cmbUsers->hide();
ui->widgetDetails->hide();
ui->btnDetails->setIcon(QIcon(":/image/assets/arrow_right.svg"));
ui->btnDetails->hide();
ui->lePassword->installEventFilter(this);
//ui->cmbUsers->hide();
//ui->widgetDetails->hide();
//ui->btnDetails->setIcon(QIcon(":/image/assets/arrow_right.svg"));
//ui->btnDetails->hide();
//ui->lePassword->installEventFilter(this);
switchWidget(UNDEFINED);
editIcon();
ui->lblContent->adjustSize();
ui->lblContent->height();
}
MainWindow::~MainWindow()
@@ -159,6 +168,52 @@ void MainWindow::closeEvent(QCloseEvent *event)
return QWidget::closeEvent(event);
}
void MainWindow::paintEvent(QPaintEvent *event)
{
Q_UNUSED(event);
QStyleOption *option = new QStyleOption();
QPainter p(this);
p.setRenderHint(QPainter::Antialiasing);
QPainterPath rectPath;
rectPath.addRoundedRect(this->rect().adjusted(0,0,0,0),0,0);
// 画一个黑底
QPixmap pixmap(this->rect().size());
pixmap.fill(Qt::transparent);
QPainter pixmapPainter(&pixmap);
pixmapPainter.setRenderHint(QPainter::Antialiasing);
pixmapPainter.setPen(Qt::transparent);
pixmapPainter.setBrush(QColor(0,0,0,100));
pixmapPainter.drawPath(rectPath);
pixmapPainter.end();
// 模糊这个黑底
QImage img = pixmap.toImage();
qt_blurImage(img, 10, false, false);
// 挖掉中心
pixmap = QPixmap::fromImage(img);
QPainter pixmapPainter2(&pixmap);
pixmapPainter2.setRenderHint(QPainter::Antialiasing);
pixmapPainter2.setCompositionMode(QPainter::CompositionMode_Clear);
pixmapPainter2.setPen(Qt::transparent);
pixmapPainter2.setBrush(Qt::transparent);
pixmapPainter2.drawPath(rectPath);
// 绘制阴影
p.drawPixmap(this->rect(), pixmap, pixmap.rect());
// 绘制一个背景
p.save();
p.fillPath(rectPath,option->palette.color(QPalette::Base));
p.restore();
//绘制一个矩形
p.setPen(Qt::red);
QRectF rect(0,290,20,20);
}
bool MainWindow::eventFilter(QObject *obj, QEvent *event)
{
if(obj == ui->lePassword){
@@ -218,7 +273,7 @@ int MainWindow::enable_biometric_authentication()
}
void MainWindow::on_btnDetails_clicked()
{
{/*
if(ui->widgetDetails->isHidden()) {
ui->widgetDetails->show();
ui->btnDetails->setIcon(QIcon(":/image/assets/arrow_down.svg"));
@@ -229,7 +284,7 @@ void MainWindow::on_btnDetails_clicked()
ui->btnDetails->setIcon(QIcon(":/image/assets/arrow_right.svg"));
// resize(width(), height() - ui->widgetDetails->height());
}
adjustSize();
adjustSize();*/
}
void MainWindow::on_btnCancel_clicked()
@@ -243,6 +298,33 @@ void MainWindow::on_btnAuth_clicked()
}
/*** pagePassword ***/
void MainWindow::editIcon()
{
m_modeButton = new QPushButton(ui->lePassword);
m_modeButton->setObjectName(QStringLiteral("echoModeButton"));
m_modeButton->setCheckable(true);
m_modeButton->setFocusPolicy(Qt::NoFocus);
m_modeButton->setCursor(Qt::PointingHandCursor);
connect(m_modeButton, &QPushButton::clicked, this, [&](bool checked){
setType(checked ? QLineEdit::Normal : QLineEdit::Password);
});
QHBoxLayout *layout = new QHBoxLayout(ui->lePassword);
//layout->setSpacing(0);
layout->addStretch();
layout->addWidget(m_modeButton);
layout->setContentsMargins(0, 0, 0, 0);
}
void MainWindow::setType(QLineEdit::EchoMode type)
{
ui->lePassword->setEchoMode(type);
if(type == 0)
m_modeButton->setChecked(true);
else
m_modeButton->setChecked(false);
}
void MainWindow::on_lePassword_returnPressed()
{
@@ -258,6 +340,13 @@ void MainWindow::on_btnBioAuth_clicked()
authMode = BIOMETRIC;
}
void MainWindow::on_returnButton_clicked()
{
widgetBioAuth->stopAuth();
accept(BIOMETRIC_IGNORE);
}
/*** end of control's slot ***/
@@ -290,12 +379,14 @@ void MainWindow::setIcon(const QString &iconName)
painter.end();
setWindowIcon(icon);
ui->lblIcon->setPixmap(icon);
//ui->lblIcon->setPixmap(icon);
}
void MainWindow::setHeader(const QString &text)
{
ui->lblHeader->setText(text);
ui->lblHeader->adjustSize();
ui->lblHeader->height();
ui->lblContent->setText(tr("An application is attempting to perform an action that requires privileges."
" Authentication is required to perform this action."));
@@ -328,8 +419,10 @@ void MainWindow::setUsers(const QStringList &usersList)
}
ui->cmbUsers->show();
ui->cmbUsers->adjustSize();
ui->cmbUsers->height();
}
/*
void MainWindow::setDetails(const QString &subPid, const QString &callerPid, const QString &actionId,
const QString &actionDesc, const QString vendorName,
const QString vendorUrl)
@@ -341,7 +434,7 @@ void MainWindow::setDetails(const QString &subPid, const QString &callerPid, con
QString vendor = QString("<a href=\"%1\">%2").arg(vendorUrl).arg(vendorName);
ui->lblVendor->setText(vendor);
}
*/
void MainWindow::setPrompt(const QString &text, bool echo)
{
QString prompt = text;
@@ -362,7 +455,9 @@ void MainWindow::setPrompt(const QString &text, bool echo)
//qDebug() << "6666";
m_timer->start();
ui->lblPrompt->setText(prompt);
ui->lePassword->clear();
ui->lePassword->setPlaceholderText(prompt);
//ui->lblMessage->setText(prompt);
ui->lePassword->setEchoMode(echo ? QLineEdit::Normal : QLineEdit::Password);
switchWidget(PASSWORD);
}
@@ -412,9 +507,14 @@ QString MainWindow::check_is_pam_message(QString text)
}
void MainWindow::setMessage(const QString &text)
void MainWindow::setMessage(const QString &text,situation situat)
{
// QString message = this->check_is_pam_message(text);
if(situat == ERROR){
ui->lblMessage->setStyleSheet("color: #F3222D;");
}else if(situat == TRUE){
ui->lblMessage->setStyleSheet("");
}
qDebug()<<"receivetext = "<<text;
if (text.indexOf("account locked") != -1 || text.indexOf("账户已锁定") != -1
|| text.indexOf("Account locked") != -1 || text.indexOf("永久锁定") != -1)
@@ -445,9 +545,9 @@ void MainWindow::setAuthResult(bool result, const QString &text)
message = tr("Authentication failed, please try again.");
if(authMode == PASSWORD)
ui->lblMessage->setText(message);
// else if(authMode == BIOMETRIC)
// ui->lblBioNotify->setText(message);
setMessage(message,ERROR);
else if(authMode == BIOMETRIC)
setMessage(message,ERROR);
switchWidget(PASSWORD);
}
@@ -599,17 +699,43 @@ void MainWindow::switchWidget(Mode mode)
switch(mode){
case PASSWORD:
setMinimumWidth(420);
setMaximumWidth(420);
setMinimumHeight(211+ui->lblHeader->height()+ui->lblContent->height());
setMaximumHeight(211+ui->lblHeader->height()+ui->lblContent->height());
ui->btnBioAuth->setStyleSheet("QPushButton{font-size:14px;}QPushButton:hover{border:none;color:#3E6CE5;}QPushButton:pressed{border:none;}");
ui->btnBioAuth->setFlat(true);
ui->widgetPasswdAuth->show();
ui->lePassword->setFocus();
ui->lePassword->setAttribute(Qt::WA_InputMethodEnabled, false);
ui->btnAuth->show();
ui->btnCancel->show();
//ui->btnBioAuth->show();
ui->lblContent->show();
ui->returnButton->hide();
//ui->cmbDevices->hide();
break;
case BIOMETRIC:
setMaximumWidth(380);
setMinimumWidth(420);
setMaximumWidth(420);
setMinimumHeight(342+ui->cmbUsers->height()+ui->lblHeader->height());
setMaximumHeight(342+ui->cmbUsers->height()+ui->lblHeader->height());
widgetBioAuth->show();
ui->btnCancel->hide();
ui->lblContent->hide();
ui->btnBioAuth->hide();
ui->returnButton->show();
ui->returnButton->setFlat(true);
ui->returnButton->setStyleSheet("QPushButton{font-size:14px;}QPushButton:hover{border:none;color:#3E6CE5;}QPushButton:pressed{border:none;}");
//ui->btnBioAuth->hide();
//ui->cmbDevices->show();
break;
case DEVICES:
widgetBioDevices->show();
widgetBioAuth->show();
break;
default:
break;
}
+10 -6
View File
@@ -23,7 +23,9 @@
#include "biometric.h"
#include "users.h"
#include "pam-tally.h"
#include <QPushButton>
#include <QLineEdit>
#include "bioauthwidget.h"
namespace Ui {
class MainWindow;
}
@@ -37,9 +39,9 @@ public:
~MainWindow();
void closeEvent(QCloseEvent *event);
bool eventFilter(QObject *obj, QEvent *event);
void paintEvent(QPaintEvent *event);
enum Mode{UNDEFINED, PASSWORD, BIOMETRIC, DEVICES};
enum situation{TRUE, ERROR};
void setIcon(const QString &iconName);
void setHeader(const QString &text);
void setUsers(const QStringList &usersList);
@@ -47,13 +49,14 @@ public:
const QString &actionId, const QString &actionDesc,
const QString vendorName, const QString vendorUrl);
void setPrompt(const QString &text, bool echo);
void setMessage(const QString &text);
void setMessage(const QString &text,situation situat = TRUE);
void setAuthResult(bool result, const QString &text="");
void clearEdit();
void switchAuthMode(Mode mode);
void setDoubleAuth(bool val);
void stopDoubleAuth();
QString check_is_pam_message(QString text);
void setType(QLineEdit::EchoMode type = QLineEdit::Password);
private:
uid_t getUid(const QString &userName);
@@ -66,12 +69,13 @@ private:
void root_unlock_countdown();
void unlock_countdown();
void editIcon();
private slots:
void on_btnDetails_clicked();
void on_lePassword_returnPressed();
void on_btnBioAuth_clicked();
void on_returnButton_clicked();
void on_cmbUsers_currentTextChanged(const QString &userName);
void on_btnCancel_clicked();
void on_btnAuth_clicked();
@@ -100,7 +104,7 @@ private:
QMap<qint32,int> m_failMap;
int maxFailedTimes;
bool isHiddenSwitchButton;
QPushButton *m_modeButton;
QTimer *m_timer;
bool isLockingFlg; //判断当前是否正在锁定倒计时
};
File diff suppressed because it is too large Load Diff