summary refs log tree commit diff
path: root/src/dialogs
diff options
context:
space:
mode:
authorCallum Brown <callum@calcuode.com>2021-08-11 15:07:06 +0100
committerCallum Brown <callum@calcuode.com>2021-08-11 15:07:06 +0100
commitb56a1be0bd3085680fd572bb31f17007bce53494 (patch)
tree8d151bcdeb419627034ec7f2fd2f3f8588b47fe6 /src/dialogs
parentAttrIbution (diff)
downloadnheko-b56a1be0bd3085680fd572bb31f17007bce53494.tar.xz
Support token authenticated registration
Using a dialog after username and password have been provided.
Diffstat (limited to 'src/dialogs')
-rw-r--r--src/dialogs/TokenRegistration.cpp62
-rw-r--r--src/dialogs/TokenRegistration.h31
2 files changed, 93 insertions, 0 deletions
diff --git a/src/dialogs/TokenRegistration.cpp b/src/dialogs/TokenRegistration.cpp
new file mode 100644

index 00000000..2333dcb1 --- /dev/null +++ b/src/dialogs/TokenRegistration.cpp
@@ -0,0 +1,62 @@ +// SPDX-FileCopyrightText: 2021 Nheko Contributors +// +// SPDX-License-Identifier: GPL-3.0-or-later + +#include <QLabel> +#include <QPushButton> +#include <QVBoxLayout> + +#include "dialogs/TokenRegistration.h" + +#include "Config.h" +#include "MatrixClient.h" +#include "ui/TextField.h" + +using namespace dialogs; + +TokenRegistration::TokenRegistration(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); + + cancelBtn_ = new QPushButton(tr("Cancel"), this); + confirmBtn_ = new QPushButton(tr("Confirm"), this); + confirmBtn_->setDefault(true); + + buttonLayout->addStretch(1); + buttonLayout->addWidget(cancelBtn_); + buttonLayout->addWidget(confirmBtn_); + + tokenInput_ = new TextField(this); + tokenInput_->setLabel(tr("Registration token")); + + QFont font; + font.setPointSizeF(font.pointSizeF() * conf::modals::LABEL_MEDIUM_SIZE_RATIO); + + auto label = new QLabel(tr("Please enter a valid registration token."), this); + label->setFont(font); + + layout->addWidget(label); + layout->addWidget(tokenInput_); + layout->addLayout(buttonLayout); + + connect(confirmBtn_, &QPushButton::clicked, this, [this]() { + emit confirmation(tokenInput_->text().toStdString()); + emit close(); + }); + connect(cancelBtn_, &QPushButton::clicked, this, [this]() { + emit cancel(); + emit close(); + }); +} diff --git a/src/dialogs/TokenRegistration.h b/src/dialogs/TokenRegistration.h new file mode 100644
index 00000000..562dcb7b --- /dev/null +++ b/src/dialogs/TokenRegistration.h
@@ -0,0 +1,31 @@ +// SPDX-FileCopyrightText: 2021 Nheko Contributors +// +// SPDX-License-Identifier: GPL-3.0-or-later + +#pragma once + +#include <QWidget> + +class QPushButton; +class QLabel; +class TextField; + +namespace dialogs { + +class TokenRegistration : public QWidget +{ + Q_OBJECT + +public: + TokenRegistration(QWidget *parent = nullptr); + +signals: + void confirmation(std::string token); + void cancel(); + +private: + QPushButton *confirmBtn_; + QPushButton *cancelBtn_; + TextField *tokenInput_; +}; +} // dialogs