Implement user registration with reCAPTCHA

fixes #264
This commit is contained in:
Konstantinos Sideris 2018-03-12 22:23:26 +02:00
parent 39a8150fae
commit 4659d0efc2
17 changed files with 212 additions and 137 deletions

View file

@ -41,7 +41,7 @@ public:
signals:
void backButtonClicked();
void loggingIn();
void errorOccured();
void errorOccurred();
protected:
void paintEvent(QPaintEvent *event) override;

View file

@ -49,6 +49,7 @@ class InviteUsers;
class JoinRoom;
class LeaveRoom;
class Logout;
class ReCaptcha;
}
class MainWindow : public QMainWindow

View file

@ -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();

View file

@ -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_;
};

View file

@ -20,12 +20,17 @@
#include <QLabel>
#include <QLayout>
#include <QSharedPointer>
#include <memory>
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<MatrixClient> client_;
//! ReCaptcha dialog.
std::shared_ptr<dialogs::ReCaptcha> captchaDialog_;
};

View file

@ -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