mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 02:16:51 +02:00
add email field, error handling for sign up inputs
This commit is contained in:
parent
556ccb90f7
commit
b66ddbdbdb
5 changed files with 86 additions and 23 deletions
|
@ -24,7 +24,7 @@ Item {
|
||||||
|
|
||||||
function signup() {
|
function signup() {
|
||||||
mainTextContainer.visible = false
|
mainTextContainer.visible = false
|
||||||
loginDialog.signup(usernameField.text, passwordField.text)
|
loginDialog.signup(emailField.text, usernameField.text, passwordField.text)
|
||||||
}
|
}
|
||||||
|
|
||||||
property bool keyboardEnabled: false
|
property bool keyboardEnabled: false
|
||||||
|
@ -81,6 +81,20 @@ Item {
|
||||||
}
|
}
|
||||||
spacing: 2 * hifi.dimensions.contentSpacing.y
|
spacing: 2 * hifi.dimensions.contentSpacing.y
|
||||||
|
|
||||||
|
Row {
|
||||||
|
spacing: hifi.dimensions.contentSpacing.x
|
||||||
|
|
||||||
|
TextField {
|
||||||
|
id: emailField
|
||||||
|
anchors {
|
||||||
|
verticalCenter: parent.verticalCenter
|
||||||
|
}
|
||||||
|
width: 350
|
||||||
|
|
||||||
|
label: "Email"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Row {
|
Row {
|
||||||
spacing: hifi.dimensions.contentSpacing.x
|
spacing: hifi.dimensions.contentSpacing.x
|
||||||
|
|
||||||
|
@ -99,11 +113,7 @@ Item {
|
||||||
verticalCenter: parent.verticalCenter
|
verticalCenter: parent.verticalCenter
|
||||||
}
|
}
|
||||||
|
|
||||||
wrapMode: Text.WordWrap
|
text: qsTr("No spaces / special chars.")
|
||||||
lineHeight: 1
|
|
||||||
lineHeightMode: Text.ProportionalHeight
|
|
||||||
|
|
||||||
text: qsTr("Must be unique. No spaces or other special characters")
|
|
||||||
|
|
||||||
verticalAlignment: Text.AlignVCenter
|
verticalAlignment: Text.AlignVCenter
|
||||||
horizontalAlignment: Text.AlignHCenter
|
horizontalAlignment: Text.AlignHCenter
|
||||||
|
@ -111,6 +121,7 @@ Item {
|
||||||
color: hifi.colors.blueAccent
|
color: hifi.colors.blueAccent
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Row {
|
Row {
|
||||||
spacing: hifi.dimensions.contentSpacing.x
|
spacing: hifi.dimensions.contentSpacing.x
|
||||||
|
|
||||||
|
@ -213,20 +224,21 @@ Item {
|
||||||
keyboardEnabled = HMD.active;
|
keyboardEnabled = HMD.active;
|
||||||
d.resize();
|
d.resize();
|
||||||
|
|
||||||
usernameField.forceActiveFocus();
|
emailField.forceActiveFocus();
|
||||||
}
|
}
|
||||||
|
|
||||||
Connections {
|
Connections {
|
||||||
target: loginDialog
|
target: loginDialog
|
||||||
onHandleSignupCompleted: {
|
onHandleSignupCompleted: {
|
||||||
console.log("Signup Succeeded")
|
console.log("Sign Up Succeeded")
|
||||||
|
|
||||||
bodyLoader.setSource("WelcomeBody.qml", { "welcomeBack" : true })
|
bodyLoader.setSource("WelcomeBody.qml", { "welcomeBack": false })
|
||||||
bodyLoader.item.width = root.pane.width
|
bodyLoader.item.width = root.pane.width
|
||||||
bodyLoader.item.height = root.pane.height
|
bodyLoader.item.height = root.pane.height
|
||||||
}
|
}
|
||||||
onHandleSignupFailed: {
|
onHandleSignupFailed: {
|
||||||
console.log("Signup Failed")
|
console.log("Sign Up Failed")
|
||||||
|
mainTextContainer.text = errorString
|
||||||
mainTextContainer.visible = true
|
mainTextContainer.visible = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -119,7 +119,7 @@ namespace MenuOption {
|
||||||
const QString LoadScript = "Open and Run Script File...";
|
const QString LoadScript = "Open and Run Script File...";
|
||||||
const QString LoadScriptURL = "Open and Run Script from URL...";
|
const QString LoadScriptURL = "Open and Run Script from URL...";
|
||||||
const QString LodTools = "LOD Tools";
|
const QString LodTools = "LOD Tools";
|
||||||
const QString Login = "Login";
|
const QString Login = "Login / Sign Up";
|
||||||
const QString Log = "Log";
|
const QString Log = "Log";
|
||||||
const QString LogExtraTimings = "Log Extra Timing Details";
|
const QString LogExtraTimings = "Log Extra Timing Details";
|
||||||
const QString LowVelocityFilter = "Low Velocity Filter";
|
const QString LowVelocityFilter = "Low Velocity Filter";
|
||||||
|
|
|
@ -11,9 +11,10 @@
|
||||||
|
|
||||||
#include "LoginDialog.h"
|
#include "LoginDialog.h"
|
||||||
|
|
||||||
#include <QDesktopServices>
|
#include <QtGui/QDesktopServices>
|
||||||
#include <QJsonDocument>
|
#include <QtCore/QJsonArray>
|
||||||
#include <QNetworkReply>
|
#include <QtCore/QJsonDocument>
|
||||||
|
#include <QtNetwork/QNetworkReply>
|
||||||
|
|
||||||
#include <NetworkingConstants.h>
|
#include <NetworkingConstants.h>
|
||||||
#include <steamworks-wrapper/SteamClient.h>
|
#include <steamworks-wrapper/SteamClient.h>
|
||||||
|
@ -47,7 +48,7 @@ void LoginDialog::toggleAction() {
|
||||||
connection = connect(loginAction, &QAction::triggered, accountManager.data(), &AccountManager::logout);
|
connection = connect(loginAction, &QAction::triggered, accountManager.data(), &AccountManager::logout);
|
||||||
} else {
|
} else {
|
||||||
// change the menu item to login
|
// change the menu item to login
|
||||||
loginAction->setText("Login");
|
loginAction->setText("Login / Sign Up");
|
||||||
connection = connect(loginAction, &QAction::triggered, [] {
|
connection = connect(loginAction, &QAction::triggered, [] {
|
||||||
LoginDialog::show();
|
LoginDialog::show();
|
||||||
});
|
});
|
||||||
|
@ -153,7 +154,7 @@ void LoginDialog::createFailed(QNetworkReply& reply) {
|
||||||
emit handleCreateFailed(reply.errorString());
|
emit handleCreateFailed(reply.errorString());
|
||||||
}
|
}
|
||||||
|
|
||||||
void LoginDialog::signup(const QString& username, const QString& password) {
|
void LoginDialog::signup(const QString& email, const QString& username, const QString& password) {
|
||||||
|
|
||||||
JSONCallbackParameters callbackParams;
|
JSONCallbackParameters callbackParams;
|
||||||
callbackParams.jsonCallbackReceiver = this;
|
callbackParams.jsonCallbackReceiver = this;
|
||||||
|
@ -162,8 +163,13 @@ void LoginDialog::signup(const QString& username, const QString& password) {
|
||||||
callbackParams.errorCallbackMethod = "signupFailed";
|
callbackParams.errorCallbackMethod = "signupFailed";
|
||||||
|
|
||||||
QJsonObject payload;
|
QJsonObject payload;
|
||||||
payload.insert("username", username);
|
|
||||||
payload.insert("password", password);
|
QJsonObject userObject;
|
||||||
|
userObject.insert("email", email);
|
||||||
|
userObject.insert("username", username);
|
||||||
|
userObject.insert("password", password);
|
||||||
|
|
||||||
|
payload.insert("user", userObject);
|
||||||
|
|
||||||
static const QString API_SIGNUP_PATH = "api/v1/users";
|
static const QString API_SIGNUP_PATH = "api/v1/users";
|
||||||
|
|
||||||
|
@ -179,7 +185,52 @@ void LoginDialog::signupCompleted(QNetworkReply& reply) {
|
||||||
emit handleSignupCompleted();
|
emit handleSignupCompleted();
|
||||||
}
|
}
|
||||||
|
|
||||||
void LoginDialog::signupFailed(QNetworkReply& reply) {
|
QString errorStringFromAPIObject(const QJsonValue& apiObject) {
|
||||||
qDebug() << "SIGNUP FAILED" << reply.readAll();
|
if (apiObject.isArray()) {
|
||||||
|
return apiObject.toArray()[0].toString();
|
||||||
|
} else if (apiObject.isString()) {
|
||||||
|
return apiObject.toString();
|
||||||
|
} else {
|
||||||
|
return "is invalid";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void LoginDialog::signupFailed(QNetworkReply& reply) {
|
||||||
|
|
||||||
|
// parse the returned JSON to see what the problem was
|
||||||
|
auto jsonResponse = QJsonDocument::fromJson(reply.readAll());
|
||||||
|
|
||||||
|
static const QString RESPONSE_DATA_KEY = "data";
|
||||||
|
|
||||||
|
auto dataJsonValue = jsonResponse.object()[RESPONSE_DATA_KEY];
|
||||||
|
|
||||||
|
if (dataJsonValue.isObject()) {
|
||||||
|
auto dataObject = dataJsonValue.toObject();
|
||||||
|
|
||||||
|
static const QString EMAIL_DATA_KEY = "email";
|
||||||
|
static const QString USERNAME_DATA_KEY = "username";
|
||||||
|
static const QString PASSWORD_DATA_KEY = "password";
|
||||||
|
|
||||||
|
QStringList errorStringList;
|
||||||
|
|
||||||
|
if (dataObject.contains(EMAIL_DATA_KEY)) {
|
||||||
|
errorStringList.append(QString("Email %1.").arg(errorStringFromAPIObject(dataObject[EMAIL_DATA_KEY])));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dataObject.contains(USERNAME_DATA_KEY)) {
|
||||||
|
errorStringList.append(QString("Username %1.").arg(errorStringFromAPIObject(dataObject[USERNAME_DATA_KEY])));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dataObject.contains(PASSWORD_DATA_KEY)) {
|
||||||
|
errorStringList.append(QString("Password %1.").arg(errorStringFromAPIObject(dataObject[PASSWORD_DATA_KEY])));
|
||||||
|
}
|
||||||
|
|
||||||
|
emit handleSignupFailed(errorStringList.join(' '));
|
||||||
|
} else {
|
||||||
|
static const QString DEFAULT_SIGN_UP_FAILURE_MESSAGE = "There was an unknown error while creating your account. Please try again later.";
|
||||||
|
emit handleSignupFailed(DEFAULT_SIGN_UP_FAILURE_MESSAGE);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,7 @@ signals:
|
||||||
void handleCreateFailed(QString error);
|
void handleCreateFailed(QString error);
|
||||||
|
|
||||||
void handleSignupCompleted();
|
void handleSignupCompleted();
|
||||||
void handleSignupFailed(QString error);
|
void handleSignupFailed(QString errorString);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void linkCompleted(QNetworkReply& reply);
|
void linkCompleted(QNetworkReply& reply);
|
||||||
|
@ -58,7 +58,7 @@ protected slots:
|
||||||
Q_INVOKABLE void linkSteam();
|
Q_INVOKABLE void linkSteam();
|
||||||
Q_INVOKABLE void createAccountFromStream(QString username = QString());
|
Q_INVOKABLE void createAccountFromStream(QString username = QString());
|
||||||
|
|
||||||
Q_INVOKABLE void signup(const QString& username, const QString& password);
|
Q_INVOKABLE void signup(const QString& email, const QString& username, const QString& password);
|
||||||
|
|
||||||
Q_INVOKABLE void openUrl(const QString& url) const;
|
Q_INVOKABLE void openUrl(const QString& url) const;
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
#include <QtCore/QUrl>
|
#include <QtCore/QUrl>
|
||||||
|
|
||||||
namespace NetworkingConstants {
|
namespace NetworkingConstants {
|
||||||
const QUrl METAVERSE_SERVER_URL = QUrl("https://metaverse.highfidelity.com");
|
const QUrl METAVERSE_SERVER_URL = QUrl("http://localhost:3000");
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // hifi_NetworkingConstants_h
|
#endif // hifi_NetworkingConstants_h
|
||||||
|
|
Loading…
Reference in a new issue