mirror of https://github.com/Nheko-Reborn/nheko
parent
39a8150fae
commit
4659d0efc2
@ -1,52 +0,0 @@ |
|||||||
/*
|
|
||||||
* nheko Copyright (C) 2017 Konstantinos Sideris <siderisk@auth.gr> |
|
||||||
* |
|
||||||
* This program is free software: you can redistribute it and/or modify |
|
||||||
* it under the terms of the GNU General Public License as published by |
|
||||||
* the Free Software Foundation, either version 3 of the License, or |
|
||||||
* (at your option) any later version. |
|
||||||
* |
|
||||||
* This program is distributed in the hope that it will be useful, |
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
||||||
* GNU General Public License for more details. |
|
||||||
* |
|
||||||
* You should have received a copy of the GNU General Public License |
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/ |
|
||||||
|
|
||||||
#pragma once |
|
||||||
|
|
||||||
#include "Deserializable.h" |
|
||||||
#include <QJsonDocument> |
|
||||||
|
|
||||||
class RegisterRequest |
|
||||||
{ |
|
||||||
public: |
|
||||||
RegisterRequest(); |
|
||||||
RegisterRequest(const QString &username, const QString &password); |
|
||||||
|
|
||||||
QByteArray serialize() noexcept; |
|
||||||
|
|
||||||
void setPassword(QString password) { password_ = password; }; |
|
||||||
void setUser(QString username) { user_ = username; }; |
|
||||||
|
|
||||||
private: |
|
||||||
QString user_; |
|
||||||
QString password_; |
|
||||||
}; |
|
||||||
|
|
||||||
class RegisterResponse : public Deserializable |
|
||||||
{ |
|
||||||
public: |
|
||||||
void deserialize(const QJsonDocument &data) override; |
|
||||||
|
|
||||||
QString getAccessToken() { return access_token_; }; |
|
||||||
QString getHomeServer() { return home_server_; }; |
|
||||||
QString getUserId() { return user_id_; }; |
|
||||||
|
|
||||||
private: |
|
||||||
QString access_token_; |
|
||||||
QString home_server_; |
|
||||||
QString user_id_; |
|
||||||
}; |
|
@ -0,0 +1,28 @@ |
|||||||
|
#pragma once |
||||||
|
|
||||||
|
#include <QWidget> |
||||||
|
|
||||||
|
class FlatButton; |
||||||
|
class RaisedButton; |
||||||
|
|
||||||
|
namespace dialogs { |
||||||
|
|
||||||
|
class ReCaptcha : public QWidget |
||||||
|
{ |
||||||
|
Q_OBJECT |
||||||
|
|
||||||
|
public: |
||||||
|
ReCaptcha(const QString &server, const QString &session, QWidget *parent = nullptr); |
||||||
|
|
||||||
|
protected: |
||||||
|
void paintEvent(QPaintEvent *event) override; |
||||||
|
|
||||||
|
signals: |
||||||
|
void closing(); |
||||||
|
|
||||||
|
private: |
||||||
|
FlatButton *openCaptchaBtn_; |
||||||
|
RaisedButton *confirmBtn_; |
||||||
|
RaisedButton *cancelBtn_; |
||||||
|
}; |
||||||
|
} // dialogs
|
@ -1,53 +0,0 @@ |
|||||||
/*
|
|
||||||
* nheko Copyright (C) 2017 Konstantinos Sideris <siderisk@auth.gr> |
|
||||||
* |
|
||||||
* This program is free software: you can redistribute it and/or modify |
|
||||||
* it under the terms of the GNU General Public License as published by |
|
||||||
* the Free Software Foundation, either version 3 of the License, or |
|
||||||
* (at your option) any later version. |
|
||||||
* |
|
||||||
* This program is distributed in the hope that it will be useful, |
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
||||||
* GNU General Public License for more details. |
|
||||||
* |
|
||||||
* You should have received a copy of the GNU General Public License |
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/ |
|
||||||
|
|
||||||
#include "Register.h" |
|
||||||
|
|
||||||
RegisterRequest::RegisterRequest(const QString &username, const QString &password) |
|
||||||
: user_(username) |
|
||||||
, password_(password) |
|
||||||
{} |
|
||||||
|
|
||||||
QByteArray |
|
||||||
RegisterRequest::serialize() noexcept |
|
||||||
{ |
|
||||||
QJsonObject body{{"username", user_}, {"password", password_}}; |
|
||||||
|
|
||||||
return QJsonDocument(body).toJson(QJsonDocument::Compact); |
|
||||||
} |
|
||||||
|
|
||||||
void |
|
||||||
RegisterResponse::deserialize(const QJsonDocument &data) |
|
||||||
{ |
|
||||||
if (!data.isObject()) |
|
||||||
throw DeserializationException("Response is not a JSON object"); |
|
||||||
|
|
||||||
QJsonObject object = data.object(); |
|
||||||
|
|
||||||
if (!object.contains("access_token")) |
|
||||||
throw DeserializationException("Missing access_token param"); |
|
||||||
|
|
||||||
if (!object.contains("home_server")) |
|
||||||
throw DeserializationException("Missing home_server param"); |
|
||||||
|
|
||||||
if (!object.contains("user_id")) |
|
||||||
throw DeserializationException("Missing user_id param"); |
|
||||||
|
|
||||||
access_token_ = object.value("access_token").toString(); |
|
||||||
home_server_ = object.value("home_server").toString(); |
|
||||||
user_id_ = object.value("user_id").toString(); |
|
||||||
} |
|
@ -0,0 +1,75 @@ |
|||||||
|
#include <QDesktopServices> |
||||||
|
#include <QLabel> |
||||||
|
#include <QPaintEvent> |
||||||
|
#include <QStyleOption> |
||||||
|
#include <QVBoxLayout> |
||||||
|
|
||||||
|
#include "Config.h" |
||||||
|
#include "FlatButton.h" |
||||||
|
#include "RaisedButton.h" |
||||||
|
#include "Theme.h" |
||||||
|
|
||||||
|
#include "dialogs/ReCaptcha.hpp" |
||||||
|
|
||||||
|
using namespace dialogs; |
||||||
|
|
||||||
|
ReCaptcha::ReCaptcha(const QString &server, const QString &session, QWidget *parent) |
||||||
|
: QWidget(parent) |
||||||
|
{ |
||||||
|
setAutoFillBackground(true); |
||||||
|
setWindowFlags(Qt::Tool | Qt::WindowStaysOnTopHint); |
||||||
|
setWindowModality(Qt::WindowModal); |
||||||
|
|
||||||
|
auto layout = new QVBoxLayout(this); |
||||||
|
layout->setSpacing(30); |
||||||
|
layout->setMargin(20); |
||||||
|
|
||||||
|
auto buttonLayout = new QHBoxLayout(); |
||||||
|
buttonLayout->setSpacing(8); |
||||||
|
buttonLayout->setMargin(0); |
||||||
|
|
||||||
|
openCaptchaBtn_ = new FlatButton("OPEN reCAPTCHA", this); |
||||||
|
openCaptchaBtn_->setFontSize(conf::btn::fontSize); |
||||||
|
|
||||||
|
confirmBtn_ = new RaisedButton(tr("CONFIRM"), this); |
||||||
|
confirmBtn_->setFontSize(conf::btn::fontSize); |
||||||
|
|
||||||
|
cancelBtn_ = new RaisedButton(tr("CANCEL"), this); |
||||||
|
cancelBtn_->setFontSize(conf::btn::fontSize); |
||||||
|
|
||||||
|
buttonLayout->addStretch(1); |
||||||
|
buttonLayout->addWidget(openCaptchaBtn_); |
||||||
|
buttonLayout->addWidget(confirmBtn_); |
||||||
|
buttonLayout->addWidget(cancelBtn_); |
||||||
|
|
||||||
|
QFont font; |
||||||
|
font.setPixelSize(conf::headerFontSize); |
||||||
|
|
||||||
|
auto label = new QLabel(tr("Solve the reCAPTCHA and press the confirm button"), this); |
||||||
|
label->setFont(font); |
||||||
|
|
||||||
|
layout->addWidget(label); |
||||||
|
layout->addLayout(buttonLayout); |
||||||
|
|
||||||
|
connect(openCaptchaBtn_, &QPushButton::clicked, [server, session, this]() { |
||||||
|
const auto url = |
||||||
|
QString( |
||||||
|
"https://%1/_matrix/client/r0/auth/m.login.recaptcha/fallback/web?session=%2") |
||||||
|
.arg(server) |
||||||
|
.arg(session); |
||||||
|
|
||||||
|
QDesktopServices::openUrl(url); |
||||||
|
}); |
||||||
|
|
||||||
|
connect(confirmBtn_, &QPushButton::clicked, this, &dialogs::ReCaptcha::closing); |
||||||
|
connect(cancelBtn_, &QPushButton::clicked, this, &dialogs::ReCaptcha::close); |
||||||
|
} |
||||||
|
|
||||||
|
void |
||||||
|
ReCaptcha::paintEvent(QPaintEvent *) |
||||||
|
{ |
||||||
|
QStyleOption opt; |
||||||
|
opt.init(this); |
||||||
|
QPainter p(this); |
||||||
|
style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this); |
||||||
|
} |
Loading…
Reference in new issue