From fedc178827c5648b0ccbdd2cd08dcebc920ac416 Mon Sep 17 00:00:00 2001 From: Loren Burkholder Date: Wed, 28 Jun 2023 17:00:34 -0400 Subject: Port the reCAPTCHA dialog to QML --- src/ui/UIA.cpp | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) (limited to 'src/ui/UIA.cpp') diff --git a/src/ui/UIA.cpp b/src/ui/UIA.cpp index 2b6b059a..ba35df9b 100644 --- a/src/ui/UIA.cpp +++ b/src/ui/UIA.cpp @@ -14,12 +14,12 @@ #include "Logging.h" #include "MatrixClient.h" #include "dialogs/FallbackAuth.h" -#include "dialogs/ReCaptcha.h" +#include "ReCaptcha.h" UIA * UIA::instance() { - static UIA uia; + static UIA uia{nullptr}; return &uia; } @@ -99,24 +99,16 @@ UIA::genericHandler(QString context) } else if (current_stage == mtx::user_interactive::auth_types::msisdn) { emit phoneNumber(); } else if (current_stage == mtx::user_interactive::auth_types::recaptcha) { - auto captchaDialog = - new dialogs::ReCaptcha(QString::fromStdString(u.session), nullptr); - captchaDialog->setWindowTitle(context); - - connect( - captchaDialog, &dialogs::ReCaptcha::confirmation, this, [captchaDialog, h, u]() { - captchaDialog->close(); - captchaDialog->deleteLater(); - h.next(mtx::user_interactive::Auth{u.session, - mtx::user_interactive::auth::Fallback{}}); - }); - - connect(captchaDialog, &dialogs::ReCaptcha::cancel, this, [this]() { + auto captcha = new ReCaptcha(QString::fromStdString(u.session), context, nullptr); + QQmlEngine::setObjectOwnership(captcha, QQmlEngine::JavaScriptOwnership); + connect(captcha, &ReCaptcha::confirmation, this, [h, u]() { + h.next(mtx::user_interactive::Auth{u.session, + mtx::user_interactive::auth::Fallback{}}); + }); + connect(captcha, &ReCaptcha::cancelled, this, [this]() { emit error(tr("Registration aborted")); }); - - QTimer::singleShot(0, this, [captchaDialog]() { captchaDialog->show(); }); - + emit reCaptcha(captcha); } else if (current_stage == mtx::user_interactive::auth_types::dummy) { h.next( mtx::user_interactive::Auth{u.session, mtx::user_interactive::auth::Dummy{}}); -- cgit 1.5.1 From d2a37ec9839e8f79e98bebe1ef7d55ccc62e1b6f Mon Sep 17 00:00:00 2001 From: Loren Burkholder Date: Thu, 29 Jun 2023 12:58:34 -0400 Subject: make lint --- src/ReCaptcha.cpp | 9 +++++---- src/ui/UIA.cpp | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) (limited to 'src/ui/UIA.cpp') diff --git a/src/ReCaptcha.cpp b/src/ReCaptcha.cpp index ffd202f5..ab9db8cc 100644 --- a/src/ReCaptcha.cpp +++ b/src/ReCaptcha.cpp @@ -10,13 +10,14 @@ #include "MatrixClient.h" ReCaptcha::ReCaptcha(const QString &session, const QString &context, QObject *parent) - : QObject{parent}, - m_session{session}, - m_context{context} + : QObject{parent} + , m_session{session} + , m_context{context} { } -void ReCaptcha::openReCaptcha() +void +ReCaptcha::openReCaptcha() { const auto url = QString("https://%1:%2/_matrix/client/r0/auth/m.login.recaptcha/" "fallback/web?session=%3") diff --git a/src/ui/UIA.cpp b/src/ui/UIA.cpp index ba35df9b..9654c9aa 100644 --- a/src/ui/UIA.cpp +++ b/src/ui/UIA.cpp @@ -13,8 +13,8 @@ #include "Logging.h" #include "MatrixClient.h" -#include "dialogs/FallbackAuth.h" #include "ReCaptcha.h" +#include "dialogs/FallbackAuth.h" UIA * UIA::instance() -- cgit 1.5.1