From f983d16cc19e34aec037c2d08efbe38180842ba3 Mon Sep 17 00:00:00 2001 From: Wayne Chen Date: Wed, 16 Jan 2019 17:03:44 -0800 Subject: [PATCH] linking oculus acct creation to spinner --- .../qml/LoginDialog/CompleteProfileBody.qml | 39 ++++++++----------- .../qml/LoginDialog/LoggingInBody.qml | 24 +++++++++++- interface/src/ui/LoginDialog.cpp | 16 ++++++-- libraries/networking/src/AccountManager.cpp | 3 +- libraries/networking/src/AccountManager.h | 2 +- 5 files changed, 53 insertions(+), 31 deletions(-) diff --git a/interface/resources/qml/LoginDialog/CompleteProfileBody.qml b/interface/resources/qml/LoginDialog/CompleteProfileBody.qml index ce5bdeae6d..db90194f0a 100644 --- a/interface/resources/qml/LoginDialog/CompleteProfileBody.qml +++ b/interface/resources/qml/LoginDialog/CompleteProfileBody.qml @@ -77,7 +77,7 @@ Item { height: loginErrorMessageTextMetrics.height anchors { bottom: buttons.top; - bottomMargin: hifi.dimensions.contentSpacing.y; + bottomMargin: 2 * hifi.dimensions.contentSpacing.y; left: buttons.left; } TextMetrics { @@ -102,10 +102,14 @@ Item { loginErrorMessage.wrapMode = Text.WordWrap; loginErrorMessage.verticalAlignment = Text.AlignLeft; loginErrorMessage.horizontalAlignment = Text.AlignLeft; - errorContainer.height = 3 * loginErrorMessageTextMetrics.height; + errorContainer.height = (loginErrorMessageTextMetrics.width / root.bannerWidth) * loginErrorMessageTextMetrics.height; + } else { + loginErrorMessage.wrapMode = Text.NoWrap; + errorContainer.height = loginErrorMessageTextMetrics.height; } if (completeProfileBody.withOculus) { errorContainer.anchors.bottom = fields.top; + errorContainer.anchors.bottomMargin = hifi.dimensions.contentSpacing.y; } } } @@ -153,6 +157,8 @@ Item { case Qt.Key_Return: event.accepted = true; loginDialog.createAccountFromOculus(emailField.text, usernameField.text, passwordField.text); + bodyLoader.setSource("LoggingInBody.qml", { "loginDialog": loginDialog, "root": root, "bodyLoader": bodyLoader, "withSteam": completeProfileBody.withSteam, + "linkSteam": false, "withOculus": completeProfileBody.withOculus, "linkOculus": false, "createOculus": true }); break; } } @@ -200,6 +206,8 @@ Item { case Qt.Key_Return: event.accepted = true; loginDialog.createAccountFromOculus(emailField.text, usernameField.text, passwordField.text); + bodyLoader.setSource("LoggingInBody.qml", { "loginDialog": loginDialog, "root": root, "bodyLoader": bodyLoader, "withSteam": completeProfileBody.withSteam, + "linkSteam": false, "withOculus": completeProfileBody.withOculus, "linkOculus": false, "createOculus": true }); break; } } @@ -337,6 +345,8 @@ Item { loginErrorMessage.visible = false; if (completeProfileBody.withOculus) { loginDialog.createAccountFromOculus(emailField.text, usernameField.text, passwordField.text); + bodyLoader.setSource("LoggingInBody.qml", { "loginDialog": loginDialog, "root": root, "bodyLoader": bodyLoader, "withSteam": completeProfileBody.withSteam, + "linkSteam": false, "withOculus": completeProfileBody.withOculus, "linkOculus": false, "createOculus": true }); } else if (completeProfileBody.withSteam) { loginDialog.createAccountFromSteam(); } @@ -452,10 +462,8 @@ Item { Connections { target: loginDialog onHandleCreateCompleted: { - console.log("Create Succeeded") - if (completeProfileBody.withOculus) { - loginDialog.loginThroughOculus(); - } else if (completeProfileBody.withSteam) { + console.log("Create Succeeded"); + if (completeProfileBody.withSteam) { loginDialog.loginThroughSteam(); } bodyLoader.setSource("LoggingInBody.qml", { "loginDialog": loginDialog, "root": root, "bodyLoader": bodyLoader, "withSteam": completeProfileBody.withSteam, "linkSteam": false, @@ -463,23 +471,8 @@ Item { } onHandleCreateFailed: { console.log("Create Failed: " + error); - if (completeProfileBody.withOculus) { - loginErrorMessage.visible = true; - loginErrorMessage.text = error; - - if (loginErrorMessageTextMetrics.width > root.bannerWidth) { - loginErrorMessage.wrapMode = Text.WordWrap; - loginErrorMessage.verticalAlignment = Text.AlignLeft; - loginErrorMessage.horizontalAlignment = Text.AlignLeft; - errorContainer.height = (loginErrorMessageTextMetrics.width / root.bannerWidth) * loginErrorMessageTextMetrics.height; - } else { - loginErrorMessage.wrapMode = Text.NoWrap; - errorContainer.height = loginErrorMessageTextMetrics.height; - } - } else { - bodyLoader.setSource("UsernameCollisionBody.qml", { "loginDialog": loginDialog, "root": root, "bodyLoader": bodyLoader, "withSteam": completeProfileBody.withSteam, - "withOculus": completeProfileBody.withOculus }); - } + bodyLoader.setSource("UsernameCollisionBody.qml", { "loginDialog": loginDialog, "root": root, "bodyLoader": bodyLoader, "withSteam": completeProfileBody.withSteam, + "withOculus": completeProfileBody.withOculus }); } } diff --git a/interface/resources/qml/LoginDialog/LoggingInBody.qml b/interface/resources/qml/LoginDialog/LoggingInBody.qml index 2f7935d0cf..2c69f58fee 100644 --- a/interface/resources/qml/LoginDialog/LoggingInBody.qml +++ b/interface/resources/qml/LoginDialog/LoggingInBody.qml @@ -30,6 +30,7 @@ Item { property bool withOculus: withOculus property bool linkSteam: linkSteam property bool linkOculus: linkOculus + property bool createOculus: createOculus QtObject { id: d @@ -73,8 +74,12 @@ Item { function init() { // For the process of logging in. loggingInText.wrapMode = Text.NoWrap; - - if (loggingInBody.linkSteam) { + if (loggingInBody.createOculus) { + loggingInGlyph.text = hifi.glyphs.oculus; + loggingInGlyph.visible = true; + loggingInText.text = "Creating account with Oculus"; + loggingInText.x = loggingInHeader.width/2 - loggingInTextMetrics.width/2 + loggingInGlyphTextMetrics.width/2; + } else if (loggingInBody.linkSteam) { loggingInGlyph.visible = true; loggingInText.text = "Linking to Steam"; loggingInText.x = loggingInHeader.width/2 - loggingInTextMetrics.width/2 + loggingInGlyphTextMetrics.width/2; @@ -243,6 +248,21 @@ Item { Connections { target: loginDialog + onHandleCreateCompleted: { + console.log("Create Succeeded") + if (loggingInBody.withOculus) { + loggingInBody.createOculus = false; + loggingInText.text = "Account created! Logging in to Oculus"; + loginDialog.loginThroughOculus(); + } + } + onHandleCreateFailed: { + console.log("Create Failed: " + error); + if (loggingInBody.withOculus) { + bodyLoader.setSource("CompleteProfileBody.qml", { "loginDialog": loginDialog, "root": root, "bodyLoader": bodyLoader, "withSteam": loggingInBody.withSteam, + "withOculus": loggingInBody.withOculus, "errorString": error }); + } + } onHandleLinkCompleted: { console.log("Link Succeeded"); loggingInBody.linkSteam = false; diff --git a/interface/src/ui/LoginDialog.cpp b/interface/src/ui/LoginDialog.cpp index 5c009d9388..d65626636a 100644 --- a/interface/src/ui/LoginDialog.cpp +++ b/interface/src/ui/LoginDialog.cpp @@ -134,7 +134,7 @@ void LoginDialog::loginThroughOculus() { qDebug() << "Attempting to login through Oculus"; if (auto oculusPlatformPlugin = PluginManager::getInstance()->getOculusPlatformPlugin()) { oculusPlatformPlugin->requestNonceAndUserID([this] (QString nonce, QString userID, QString oculusID) { - DependencyManager::get()->requestAccessTokenWithOculus(nonce, userID); + DependencyManager::get()->requestAccessTokenWithOculus(nonce, userID, oculusID); }); } } @@ -143,7 +143,7 @@ void LoginDialog::linkOculus() { qDebug() << "Attempting to link Oculus account"; if (auto oculusPlatformPlugin = PluginManager::getInstance()->getOculusPlatformPlugin()) { oculusPlatformPlugin->requestNonceAndUserID([this] (QString nonce, QString userID, QString oculusID) { - if (nonce.isEmpty() || userID.isEmpty()) { + if (nonce.isEmpty() || userID.isEmpty() || oculusID.isEmpty()) { emit handleLoginFailed(); return; } @@ -157,6 +157,7 @@ void LoginDialog::linkOculus() { QJsonObject payload; payload.insert("oculus_nonce", QJsonValue::fromVariant(QVariant(nonce))); payload.insert("oculus_user_id", QJsonValue::fromVariant(QVariant(userID))); + payload.insert("oculus_id", QJsonValue::fromVariant(QVariant(oculusID))); auto accountManager = DependencyManager::get(); accountManager->sendRequest(LINK_OCULUS_PATH, AccountManagerAuth::Required, @@ -170,7 +171,7 @@ void LoginDialog::createAccountFromOculus(QString email, QString username, QStri qDebug() << "Attempting to create account from Oculus info"; if (auto oculusPlatformPlugin = PluginManager::getInstance()->getOculusPlatformPlugin()) { oculusPlatformPlugin->requestNonceAndUserID([this, email, username, password] (QString nonce, QString userID, QString oculusID) { - if (nonce.isEmpty() || userID.isEmpty()) { + if (nonce.isEmpty() || userID.isEmpty() || oculusID.isEmpty()) { emit handleLoginFailed(); return; } @@ -297,7 +298,6 @@ void LoginDialog::createFailed(QNetworkReply* reply) { QJsonParseError parseError; auto doc = QJsonDocument::fromJson(replyData, &parseError); if (parseError.error != QJsonParseError::NoError) { - qDebug() << "Failed parsing error " << parseError.error; emit handleCreateFailed(reply->errorString()); return; } @@ -306,11 +306,19 @@ void LoginDialog::createFailed(QNetworkReply* reply) { auto error = data.value("error").toObject(); auto identity = error.value("identity"); auto user = error.value("username"); + auto uid = error.value("uid"); auto email = error.value("email"); QString usernameError; QString emailError; QString identityError; QString errorReply; + if (!uid.isNull() && !uid.isUndefined()) { + QJsonArray arr = uid.toArray(); + if (!arr.isEmpty()) { + emit handleCreateFailed("Oculus ID " + arr.at(0).toString() + "."); + return; + } + } if (!user.isNull() && !user.isUndefined()) { QJsonArray arr = user.toArray(); if (!arr.isEmpty()) { diff --git a/libraries/networking/src/AccountManager.cpp b/libraries/networking/src/AccountManager.cpp index 38d286d131..1d686f7163 100644 --- a/libraries/networking/src/AccountManager.cpp +++ b/libraries/networking/src/AccountManager.cpp @@ -586,7 +586,7 @@ void AccountManager::requestAccessTokenWithSteam(QByteArray authSessionTicket) { connect(requestReply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(requestAccessTokenError(QNetworkReply::NetworkError))); } -void AccountManager::requestAccessTokenWithOculus(const QString& nonce, const QString& userID) { +void AccountManager::requestAccessTokenWithOculus(const QString& nonce, const QString& userID, const QString &oculusID) { QNetworkAccessManager& networkAccessManager = NetworkAccessManager::getInstance(); QNetworkRequest request; @@ -599,6 +599,7 @@ void AccountManager::requestAccessTokenWithOculus(const QString& nonce, const QS postData.append("grant_type=password&"); postData.append("oculus_nonce=" + nonce + "&"); postData.append("oculus_user_id=" + userID + "&"); + postData.append("oculus_id=" + oculusID + "&"); postData.append("scope=" + ACCOUNT_MANAGER_REQUESTED_SCOPE); request.setUrl(grantURL); diff --git a/libraries/networking/src/AccountManager.h b/libraries/networking/src/AccountManager.h index 748dc27252..9ef8d615db 100644 --- a/libraries/networking/src/AccountManager.h +++ b/libraries/networking/src/AccountManager.h @@ -104,7 +104,7 @@ public: public slots: void requestAccessToken(const QString& login, const QString& password); void requestAccessTokenWithSteam(QByteArray authSessionTicket); - void requestAccessTokenWithOculus(const QString& nonce, const QString& userID); + void requestAccessTokenWithOculus(const QString& nonce, const QString& userID, const QString& oculusID); void requestAccessTokenWithAuthCode(const QString& authCode, const QString& clientId, const QString& clientSecret, const QString& redirectUri); void refreshAccessToken();