diff --git a/src/greeter/greeterproxy.cpp b/src/greeter/greeterproxy.cpp index 58b2e411bb..01ccad7418 100644 --- a/src/greeter/greeterproxy.cpp +++ b/src/greeter/greeterproxy.cpp @@ -196,6 +196,21 @@ void GreeterProxy::setLock(bool isLocked) setShowShutdownView(false); } +void GreeterProxy::beginAuthentication(const QString &user) +{ + m_authenticationUser = user; + Q_EMIT authPendingChanged(); +} + +void GreeterProxy::finishAuthentication() +{ + if (!authPending()) + return; + + m_authenticationUser.clear(); + Q_EMIT authPendingChanged(); +} + /////////// // Slots // /////////// @@ -227,6 +242,9 @@ void GreeterProxy::hybridSleep() void GreeterProxy::login(const QString &user, const QString &password, const int sessionIndex) { + if (authPending()) + return; + if (!m_socket->isValid()) { qCDebug(lcTlGreeter) << "Socket is not valid. Local password check."; if (localValidation(user, password)) { @@ -243,11 +261,15 @@ void GreeterProxy::login(const QString &user, const QString &password, const int // send command to the daemon QString name = sessionModel()->data(index, SessionModel::FileRole).toString(); qCInfo(lcTlGreeter) << "Logging user" << user << "in with session" << name; + beginAuthentication(user); SocketWriter(m_socket) << quint32(GreeterMessages::Login) << user << password << name; } void GreeterProxy::unlock(const QString &user, const QString &password) { + if (authPending()) + return; + if (!m_socket->isValid()) { qCDebug(lcTlGreeter) << "Socket is not valid. Local password check."; if (localValidation(user, password)) { @@ -261,6 +283,7 @@ void GreeterProxy::unlock(const QString &user, const QString &password) auto userInfo = userModel()->get(user); if (userInfo.isValid()) { qCInfo(lcTlGreeter) << "Unlocking user" << user; + beginAuthentication(user); SocketWriter(m_socket) << quint32(GreeterMessages::Unlock) << user << password; } } @@ -469,12 +492,14 @@ void GreeterProxy::disconnected() { qCWarning(lcTlGreeter) << "Disconnected from the ddm"; + finishAuthentication(); Q_EMIT socketDisconnected(); } void GreeterProxy::error() { qCCritical(lcTlGreeter) << "Socket error: " << m_socket->errorString(); + finishAuthentication(); } void GreeterProxy::readyRead() @@ -556,6 +581,7 @@ void GreeterProxy::readyRead() qCDebug(lcTlGreeter) << "Message received from daemon: LoginFailed" << user; + finishAuthentication(); Q_EMIT failedAttemptsChanged(++m_failedAttempts); } break; case DaemonMessages::InformationMessage: { @@ -592,6 +618,9 @@ void GreeterProxy::readyRead() if (!input.commitTransaction()) return; + if (user == m_authenticationUser) + finishAuthentication(); + // NOTE: maybe DDM will active dde user. if (!userModel()->getUser(user)) { qCInfo(lcTlGreeter) << "activate user, but switch to greeter"; diff --git a/src/greeter/greeterproxy.h b/src/greeter/greeterproxy.h index 06fced041c..efe2573ca3 100644 --- a/src/greeter/greeterproxy.h +++ b/src/greeter/greeterproxy.h @@ -37,6 +37,7 @@ class GreeterProxy Q_PROPERTY(bool isLocked READ isLocked NOTIFY lockChanged) Q_PROPERTY(bool undecided READ undecided NOTIFY undecidedChanged) Q_PROPERTY(int failedAttempts READ failedAttempts NOTIFY failedAttemptsChanged) + Q_PROPERTY(bool authPending READ authPending NOTIFY authPendingChanged) Q_PROPERTY(bool showShutdownView READ showShutdownView WRITE setShowShutdownView NOTIFY showShutdownViewChanged) Q_PROPERTY(bool showAnimation READ showAnimation NOTIFY showAnimationChanged) Q_PROPERTY(bool hasActiveSession READ hasActiveSession NOTIFY hasActiveSessionChanged) @@ -114,6 +115,14 @@ class GreeterProxy */ inline int failedAttempts() const { return m_failedAttempts; }; + /** + * @brief Get whether DDM authentication is pending + * QML uses this property to disable the password field and login buttons. + * + * @return true if a login or unlock request is awaiting a result + */ + inline bool authPending() const { return !m_authenticationUser.isEmpty(); }; + /** * @brief Get whether the shutdown view is shown * QML elements should listen to this property to show/hide the shutdown view @@ -296,6 +305,9 @@ private Q_SLOTS: /** @brief Emitted when failed attempts changes. See failedAttempts() */ void failedAttemptsChanged (int failedAttempts); + /** @brief Emitted when the authentication pending state changes. See authPending() */ + void authPendingChanged(); + /** @brief Emitted when showShutdownView changes. See showShutdownView() */ void showShutdownViewChanged (bool showShutdownView); @@ -321,6 +333,16 @@ private Q_SLOTS: */ void setLock(bool isLocked); + /** + * @brief Start waiting for the given user's authentication result. + * + * @param user Username submitted in the login or unlock request + */ + void beginAuthentication(const QString &user); + + /** @brief Clear the pending authentication request, if any. */ + void finishAuthentication(); + /** * @brief Update the DDM communication socket */ @@ -346,6 +368,7 @@ private Q_SLOTS: bool m_undecided { true }; QTimer *m_undecidedTimer{ nullptr }; int m_failedAttempts { 0 }; + QString m_authenticationUser; bool m_showShutdownView { false }; bool m_showAnimation { true }; bool m_hasActiveSession { false }; diff --git a/src/plugins/lockscreen/qml/UserInput.qml b/src/plugins/lockscreen/qml/UserInput.qml index 9ca6c61c61..cdd26ab07c 100644 --- a/src/plugins/lockscreen/qml/UserInput.qml +++ b/src/plugins/lockscreen/qml/UserInput.qml @@ -107,6 +107,7 @@ Item { width: loginGroup.width height: 30 anchors.horizontalCenter: parent.horizontalCenter + enabled: !GreeterProxy.authPending TextField { id: passwordField @@ -271,7 +272,7 @@ Item { bottom: userCol.bottom leftMargin: 20 } - enabled: passwordField.length != 0 + enabled: passwordField.length != 0 && !GreeterProxy.authPending font: D.DTK.fontManager.t8 background: RoundBlur { anchors.fill: parent @@ -398,6 +399,9 @@ Item { } function userLogin() { + if (!loginGroup.noPasswdLogin && passwordField.length === 0) + return + let user = UserModel.get(UserModel.currentUserName) let pwd = loginGroup.noPasswdLogin ? "" : passwordField.text if (user.loggedIn)