filling username with oculus username, checking create error

This commit is contained in:
Wayne Chen 2019-01-16 09:43:48 -08:00
parent 671f15b63c
commit d38a657c54
6 changed files with 107 additions and 59 deletions

View file

@ -121,12 +121,61 @@ Item {
bottomMargin: hifi.dimensions.contentSpacing.y
}
HifiControlsUit.TextField {
id: usernameField
width: root.bannerWidth
height: completeProfileBody.textFieldHeight
placeholderText: "Username"
font.pixelSize: completeProfileBody.textFieldFontSize
styleRenderType: Text.QtRendering
anchors {
top: parent.top
}
Keys.onPressed: {
if (!usernameField.visible) {
return;
}
switch (event.key) {
case Qt.Key_Tab:
event.accepted = true;
if (event.modifiers === Qt.ShiftModifier) {
passwordField.focus = true;
} else {
emailField.focus = true;
}
break;
case Qt.Key_Backtab:
event.accepted = true;
passwordField.focus = true;
break;
case Qt.Key_Enter:
case Qt.Key_Return:
event.accepted = true;
loginDialog.createAccountFromOculus(emailField.text, usernameField.text, passwordField.text);
break;
}
}
onFocusChanged: {
root.text = "";
if (focus) {
root.isPassword = false;
}
}
Component.onCompleted: {
var userID = "";
if (completeProfileBody.withOculus) {
userID = loginDialog.oculusUserID();
}
usernameField.text = userID;
}
}
HifiControlsUit.TextField {
id: emailField
width: root.bannerWidth
height: completeProfileBody.textFieldHeight
anchors {
top: parent.top
top: usernameField.bottom
topMargin: hifi.dimensions.contentSpacing.y
}
placeholderText: "Email"
font.pixelSize: completeProfileBody.textFieldFontSize
@ -137,9 +186,9 @@ Item {
case Qt.Key_Tab:
event.accepted = true;
if (event.modifiers === Qt.ShiftModifier) {
passwordField.focus = true;
} else {
usernameField.focus = true;
} else {
passwordField.focus = true;
}
break;
case Qt.Key_Backtab:
@ -160,60 +209,17 @@ Item {
}
}
}
HifiControlsUit.TextField {
id: usernameField
width: root.bannerWidth
height: completeProfileBody.textFieldHeight
placeholderText: "Username"
font.pixelSize: completeProfileBody.textFieldFontSize
styleRenderType: Text.QtRendering
anchors {
top: emailField.bottom
topMargin: hifi.dimensions.contentSpacing.y
}
Keys.onPressed: {
if (!usernameField.visible) {
return;
}
switch (event.key) {
case Qt.Key_Tab:
event.accepted = true;
if (event.modifiers === Qt.ShiftModifier) {
emailField.focus = true;
} else {
passwordField.focus = true;
}
break;
case Qt.Key_Backtab:
event.accepted = true;
passwordField.focus = true;
break;
case Qt.Key_Enter:
case Qt.Key_Return:
event.accepted = true;
loginDialog.createAccountFromOculus(emailField.text, usernameField.text, passwordField.text);
break;
}
}
onFocusChanged: {
root.text = "";
if (focus) {
root.isPassword = false;
}
}
}
HifiControlsUit.TextField {
id: passwordField
width: root.bannerWidth
height: completeProfileBody.textFieldHeight
placeholderText: "Password (min. 6 characters)"
placeholderText: "Password (optional)"
font.pixelSize: completeProfileBody.textFieldFontSize
styleRenderType: Text.QtRendering
activeFocusOnPress: true
echoMode: passwordFieldMouseArea.showPassword ? TextInput.Normal : TextInput.Password
anchors {
top: usernameField.bottom
top: emailField.bottom
topMargin: hifi.dimensions.contentSpacing.y
}

View file

@ -110,6 +110,13 @@ bool LoginDialog::isOculusRunning() const {
return (oculusPlatformPlugin && oculusPlatformPlugin->isRunning());
}
QString LoginDialog::oculusUserID() const {
if (auto oculusPlatformPlugin = PluginManager::getInstance()->getOculusPlatformPlugin()) {
return oculusPlatformPlugin->getOculusUserID();
}
return "";
}
void LoginDialog::dismissLoginDialog() {
QAction* loginAction = Menu::getInstance()->getActionForOption(MenuOption::Login);
Q_CHECK_PTR(loginAction);
@ -159,10 +166,10 @@ void LoginDialog::linkOculus() {
}
}
void LoginDialog::createAccountFromOculus(QString username) {
void LoginDialog::createAccountFromOculus(QString email, QString username, QString password) {
qDebug() << "Attempting to create account from Oculus info";
if (auto oculusPlatformPlugin = PluginManager::getInstance()->getOculusPlatformPlugin()) {
oculusPlatformPlugin->requestNonceAndUserID([this, username] (QString nonce, QString userID, QString oculusID) {
oculusPlatformPlugin->requestNonceAndUserID([this, email, username, password] (QString nonce, QString userID, QString oculusID) {
if (nonce.isEmpty() || userID.isEmpty()) {
emit handleLoginFailed();
return;
@ -179,9 +186,15 @@ void LoginDialog::createAccountFromOculus(QString username) {
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)));
if (!email.isEmpty()) {
payload.insert("email", QJsonValue::fromVariant(QVariant(email)));
}
if (!username.isEmpty()) {
payload.insert("username", QJsonValue::fromVariant(QVariant(username)));
}
if (!password.isEmpty()) {
payload.insert("password", QJsonValue::fromVariant(QVariant(password)));
}
auto accountManager = DependencyManager::get<AccountManager>();
accountManager->sendRequest(CREATE_ACCOUNT_FROM_OCULUS_PATH, AccountManagerAuth::None,
@ -279,6 +292,39 @@ void LoginDialog::createCompleted(QNetworkReply* reply) {
}
void LoginDialog::createFailed(QNetworkReply* reply) {
if (isOculusRunning()) {
auto replyData = reply->readAll();
qDebug() << replyData;
QJsonParseError parseError;
auto doc = QJsonDocument::fromJson(replyData, &parseError);
if (parseError.error != QJsonParseError::NoError) {
qDebug() << "Failed parsing error " << parseError.error;
emit handleCreateFailed(reply->errorString());
return;
}
auto root = doc.object();
auto data = root.value("data").toObject();
auto error = data.value("error").toObject();
auto identity = error.value("identity");
auto user = error.value("username");
qDebug() << user.isArray() << " " << user.isObject() << " " << user.isString() << " " << user.isUndefined() << " " << user.isNull();
if (!user.isNull() && !user.isUndefined()) {
QJsonArray arr = user.toArray();
if (!arr.isEmpty()) {
auto firstError = arr.at(0).toString();
qDebug() << firstError;
emit handleCreateFailed("Username " + firstError);
}
}
if (!identity.isNull()) {
QJsonArray arr = identity.toArray();
if (!arr.isEmpty()) {
auto firstError = arr.at(0).toString();
qDebug() << firstError;
emit handleCreateFailed(firstError);
}
}
}
emit handleCreateFailed(reply->errorString());
}

View file

@ -22,7 +22,6 @@ extern const QUrl OVERLAY_LOGIN_DIALOG;
class LoginDialog : public OffscreenQmlDialog {
Q_OBJECT
Q_PROPERTY(bool isLogIn READ getIsLogIn WRITE setIsLogIn)
HIFI_QML_DECL
public:
@ -69,25 +68,21 @@ protected slots:
Q_INVOKABLE bool isSteamRunning() const;
Q_INVOKABLE bool isOculusRunning() const;
Q_INVOKABLE QString oculusUserID() const;
Q_INVOKABLE void login(const QString& username, const QString& password) const;
Q_INVOKABLE void loginThroughSteam();
Q_INVOKABLE void linkSteam();
Q_INVOKABLE void createAccountFromSteam(QString username = QString());
Q_INVOKABLE void loginThroughOculus();
Q_INVOKABLE void linkOculus();
Q_INVOKABLE void createAccountFromOculus(QString username = QString());
Q_INVOKABLE void createAccountFromOculus(QString email = QString(), QString username = QString(), QString password = QString());
Q_INVOKABLE void signup(const QString& email, const QString& username, const QString& password);
Q_INVOKABLE void openUrl(const QString& url) const;
Q_INVOKABLE bool getLoginDialogPoppedUp() const;
private:
bool getIsLogIn() const { return _isLogIn; }
void setIsLogIn(const bool isLogIn) { _isLogIn = isLogIn; }
bool _isLogIn{ false };
};
#endif // hifi_LoginDialog_h

View file

@ -18,6 +18,7 @@ public:
virtual ~OculusPlatformPlugin() = default;
virtual const QString getName() const = 0;
virtual const QString getOculusUserID() const = 0;
virtual const bool isRunning() const = 0;

View file

@ -97,7 +97,6 @@ void OculusAPIPlugin::handleOVREvents() {
if (_nonceChanged) {
_nonceUserIDCallback(_nonce, _user, QString::number(_userID));
_nonce = _user = "";
_nonceChanged = false;
}

View file

@ -19,6 +19,7 @@ public:
OculusAPIPlugin();
virtual ~OculusAPIPlugin();
const QString getName() const { return NAME; }
const QString getOculusUserID() const { return _user; };
const bool isRunning() const;