Skip to content

Commit

Permalink
Fix certification prompts and some other bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
liuyuanpeng committed Aug 13, 2019
1 parent 943b637 commit ef470f6
Show file tree
Hide file tree
Showing 11 changed files with 122 additions and 25 deletions.
31 changes: 31 additions & 0 deletions BiometricAuth/biometricproxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,37 @@ QDBusPendingCall BiometricProxy::Identify(int drvid, int uid, int indexStart, in
return asyncCallWithArgumentList(QStringLiteral("Identify"), argList);
}

int BiometricProxy::GetFeatureCount(int uid, int indexStart, int indexEnd)
{
QDBusMessage result = call(QStringLiteral("GetDevList"));
if(result.type() == QDBusMessage::ErrorMessage)
{
qWarning() << "GetDevList error:" << result.errorMessage();
return 0;
}
auto dbusArg = result.arguments().at(1).value<QDBusArgument>();
QList<QVariant> variantList;
dbusArg >> variantList;
int res = 0;
for(int i = 0; i < variantList.size(); i++)
{

DeviceInfoPtr pDeviceInfo = std::make_shared<DeviceInfo>();

auto arg = variantList.at(i).value<QDBusArgument>();
arg >> *pDeviceInfo;

QDBusMessage FeatureResult = call(QStringLiteral("GetFeatureList"),pDeviceInfo->id,uid,indexStart,indexEnd);
if(FeatureResult.type() == QDBusMessage::ErrorMessage)
{
qWarning() << "GetFeatureList error:" << FeatureResult.errorMessage();
return 0;
}
res += FeatureResult.arguments().takeFirst().toInt();
}
return res;
}

int BiometricProxy::StopOps(int drvid, int waiting)
{
QDBusReply<int> reply = call(QStringLiteral("StopOps"), drvid, waiting);
Expand Down
9 changes: 9 additions & 0 deletions BiometricAuth/biometricproxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,15 @@ public Q_SLOTS:
* @return
*/
int StopOps(int drvid, int waiting = 5);
/**
* @brief 获取当前用户已连接设备对应特征数目
* @param uid 用户id
* @param indexStart 用于认证的特征索引范围
* @param indexEnd
* @return
*/
int GetFeatureCount(int uid, int indexStart = 0, int indexEnd = -1);

/**
* @brief 获取已连接的设备列表
* @return
Expand Down
14 changes: 7 additions & 7 deletions greeter/greeterwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,28 +140,28 @@ void GreeterWindow::initUI()

m_userWnd->setModel(m_usersModel);

//显示lightdm传过来的被选中的用户 -- SwitchToUser()
//显示lightdm传过来的被选中的用户且自动进入认证界面 -- SwitchToUser()
QString selectedUser = m_greeter->selectUserHint();
if(!selectedUser.isEmpty())
{
qDebug() << "SelectUserHint: " << selectedUser;
m_userWnd->setCurrentUser(selectedUser);
m_userWnd->setCurrentUser(selectedUser, true);
}
// SwitchToGuest()
// SwitchToGuest()且自动进入认证界面
else if(m_greeter->selectGuestHint())
{
qDebug() << "SelectGuest";
m_userWnd->setCurrentUser("*guest");
m_userWnd->setCurrentUser("*guest", true);
}
//如果只有一个用户,直接进入认证界面
else if(m_usersModel->rowCount() == 1)
{
QString userName = m_usersModel->index(0, 0).data(QLightDM::UsersModel::NameRole).toString();
m_userWnd->setCurrentUser(userName);
m_userWnd->setCurrentUser(userName, true);
}
else
{
//选中上一次登录的用户
//选中上一次登录的用户,但不进入认证界面
QString lastLoginUser = Configuration::instance()->getLastLoginUser();
m_userWnd->setCurrentUser(lastLoginUser);
}
Expand Down Expand Up @@ -323,7 +323,7 @@ void GreeterWindow::onCurrentUserChanged(const QModelIndex &index)

void GreeterWindow::onUserChangedByManual(const QString &userName)
{
m_userWnd->setCurrentUser(userName);
m_userWnd->setCurrentUser(userName, true);
}

void GreeterWindow::onBacktoUsers()
Expand Down
15 changes: 15 additions & 0 deletions greeter/iconedit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ IconEdit::IconEdit(QWidget *parent)
m_edit->setObjectName(QStringLiteral("passwdEdit"));
m_edit->setAttribute(Qt::WA_InputMethodEnabled, false); //禁用输入法
m_edit->setContextMenuPolicy(Qt::NoContextMenu); //禁用右键菜单
m_edit->installEventFilter(this);

m_capsIcon = new QLabel(this);
m_capsIcon->setObjectName(QStringLiteral("capsIconLabel"));
Expand Down Expand Up @@ -70,6 +71,20 @@ IconEdit::IconEdit(QWidget *parent)
setCapsState(checkCapsState());
}

bool IconEdit::eventFilter(QObject *obj, QEvent *event)
{
if(obj == m_edit){
if(event->type() == QEvent::KeyPress){
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
if(keyEvent->key()==80 &&keyEvent->modifiers() ==(Qt::MetaModifier)){
event->ignore();
return true;
}
}
}
return false;
}

void IconEdit::setType(QLineEdit::EchoMode type)
{
m_edit->setEchoMode(type);
Expand Down
2 changes: 1 addition & 1 deletion greeter/iconedit.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class IconEdit : public QWidget

protected:
void resizeEvent(QResizeEvent *) Q_DECL_OVERRIDE;

bool eventFilter(QObject *obj, QEvent *event);
private:
void updatePixmap();

Expand Down
52 changes: 43 additions & 9 deletions greeter/loginwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ LoginWindow::LoginWindow(GreeterWrapper *greeter, QWidget *parent)
isManual(false),
authMode(UNKNOWN),
m_deviceCount(-1),
m_featureCount(-1),
m_biometricProxy(nullptr),
m_biometricAuthWidget(nullptr),
m_biometricDevicesWidget(nullptr),
Expand Down Expand Up @@ -106,6 +107,8 @@ void LoginWindow::initUI()
m_messageLabel = new QLabel(m_passwdWidget);
m_messageLabel->setObjectName(QStringLiteral("messageLabel"));
m_messageLabel->setAlignment(Qt::AlignCenter);

isloginauth = false;
}

void LoginWindow::showEvent(QShowEvent *e)
Expand Down Expand Up @@ -170,9 +173,9 @@ void LoginWindow::setChildrenGeometry()
// 密码框和提示信息显示位置
m_passwdWidget->setGeometry(0, m_userWidget->geometry().bottom(), width(), 150);
m_passwordEdit->setGeometry((m_passwdWidget->width() - 400)/2, 0, 400, 40);
m_messageLabel->setGeometry((m_passwdWidget->width() - 300)/2,
m_messageLabel->setGeometry((m_passwdWidget->width() - 400)/2,
m_passwordEdit->geometry().bottom() + 25,
300, 20);
400, 20);


setBiometricWidgetGeometry();
Expand Down Expand Up @@ -325,7 +328,10 @@ bool LoginWindow::setUserIndex(const QModelIndex& index)

setChildrenGeometry();

startAuthentication();
if(!isloginauth)
startAuthentication();

isloginauth = false;

return true;
}
Expand All @@ -336,6 +342,7 @@ bool LoginWindow::setUserIndex(const QModelIndex& index)
*/
void LoginWindow::setUserNotInView(const QString &userName)
{
isloginauth = false;
m_name = userName;
setUserName(userName);
}
Expand Down Expand Up @@ -389,6 +396,7 @@ void LoginWindow::onLogin(const QString &str)
}
else if(m_name == "*login")
{ //用户输入用户名
isloginauth = true;
Q_EMIT userChangedByManual(str);
m_greeter->respond(str);
}
Expand Down Expand Up @@ -508,6 +516,17 @@ void LoginWindow::performBiometricAuth()
return;
}

//初始化用户对应特征数量
m_featureCount = m_biometricProxy->GetFeatureCount(m_uid);

qDebug()<<"m_featureCount = "<<m_featureCount;
//没有可用特征,不启用生物识别认证
if(m_deviceCount < 1)
{
skipBiometricAuth();
return;
}

//初始化生物识别认证UI
initBiometricButtonWidget();
initBiometricWidget();
Expand Down Expand Up @@ -568,9 +587,9 @@ void LoginWindow::skipBiometricAuth()
// m_biometricButton->setVisible(true);
// m_passwordButton->setVisible(false);
// m_otherDeviceButton->setVisible(false);
// m_retryButton->setVisible(false);
// m_retryButton->setVisible(false);
// }
// m_passwdWidget->show();
m_passwdWidget->show();
}

void LoginWindow::initBiometricWidget()
Expand Down Expand Up @@ -729,15 +748,30 @@ void LoginWindow::onBiometricButtonClicked()
//当前没有设备,让用户选择设备
if(!m_deviceInfo)
{
m_otherDeviceButton->click();

if(m_deviceCount == 1)
{
DeviceList deviceList = m_biometricProxy->GetDevList();
m_deviceInfo = deviceList.at(0);
if(!m_deviceInfo)
{
m_otherDeviceButton->click();
}
else
{
authMode = BIOMETRIC;
startAuthentication();
}
}
else
{
m_otherDeviceButton->click();
}
}
else
{
authMode = BIOMETRIC;
startAuthentication();
}

}

void LoginWindow::onPasswordButtonClicked()
Expand Down Expand Up @@ -782,7 +816,7 @@ void LoginWindow::showPasswordAuthWidget()

if(m_buttonsWidget)
{
if(m_deviceCount > 0)
if(m_deviceCount > 0 && m_featureCount > 0)
{
m_buttonsWidget->setVisible(true);
m_biometricButton->setVisible(true);
Expand Down
4 changes: 3 additions & 1 deletion greeter/loginwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class LoginWindow : public QWidget
void setPrompt(const QString& text);
QString getPassword();
void reset();
bool isloginauth;

protected:
void showEvent(QShowEvent *);
Expand All @@ -73,7 +74,7 @@ public slots:
void onShowPrompt(QString text, QLightDM::Greeter::PromptType type);
void onAuthenticationComplete();
void setUserNotInView(const QString &userName);

private slots:
void onLogin(const QString &str);
void onBackButtonClicked();
Expand Down Expand Up @@ -117,6 +118,7 @@ private slots:
AuthMode authMode;
// 生物识别认证
int m_deviceCount;
int m_featureCount;
QString m_deviceName;
DeviceInfoPtr m_deviceInfo;
BiometricProxy *m_biometricProxy;
Expand Down
4 changes: 2 additions & 2 deletions greeter/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,8 @@ void MainWindow::moveToScreen(QScreen *screen)
QRect activeScreenRect = m_activeScreen->geometry();

qDebug() << "moveToScreen activeScreenRect " << activeScreenRect;
//if(m_monitorWatcher->getMonitorCount() == 1)
// activeScreenRect = QRect(QPoint(0, 0), m_monitorWatcher->getVirtualSize());
if(m_monitorWatcher->getMonitorCount() == 1)
activeScreenRect = QRect(QPoint(0, 0), m_monitorWatcher->getVirtualSize());

m_greeterWnd->setGeometry(activeScreenRect);
Q_EMIT activeScreenChanged(activeScreenRect);
Expand Down
5 changes: 5 additions & 0 deletions greeter/userentry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@ void UserEntry::setUserName(const QString &name)
int pixelsWide = fm.width(m_name);
if(pixelsWide < m_nameLabel->width())
m_nameLabel->setAlignment(Qt::AlignCenter);
else{
QFontMetrics fontWidth(font);
QString str = fontWidth.elidedText(m_name,Qt::ElideRight,m_nameLabel->width());
this->m_nameLabel->setText(str);
}
}

void UserEntry::setLogin(bool isLogin)
Expand Down
9 changes: 5 additions & 4 deletions greeter/usersview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ void UsersView::setModel(QAbstractListModel *model)
setCurrentRow(0); //默认选中第一位用户s
}

void UsersView::setCurrentUser(const QString &userName)
void UsersView::setCurrentUser(const QString &userName, bool entered)
{
if(!usersModel || userName.isEmpty())
return;
Expand All @@ -84,7 +84,8 @@ void UsersView::setCurrentUser(const QString &userName)
if(name == userName)
{
setCurrentRow(i);
onUserClicked(i);
if (entered)
onUserClicked(i);
return;
}
}
Expand Down Expand Up @@ -244,15 +245,15 @@ void UsersView::setCurrentRow(int row)

void UsersView::pageUp()
{
if(usersList->currentRow() >= 5)
if(usersList->currentRow() > 5)
setCurrentRow(usersList->currentRow() - 5);
else
setCurrentRow(0);
}

void UsersView::pageDown()
{
if(usersList->count() - usersList->currentRow() >= 5)
if(usersList->count() - usersList->currentRow() > 5)
setCurrentRow(usersList->currentRow() + 5);
else
setCurrentRow(usersList->count() - 1);
Expand Down
2 changes: 1 addition & 1 deletion greeter/usersview.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class UsersView : public QWidget
~UsersView();
void initUI();
void setModel(QAbstractListModel *);
void setCurrentUser(const QString &userName);
void setCurrentUser(const QString &userName, bool entered = false);
void pageUp();
void pageDown();

Expand Down

0 comments on commit ef470f6

Please sign in to comment.