From ebd12a6f33fa2cff04da1756b1363a3f4ec45f90 Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Fri, 19 Feb 2021 15:48:43 +0100 Subject: Fix login with SSO and Password supported --- src/LoginPage.cpp | 47 +++++++++++++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 18 deletions(-) (limited to 'src/LoginPage.cpp') diff --git a/src/LoginPage.cpp b/src/LoginPage.cpp index 15aeb12a..26a170c5 100644 --- a/src/LoginPage.cpp +++ b/src/LoginPage.cpp @@ -147,16 +147,23 @@ LoginPage::LoginPage(QWidget *parent) error_matrixid_label_->hide(); button_layout_ = new QHBoxLayout(); - button_layout_->setSpacing(0); + button_layout_->setSpacing(20); button_layout_->setContentsMargins(0, 0, 0, 30); login_button_ = new RaisedButton(tr("LOGIN"), this); - login_button_->setMinimumSize(350, 65); + login_button_->setMinimumSize(150, 65); login_button_->setFontSize(20); login_button_->setCornerRadius(3); + sso_login_button_ = new RaisedButton(tr("SSO LOGIN"), this); + sso_login_button_->setMinimumSize(150, 65); + sso_login_button_->setFontSize(20); + sso_login_button_->setCornerRadius(3); + sso_login_button_->setVisible(false); + button_layout_->addStretch(1); button_layout_->addWidget(login_button_); + button_layout_->addWidget(sso_login_button_); button_layout_->addStretch(1); error_label_ = new QLabel(this); @@ -179,7 +186,12 @@ LoginPage::LoginPage(QWidget *parent) this, &LoginPage::versionErrorCb, this, &LoginPage::versionError, Qt::QueuedConnection); connect(back_button_, SIGNAL(clicked()), this, SLOT(onBackButtonClicked())); - connect(login_button_, SIGNAL(clicked()), this, SLOT(onLoginButtonClicked())); + connect(login_button_, &RaisedButton::clicked, this, [this]() { + onLoginButtonClicked(passwordSupported ? LoginMethod::Password : LoginMethod::SSO); + }); + connect(sso_login_button_, &RaisedButton::clicked, this, [this]() { + onLoginButtonClicked(LoginMethod::SSO); + }); connect(matrixid_input_, SIGNAL(returnPressed()), login_button_, SLOT(click())); connect(password_input_, SIGNAL(returnPressed()), login_button_, SLOT(click())); connect(deviceName_, SIGNAL(returnPressed()), login_button_, SLOT(click())); @@ -314,16 +326,19 @@ LoginPage::checkHomeserverVersion() http::client()->get_login( [this](mtx::responses::LoginFlows flows, mtx::http::RequestErr err) { if (err || flows.flows.empty()) - emit versionOkCb(LoginMethod::Password); + emit versionOkCb(true, false); - LoginMethod loginMethod_ = LoginMethod::Password; + bool ssoSupported_ = false; + bool passwordSupported_ = false; for (const auto &flow : flows.flows) { if (flow.type == mtx::user_interactive::auth_types::sso) { - loginMethod_ = LoginMethod::SSO; - break; + ssoSupported_ = true; + } else if (flow.type == + mtx::user_interactive::auth_types::password) { + passwordSupported_ = true; } } - emit versionOkCb(loginMethod_); + emit versionOkCb(passwordSupported_, ssoSupported_); }); }); } @@ -355,28 +370,24 @@ LoginPage::versionError(const QString &error) } void -LoginPage::versionOk(LoginMethod loginMethod_) +LoginPage::versionOk(bool passwordSupported_, bool ssoSupported_) { - this->loginMethod = loginMethod_; + passwordSupported = passwordSupported_; + ssoSupported = ssoSupported_; serverLayout_->removeWidget(spinner_); matrixidLayout_->removeWidget(spinner_); spinner_->stop(); - if (loginMethod == LoginMethod::SSO) { - password_input_->hide(); - login_button_->setText(tr("SSO LOGIN")); - } else { - password_input_->show(); - login_button_->setText(tr("LOGIN")); - } + sso_login_button_->setVisible(ssoSupported); + login_button_->setVisible(passwordSupported); if (serverInput_->isVisible()) serverInput_->hide(); } void -LoginPage::onLoginButtonClicked() +LoginPage::onLoginButtonClicked(LoginMethod loginMethod) { error_label_->setText(""); -- cgit 1.5.1 From 4a5b9d014a7659223b3a820723b13f834b922c4f Mon Sep 17 00:00:00 2001 From: Jedi18 Date: Thu, 25 Feb 2021 18:10:06 +0530 Subject: change mtxclient url, fix login page assert failure and dendrite registration bug --- CMakeLists.txt | 2 +- io.github.NhekoReborn.Nheko.json | 2 +- src/LoginPage.cpp | 13 +++++++++---- src/LoginPage.h | 1 + src/RegisterPage.cpp | 1 + 5 files changed, 13 insertions(+), 6 deletions(-) (limited to 'src/LoginPage.cpp') diff --git a/CMakeLists.txt b/CMakeLists.txt index 05e54380..ff0d6a1f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -358,7 +358,7 @@ if(USE_BUNDLED_MTXCLIENT) FetchContent_Declare( MatrixClient GIT_REPOSITORY https://github.com/Nheko-Reborn/mtxclient.git - GIT_TAG fee5298f068394958c2de935836a2c145f273906 + GIT_TAG 004d4203ceb441239aafb17e1340cd063139d029 ) set(BUILD_LIB_EXAMPLES OFF CACHE INTERNAL "") set(BUILD_LIB_TESTS OFF CACHE INTERNAL "") diff --git a/io.github.NhekoReborn.Nheko.json b/io.github.NhekoReborn.Nheko.json index 453d6c8a..c014aaea 100644 --- a/io.github.NhekoReborn.Nheko.json +++ b/io.github.NhekoReborn.Nheko.json @@ -220,7 +220,7 @@ "name": "mtxclient", "sources": [ { - "commit": "fee5298f068394958c2de935836a2c145f273906", + "commit": "004d4203ceb441239aafb17e1340cd063139d029", "type": "git", "url": "https://github.com/Nheko-Reborn/mtxclient.git" } diff --git a/src/LoginPage.cpp b/src/LoginPage.cpp index 26a170c5..cd54431d 100644 --- a/src/LoginPage.cpp +++ b/src/LoginPage.cpp @@ -192,6 +192,11 @@ LoginPage::LoginPage(QWidget *parent) connect(sso_login_button_, &RaisedButton::clicked, this, [this]() { onLoginButtonClicked(LoginMethod::SSO); }); + connect(this, + &LoginPage::showErrorMessage, + this, + static_cast(&LoginPage::showError), + Qt::QueuedConnection); connect(matrixid_input_, SIGNAL(returnPressed()), login_button_, SLOT(click())); connect(password_input_, SIGNAL(returnPressed()), login_button_, SLOT(click())); connect(deviceName_, SIGNAL(returnPressed()), login_button_, SLOT(click())); @@ -422,8 +427,8 @@ LoginPage::onLoginButtonClicked(LoginMethod loginMethod) : deviceName_->text().toStdString(), [this](const mtx::responses::Login &res, mtx::http::RequestErr err) { if (err) { - showError(error_label_, - QString::fromStdString(err->matrix_error.error)); + showErrorMessage(error_label_, + QString::fromStdString(err->matrix_error.error)); emit errorOccurred(); return; } @@ -448,7 +453,7 @@ LoginPage::onLoginButtonClicked(LoginMethod loginMethod) http::client()->login( req, [this](const mtx::responses::Login &res, mtx::http::RequestErr err) { if (err) { - showError( + showErrorMessage( error_label_, QString::fromStdString(err->matrix_error.error)); emit errorOccurred(); @@ -467,7 +472,7 @@ LoginPage::onLoginButtonClicked(LoginMethod loginMethod) sso->deleteLater(); }); connect(sso, &SSOHandler::ssoFailed, this, [this, sso]() { - showError(error_label_, tr("SSO login failed")); + showErrorMessage(error_label_, tr("SSO login failed")); emit errorOccurred(); sso->deleteLater(); }); diff --git a/src/LoginPage.h b/src/LoginPage.h index 2341c0ce..f6428cbb 100644 --- a/src/LoginPage.h +++ b/src/LoginPage.h @@ -59,6 +59,7 @@ signals: void versionOkCb(bool passwordSupported, bool ssoSupported); void loginOk(const mtx::responses::Login &res); + void showErrorMessage(QLabel *label, const QString &msg); protected: void paintEvent(QPaintEvent *event) override; diff --git a/src/RegisterPage.cpp b/src/RegisterPage.cpp index 44ad7a3d..004d5b98 100644 --- a/src/RegisterPage.cpp +++ b/src/RegisterPage.cpp @@ -277,6 +277,7 @@ RegisterPage::RegisterPage(QWidget *parent) if (!err) { http::client()->set_user(res.user_id); http::client()->set_access_token(res.access_token); + http::client()->set_device_id(res.device_id); emit registerOk(); return; -- cgit 1.5.1