From 4659d0efc274f2a955b203ca5b00cf1dfc26d5fc Mon Sep 17 00:00:00 2001 From: Konstantinos Sideris Date: Mon, 12 Mar 2018 22:23:26 +0200 Subject: Implement user registration with reCAPTCHA fixes #264 --- include/LoginPage.h | 2 +- include/MainWindow.h | 1 + include/MatrixClient.h | 7 +++++- include/Register.h | 52 ------------------------------------------- include/RegisterPage.h | 9 ++++++++ include/dialogs/ReCaptcha.hpp | 28 +++++++++++++++++++++++ 6 files changed, 45 insertions(+), 54 deletions(-) delete mode 100644 include/Register.h create mode 100644 include/dialogs/ReCaptcha.hpp (limited to 'include') diff --git a/include/LoginPage.h b/include/LoginPage.h index b2b40537..34835229 100644 --- a/include/LoginPage.h +++ b/include/LoginPage.h @@ -41,7 +41,7 @@ public: signals: void backButtonClicked(); void loggingIn(); - void errorOccured(); + void errorOccurred(); protected: void paintEvent(QPaintEvent *event) override; diff --git a/include/MainWindow.h b/include/MainWindow.h index e3a5e19d..d747f9b4 100644 --- a/include/MainWindow.h +++ b/include/MainWindow.h @@ -49,6 +49,7 @@ class InviteUsers; class JoinRoom; class LeaveRoom; class Logout; +class ReCaptcha; } class MainWindow : public QMainWindow diff --git a/include/MatrixClient.h b/include/MatrixClient.h index 46d946c7..69fa72bc 100644 --- a/include/MatrixClient.h +++ b/include/MatrixClient.h @@ -54,7 +54,8 @@ public: void login(const QString &username, const QString &password) noexcept; void registerUser(const QString &username, const QString &password, - const QString &server) noexcept; + const QString &server, + const QString &session = "") noexcept; void versions() noexcept; void fetchRoomAvatar(const QString &roomid, const QUrl &avatar_url); //! Download user's avatar. @@ -109,6 +110,10 @@ public slots: signals: void loginError(const QString &error); void registerError(const QString &error); + void registrationFlow(const QString &user, + const QString &pass, + const QString &server, + const QString &session); void versionError(const QString &error); void loggedOut(); diff --git a/include/Register.h b/include/Register.h deleted file mode 100644 index ed903172..00000000 --- a/include/Register.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * nheko Copyright (C) 2017 Konstantinos Sideris - * - * 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 . - */ - -#pragma once - -#include "Deserializable.h" -#include - -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_; -}; diff --git a/include/RegisterPage.h b/include/RegisterPage.h index b98e59de..32f2fcf2 100644 --- a/include/RegisterPage.h +++ b/include/RegisterPage.h @@ -20,12 +20,17 @@ #include #include #include +#include class FlatButton; class MatrixClient; class RaisedButton; class TextField; +namespace dialogs { +class ReCaptcha; +} + class RegisterPage : public QWidget { Q_OBJECT @@ -38,6 +43,8 @@ protected: signals: void backButtonClicked(); + void errorOccurred(); + void registering(); private slots: void onBackButtonClicked(); @@ -70,4 +77,6 @@ private: // Matrix client API provider. QSharedPointer client_; + //! ReCaptcha dialog. + std::shared_ptr captchaDialog_; }; diff --git a/include/dialogs/ReCaptcha.hpp b/include/dialogs/ReCaptcha.hpp new file mode 100644 index 00000000..1eda40c7 --- /dev/null +++ b/include/dialogs/ReCaptcha.hpp @@ -0,0 +1,28 @@ +#pragma once + +#include + +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 -- cgit 1.5.1