Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support token authenticated registration #680

Merged
merged 4 commits into from
Aug 15, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ set(SRC_FILES
src/dialogs/Logout.cpp
src/dialogs/PreviewUploadOverlay.cpp
src/dialogs/ReCaptcha.cpp
src/dialogs/TokenRegistration.cpp

# Emoji
src/emoji/EmojiModel.cpp
Expand Down Expand Up @@ -497,6 +498,7 @@ qt5_wrap_cpp(MOC_HEADERS
src/dialogs/Logout.h
src/dialogs/PreviewUploadOverlay.h
src/dialogs/ReCaptcha.h
src/dialogs/TokenRegistration.h

# Emoji
src/emoji/EmojiModel.h
Expand Down
18 changes: 18 additions & 0 deletions src/RegisterPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

#include "dialogs/FallbackAuth.h"
#include "dialogs/ReCaptcha.h"
#include "dialogs/TokenRegistration.h"

Q_DECLARE_METATYPE(mtx::user_interactive::Unauthorized)
Q_DECLARE_METATYPE(mtx::user_interactive::Auth)
Expand Down Expand Up @@ -481,6 +482,23 @@ RegisterPage::doUIA(const mtx::user_interactive::Unauthorized &unauthorized)
doRegistrationWithAuth(
mtx::user_interactive::Auth{session, mtx::user_interactive::auth::Dummy{}});

} else if (current_stage == mtx::user_interactive::auth_types::registration_token) {
auto dialog = new dialogs::TokenRegistration(this);
govynnus marked this conversation as resolved.
Show resolved Hide resolved

connect(dialog,
&dialogs::TokenRegistration::confirmation,
this,
[this, session, dialog](std::string token) {
dialog->close();
dialog->deleteLater();
emit registrationWithAuth(mtx::user_interactive::Auth{
session, mtx::user_interactive::auth::RegistrationToken{token}});
});

connect(
dialog, &dialogs::TokenRegistration::cancel, this, &RegisterPage::errorOccurred);

dialog->show();
} else {
// use fallback
auto dialog = new dialogs::FallbackAuth(
Expand Down
62 changes: 62 additions & 0 deletions src/dialogs/TokenRegistration.cpp
Original file line number Diff line number Diff line change
@@ -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();
});
}
31 changes: 31 additions & 0 deletions src/dialogs/TokenRegistration.h
Original file line number Diff line number Diff line change
@@ -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