diff --git a/src/LoginPage.cpp b/src/LoginPage.cpp index 9a920d1d..348cfa29 100644 --- a/src/LoginPage.cpp +++ b/src/LoginPage.cpp @@ -95,8 +95,6 @@ LoginPage::LoginPage(QWidget *parent) "address there, if your server doesn't support .well-known lookup.\nExample: " "@user:server.my\nIf Nheko fails to discover your homeserver, it will show you a " "field to enter the server manually.")); - matrixid_input_->setValidator( - new QRegularExpressionValidator(QRegularExpression("@.+?:.{3,}"), this)); spinner_ = new LoadingIndicator(this); spinner_->setFixedHeight(40); @@ -153,7 +151,6 @@ LoginPage::LoginPage(QWidget *parent) error_label_ = new QLabel(this); error_label_->setFont(font); - error_label_->setWordWrap(true); top_layout_->addLayout(top_bar_layout_); top_layout_->addStretch(1); @@ -186,6 +183,15 @@ LoginPage::loginError(const QString &msg) error_label_->setText(msg); } +bool +LoginPage::isMatrixIdValid() +{ + QRegularExpressionValidator v(QRegularExpression("@.+?:.{3,}"), this); + QString s = matrixid_input_->text(); + int pos = 0; + return v.validate(s, pos); +} + void LoginPage::onMatrixIdEntered() { @@ -193,6 +199,10 @@ LoginPage::onMatrixIdEntered() User user; + if (isMatrixIdValid() == 0) { + return loginError("You have entered an invalid Matrix ID e.g @joe:matrix.org"); + } + try { user = parse(matrixid_input_->text().toStdString()); } catch (const std::exception &e) { @@ -344,6 +354,9 @@ LoginPage::onLoginButtonClicked() error_label_->setText(""); User user; + if (isMatrixIdValid() == 0) { + return loginError("You have entered an invalid Matrix ID e.g @joe:matrix.org"); + } try { user = parse(matrixid_input_->text().toStdString());