From bc4c4f851965a0226c2649e3b73a0c745acc815c Mon Sep 17 00:00:00 2001 From: Tobias Fella Date: Mon, 8 May 2023 14:29:07 +0200 Subject: [PATCH] Refactor login BUG: 469486 --- src/login.cpp | 4 ++++ src/qml/Component/Login/Login.qml | 10 ++-------- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/login.cpp b/src/login.cpp index 8b937abaa..6da1a2bc0 100644 --- a/src/login.cpp +++ b/src/login.cpp @@ -38,6 +38,10 @@ void Login::init() connect(this, &Login::matrixIdChanged, this, [this]() { setHomeserverReachable(false); + QRegularExpression validator("^\\@?[a-zA-Z0-9\\._=\\-/]+\\:[a-zA-Z0-9\\-]+(\\.[a-zA-Z0-9\\-]+)*(\\:[0-9]+)?$"); + if (!validator.match(m_matrixId).hasMatch()) { + return; + } if (m_matrixId == "@") { return; diff --git a/src/qml/Component/Login/Login.qml b/src/qml/Component/Login/Login.qml index 384997725..347c798be 100644 --- a/src/qml/Component/Login/Login.qml +++ b/src/qml/Component/Login/Login.qml @@ -29,9 +29,7 @@ LoginStep { Kirigami.FormData.label: i18n("Matrix ID:") placeholderText: "@user:matrix.org" onTextChanged: { - if (acceptableInput) { - LoginHelper.matrixId = text - } + LoginHelper.matrixId = text } Component.onCompleted: { @@ -41,15 +39,11 @@ LoginStep { Keys.onReturnPressed: { login.action.trigger() } - - validator: RegularExpressionValidator { - regularExpression: /^\@?[a-zA-Z0-9\._=\-/]+\:[a-zA-Z0-9\-]+(\.[a-zA-Z0-9\-]+)*(\:[0-9]+)?$/ - } } } action: Kirigami.Action { - text: LoginHelper.testing && matrixIdField.acceptableInput ? (LoginHelper.isLoggedIn ? i18n("Already logged in") : i18n("Loading…")) : i18nc("@action:button", "Continue") + text: LoginHelper.isLoggedIn ? i18n("Already logged in") : (LoginHelper.testing && matrixIdField.acceptableInput) ? i18n("Loading…") : i18nc("@action:button", "Continue") onTriggered: { if (LoginHelper.supportsSso && LoginHelper.supportsPassword) { processed("qrc:/LoginMethod.qml");