Improve login flow (#35)
* Validate both inferred and explicitly entered server addresses by attempting to call the /versions endpoint
* If the domain from the mxid fails validation, try prefixing it with 'matrix'
* Only show server address field if address validation ultimately fails
3 files changed, 36 insertions, 19 deletions
diff --git a/include/LoginPage.h b/include/LoginPage.h
index 774dd8e9..8e95061a 100644
--- a/include/LoginPage.h
+++ b/include/LoginPage.h
@@ -23,8 +23,8 @@
#include <QVBoxLayout>
#include <QWidget>
+#include "CircularProgress.h"
#include "FlatButton.h"
-#include "LoginSettings.h"
#include "MatrixClient.h"
#include "OverlayModal.h"
#include "RaisedButton.h"
@@ -50,12 +50,20 @@ private slots:
// Callback for the login button.
void onLoginButtonClicked();
+ // Callback for probing the server found in the mxid
+ void onMatrixIdEntered();
+
+ // Callback for probing the manually entered server
+ void onServerAddressEntered();
+
// Displays errors produced during the login.
void loginError(QString error_message);
- // Manipulate settings modal.
- void showSettingsModal();
- void closeSettingsModal(const QString &server);
+ // Callback for errors produced during server probing
+ void versionError(QString error_message);
+
+ // Callback for successful server probing
+ void versionSuccess();
private:
QVBoxLayout *top_layout_;
@@ -67,8 +75,13 @@ private:
QLabel *logo_;
QLabel *error_label_;
+ QHBoxLayout *serverLayout_;
+ QHBoxLayout *matrixidLayout_;
+ CircularProgress *spinner_;
+ QLabel *errorIcon_;
+ QString inferredServerAddress_;
+
FlatButton *back_button_;
- FlatButton *advanced_settings_button_;
RaisedButton *login_button_;
QWidget *form_widget_;
@@ -77,10 +90,7 @@ private:
TextField *matrixid_input_;
TextField *password_input_;
-
- OverlayModal *settings_modal_;
- LoginSettings *login_settings_;
- QString custom_domain_;
+ TextField *serverInput_;
// Matrix client API provider.
QSharedPointer<MatrixClient> client_;
diff --git a/include/MatrixClient.h b/include/MatrixClient.h
index 7a4ac24b..e3613ab7 100644
--- a/include/MatrixClient.h
+++ b/include/MatrixClient.h
@@ -63,11 +63,13 @@ public slots:
signals:
void loginError(const QString &error);
void registerError(const QString &error);
+ void versionError(const QString &error);
void loggedOut();
void loginSuccess(const QString &userid, const QString &homeserver, const QString &token);
void registerSuccess(const QString &userid, const QString &homeserver, const QString &token);
+ void versionSuccess();
void roomAvatarRetrieved(const QString &roomid, const QPixmap &img);
void userAvatarRetrieved(const QString &userId, const QImage &img);
diff --git a/include/LoginSettings.h b/include/Versions.h
index 62e9b2f5..9d7f1eb4 100644
--- a/include/LoginSettings.h
+++ b/include/Versions.h
@@ -17,21 +17,26 @@
#pragma once
-#include <QFrame>
+#include <QJsonDocument>
+#include <QVector>
-#include "FlatButton.h"
-#include "TextField.h"
+#include "Deserializable.h"
-class LoginSettings : public QFrame
+
+class VersionsResponse : public Deserializable
{
- Q_OBJECT
public:
- explicit LoginSettings(QWidget *parent = nullptr);
+ void deserialize(const QJsonDocument &data) override;
-signals:
- void closing(const QString &server);
+ bool isVersionSupported(unsigned int major, unsigned int minor, unsigned int patch);
private:
- TextField *input_;
- FlatButton *submit_button_;
+ struct Version_ {
+ unsigned int major_;
+ unsigned int minor_;
+ unsigned int patch_;
+ };
+
+ QVector<Version_> supported_versions_;
+
};
|