Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Unverified Commit e65d4600 authored by Melvin Keskin's avatar Melvin Keskin Committed by Linus Jahn

Open login page for XMPP URI without password of scanned QR code

The JID from the XMPP URI is used to pre-fill the corresponding field
on the login page so that the user only needs to enter the password.
parent 2397aeb4
Pipeline #28972 passed with stages
in 48 minutes and 39 seconds
......@@ -103,6 +103,16 @@ namespace Enums {
};
Q_ENUM_NS(DeliveryState)
/**
* State which specifies how the XMPP login URI was used
*/
enum class LoginByUriState {
Connecting, ///< The JID and password are included in the URI and the client is connecting.
PasswordNeeded, ///< The JID is included in the URI but not the password.
InvalidLoginUri ///< The URI cannot be used to log in.
};
Q_ENUM_NS(LoginByUriState)
template <typename T, ENABLE_IF(!has_enum_type<T>::value && std::is_enum<T>::value)>
QString toString(const T flag) {
static const QMetaEnum e = QMetaEnum::fromType<T>();
......
......@@ -268,27 +268,30 @@ void Kaidan::addOpenUri(const QString &uri)
}
}
bool Kaidan::logInByUri(const QString &uri)
quint8 Kaidan::logInByUri(const QString &uri)
{
if (!QXmppUri::isXmppUri(uri)) {
notifyForInvalidLoginUri();
return false;
return quint8(LoginByUriState::InvalidLoginUri);
}
QXmppUri parsedUri(uri);
if (!CredentialsValidator::isAccountJidValid(parsedUri.jid()) || !parsedUri.hasAction(QXmppUri::Action::Login) || !CredentialsValidator::isPasswordValid(parsedUri.password())) {
if (!CredentialsValidator::isAccountJidValid(parsedUri.jid())) {
notifyForInvalidLoginUri();
return false;
return quint8(LoginByUriState::InvalidLoginUri);
}
setJid(parsedUri.jid());
setPassword(parsedUri.password());
if (!parsedUri.hasAction(QXmppUri::Login) || !CredentialsValidator::isPasswordValid(parsedUri.password())) {
return quint8(LoginByUriState::PasswordNeeded);
}
// Connect with the extracted credentials.
setPassword(parsedUri.password());
mainConnect();
return true;
return quint8(LoginByUriState::Connecting);
}
void Kaidan::notifyForInvalidLoginUri()
......
......@@ -228,9 +228,26 @@ public:
/**
* Connects to the server by the parsed credentials (bare JID and password) from a given XMPP URI (e.g. from scanning a QR code) like "xmpp:user@example.org?login;password=abc"
*
* @return true if the login worked
* The URI is used in the following cases.
*
* Login attempt (LoginByUriState::Connecting is returned):
* xmpp:user@example.org?login;password=abc
*
* Pre-fill of JID for opening login page (LoginByUriState::PasswordNeeded is returned):
* xmpp:user@example.org?login;password=
* xmpp:user@example.org?login;password
* xmpp:user@example.org?login;
* xmpp:user@example.org?login
* xmpp:user@example.org?
* xmpp:user@example.org
*
* In all other cases, LoginByUriState::InvalidLoginUri is returned.
*
* @param uri string which can be an XMPP login URI
*
* @return the state which specifies how the XMPP login URI was used
*/
Q_INVOKABLE bool logInByUri(const QString &uri);
Q_INVOKABLE quint8 logInByUri(const QString &uri);
signals:
/**
......
......@@ -52,7 +52,7 @@ Kirigami.Page {
bottomPadding: 0
property bool cameraEnabled: false
property bool loggingIn: false
property bool connecting: false
// hint for camera issues
Kirigami.InlineMessage {
......@@ -99,9 +99,17 @@ Kirigami.Page {
id: scannerFilter
onScanningSucceeded: {
if (!loggingIn) {
// Login by the data from the decoded QR code.
loggingIn = Kaidan.logInByUri(result)
if (!connecting) {
// Try to log in by the data from the decoded QR code.
switch (Kaidan.logInByUri(result)) {
case Enums.Connecting:
connecting = true
break;
case Enums.PasswordNeeded:
pageStack.push(loginPage)
break;
case Enums.InvalidLoginUri:
}
}
}
......@@ -124,14 +132,14 @@ Kirigami.Page {
id: loadingArea
z: 2
anchors.centerIn: parent
visible: loggingIn
visible: connecting
Controls.BusyIndicator {
Layout.alignment: Qt.AlignHCenter
}
Controls.Label {
text: "<i>" + qsTr("Logging in") + "</i>"
text: "<i>" + qsTr("Connecting") + "</i>"
color: Kirigami.Theme.textColor
}
......@@ -139,14 +147,14 @@ Kirigami.Page {
target: Kaidan
onConnectionStateChanged: {
if (loggingIn) {
if (connecting) {
switch (Kaidan.connectionState) {
case Enums.StateConnected:
popAllLayers()
break
case Enums.StateDisconnected:
showPassiveNotificationForConnectionError()
loggingIn = false
connecting = false
break
}
}
......
......@@ -40,6 +40,7 @@ CredentialsField {
placeholderText: qsTr("user@example.org")
inputMethodHints: Qt.ImhEmailCharactersOnly
invalidHintText: qsTr("The chat address must have the form <b>username@server</b>")
text: Kaidan.jid
// Validate the entered JID and show a hint if it is not valid.
onTextChanged: {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment