summary refs log tree commit diff
path: root/src/dialogs
diff options
context:
space:
mode:
authorNicolas Werner <nicolas.werner@hotmail.de>2020-02-23 11:42:29 +0100
committerNicolas Werner <nicolas.werner@hotmail.de>2020-02-23 13:44:05 +0100
commit3ef0d9db3cb1fe84c3c905fe7fbd80c3bbb51fd4 (patch)
tree99988bb1803817b1e60899a3bf78072bf4b067a0 /src/dialogs
parentMerge pull request #128 from adasauce/no-setstylesheet (diff)
downloadnheko-3ef0d9db3cb1fe84c3c905fe7fbd80c3bbb51fd4.tar.xz
Fix Registration
fixes #97
fixes #51
Diffstat (limited to '')
-rw-r--r--src/dialogs/FallbackAuth.cpp69
-rw-r--r--src/dialogs/FallbackAuth.h26
-rw-r--r--src/dialogs/ReCaptcha.cpp5
-rw-r--r--src/dialogs/ReCaptcha.h1
4 files changed, 100 insertions, 1 deletions
diff --git a/src/dialogs/FallbackAuth.cpp b/src/dialogs/FallbackAuth.cpp
new file mode 100644
index 00000000..a0633c1e
--- /dev/null
+++ b/src/dialogs/FallbackAuth.cpp
@@ -0,0 +1,69 @@
+#include <QDesktopServices>
+#include <QLabel>
+#include <QPushButton>
+#include <QUrl>
+#include <QVBoxLayout>
+
+#include "dialogs/FallbackAuth.h"
+
+#include "Config.h"
+#include "MatrixClient.h"
+
+using namespace dialogs;
+
+FallbackAuth::FallbackAuth(const QString &authType, const QString &session, QWidget *parent)
+  : QWidget(parent)
+{
+        setAutoFillBackground(true);
+        setWindowFlags(Qt::Tool | Qt::WindowStaysOnTopHint);
+        setWindowModality(Qt::WindowModal);
+        setAttribute(Qt::WA_DeleteOnClose, true);
+
+        auto layout = new QVBoxLayout(this);
+        layout->setSpacing(conf::modals::WIDGET_SPACING);
+        layout->setMargin(conf::modals::WIDGET_MARGIN);
+
+        auto buttonLayout = new QHBoxLayout();
+        buttonLayout->setSpacing(8);
+        buttonLayout->setMargin(0);
+
+        openBtn_    = new QPushButton(tr("Open Fallback in Browser"), this);
+        cancelBtn_  = new QPushButton(tr("Cancel"), this);
+        confirmBtn_ = new QPushButton(tr("Confirm"), this);
+        confirmBtn_->setDefault(true);
+
+        buttonLayout->addStretch(1);
+        buttonLayout->addWidget(openBtn_);
+        buttonLayout->addWidget(cancelBtn_);
+        buttonLayout->addWidget(confirmBtn_);
+
+        QFont font;
+        font.setPointSizeF(font.pointSizeF() * conf::modals::LABEL_MEDIUM_SIZE_RATIO);
+
+        auto label = new QLabel(
+          tr("Open the fallback, follow the steps and confirm after completing them."), this);
+        label->setFont(font);
+
+        layout->addWidget(label);
+        layout->addLayout(buttonLayout);
+
+        connect(openBtn_, &QPushButton::clicked, [session, authType]() {
+                const auto url = QString("https://%1:%2/_matrix/client/r0/auth/%4/"
+                                         "fallback/web?session=%3")
+                                   .arg(QString::fromStdString(http::client()->server()))
+                                   .arg(http::client()->port())
+                                   .arg(session)
+                                   .arg(authType);
+
+                QDesktopServices::openUrl(url);
+        });
+
+        connect(confirmBtn_, &QPushButton::clicked, this, [this]() {
+                emit confirmation();
+                emit close();
+        });
+        connect(cancelBtn_, &QPushButton::clicked, this, [this]() {
+                emit cancel();
+                emit close();
+        });
+}
diff --git a/src/dialogs/FallbackAuth.h b/src/dialogs/FallbackAuth.h
new file mode 100644
index 00000000..245fa03e
--- /dev/null
+++ b/src/dialogs/FallbackAuth.h
@@ -0,0 +1,26 @@
+#pragma once
+
+#include <QWidget>
+
+class QPushButton;
+class QLabel;
+
+namespace dialogs {
+
+class FallbackAuth : public QWidget
+{
+        Q_OBJECT
+
+public:
+        FallbackAuth(const QString &authType, const QString &session, QWidget *parent = nullptr);
+
+signals:
+        void confirmation();
+        void cancel();
+
+private:
+        QPushButton *openBtn_;
+        QPushButton *confirmBtn_;
+        QPushButton *cancelBtn_;
+};
+} // dialogs
diff --git a/src/dialogs/ReCaptcha.cpp b/src/dialogs/ReCaptcha.cpp
index 7849aa4f..21dc8c77 100644
--- a/src/dialogs/ReCaptcha.cpp
+++ b/src/dialogs/ReCaptcha.cpp
@@ -60,5 +60,8 @@ ReCaptcha::ReCaptcha(const QString &session, QWidget *parent)
                 emit confirmation();
                 emit close();
         });
-        connect(cancelBtn_, &QPushButton::clicked, this, &dialogs::ReCaptcha::close);
+        connect(cancelBtn_, &QPushButton::clicked, this, [this]() {
+                emit cancel();
+                emit close();
+        });
 }
diff --git a/src/dialogs/ReCaptcha.h b/src/dialogs/ReCaptcha.h
index f8407640..88ff3722 100644
--- a/src/dialogs/ReCaptcha.h
+++ b/src/dialogs/ReCaptcha.h
@@ -15,6 +15,7 @@ public:
 
 signals:
         void confirmation();
+        void cancel();
 
 private:
         QPushButton *openCaptchaBtn_;