mirror of
https://github.com/overte-org/overte.git
synced 2025-08-04 11:14:01 +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() {
|
||||
mainTextContainer.visible = false
|
||||
loginDialog.signup(usernameField.text, passwordField.text)
|
||||
loginDialog.signup(emailField.text, usernameField.text, passwordField.text)
|
||||
}
|
||||
|
||||
property bool keyboardEnabled: false
|
||||
|
@ -81,6 +81,20 @@ Item {
|
|||
}
|
||||
spacing: 2 * hifi.dimensions.contentSpacing.y
|
||||
|
||||
Row {
|
||||
spacing: hifi.dimensions.contentSpacing.x
|
||||
|
||||
TextField {
|
||||
id: emailField
|
||||
anchors {
|
||||
verticalCenter: parent.verticalCenter
|
||||
}
|
||||
width: 350
|
||||
|
||||
label: "Email"
|
||||
}
|
||||
}
|
||||
|
||||
Row {
|
||||
spacing: hifi.dimensions.contentSpacing.x
|
||||
|
||||
|
@ -99,11 +113,7 @@ Item {
|
|||
verticalCenter: parent.verticalCenter
|
||||
}
|
||||
|
||||
wrapMode: Text.WordWrap
|
||||
lineHeight: 1
|
||||
lineHeightMode: Text.ProportionalHeight
|
||||
|
||||
text: qsTr("Must be unique. No spaces or other special characters")
|
||||
text: qsTr("No spaces / special chars.")
|
||||
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
|
@ -111,6 +121,7 @@ Item {
|
|||
color: hifi.colors.blueAccent
|
||||
}
|
||||
}
|
||||
|
||||
Row {
|
||||
spacing: hifi.dimensions.contentSpacing.x
|
||||
|
||||
|
@ -213,20 +224,21 @@ Item {
|
|||
keyboardEnabled = HMD.active;
|
||||
d.resize();
|
||||
|
||||
usernameField.forceActiveFocus();
|
||||
emailField.forceActiveFocus();
|
||||
}
|
||||
|
||||
Connections {
|
||||
target: loginDialog
|
||||
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.height = root.pane.height
|
||||
}
|
||||
onHandleSignupFailed: {
|
||||
console.log("Signup Failed")
|
||||
console.log("Sign Up Failed")
|
||||
mainTextContainer.text = errorString
|
||||
mainTextContainer.visible = true
|
||||
}
|
||||
}
|
||||
|
|
|
@ -119,7 +119,7 @@ namespace MenuOption {
|
|||
const QString LoadScript = "Open and Run Script File...";
|
||||
const QString LoadScriptURL = "Open and Run Script from URL...";
|
||||
const QString LodTools = "LOD Tools";
|
||||
const QString Login = "Login";
|
||||
const QString Login = "Login / Sign Up";
|
||||
const QString Log = "Log";
|
||||
const QString LogExtraTimings = "Log Extra Timing Details";
|
||||
const QString LowVelocityFilter = "Low Velocity Filter";
|
||||
|
|
|
@ -11,9 +11,10 @@
|
|||
|
||||
#include "LoginDialog.h"
|
||||
|
||||
#include <QDesktopServices>
|
||||
#include <QJsonDocument>
|
||||
#include <QNetworkReply>
|
||||
#include <QtGui/QDesktopServices>
|
||||
#include <QtCore/QJsonArray>
|
||||
#include <QtCore/QJsonDocument>
|
||||
#include <QtNetwork/QNetworkReply>
|
||||
|
||||
#include <NetworkingConstants.h>
|
||||
#include <steamworks-wrapper/SteamClient.h>
|
||||
|
@ -47,7 +48,7 @@ void LoginDialog::toggleAction() {
|
|||
connection = connect(loginAction, &QAction::triggered, accountManager.data(), &AccountManager::logout);
|
||||
} else {
|
||||
// change the menu item to login
|
||||
loginAction->setText("Login");
|
||||
loginAction->setText("Login / Sign Up");
|
||||
connection = connect(loginAction, &QAction::triggered, [] {
|
||||
LoginDialog::show();
|
||||
});
|
||||
|
@ -153,7 +154,7 @@ void LoginDialog::createFailed(QNetworkReply& reply) {
|
|||
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;
|
||||
callbackParams.jsonCallbackReceiver = this;
|
||||
|
@ -162,8 +163,13 @@ void LoginDialog::signup(const QString& username, const QString& password) {
|
|||
callbackParams.errorCallbackMethod = "signupFailed";
|
||||
|
||||
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";
|
||||
|
||||
|
@ -179,7 +185,52 @@ void LoginDialog::signupCompleted(QNetworkReply& reply) {
|
|||
emit handleSignupCompleted();
|
||||
}
|
||||
|
||||
void LoginDialog::signupFailed(QNetworkReply& reply) {
|
||||
qDebug() << "SIGNUP FAILED" << reply.readAll();
|
||||
QString errorStringFromAPIObject(const QJsonValue& apiObject) {
|
||||
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 handleSignupCompleted();
|
||||
void handleSignupFailed(QString error);
|
||||
void handleSignupFailed(QString errorString);
|
||||
|
||||
public slots:
|
||||
void linkCompleted(QNetworkReply& reply);
|
||||
|
@ -58,7 +58,7 @@ protected slots:
|
|||
Q_INVOKABLE void linkSteam();
|
||||
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;
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
#include <QtCore/QUrl>
|
||||
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue