mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 06:18:52 +02:00
filling username with oculus username, checking create error
This commit is contained in:
parent
671f15b63c
commit
d38a657c54
6 changed files with 107 additions and 59 deletions
|
@ -121,12 +121,61 @@ Item {
|
||||||
bottomMargin: hifi.dimensions.contentSpacing.y
|
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 {
|
HifiControlsUit.TextField {
|
||||||
id: emailField
|
id: emailField
|
||||||
width: root.bannerWidth
|
width: root.bannerWidth
|
||||||
height: completeProfileBody.textFieldHeight
|
height: completeProfileBody.textFieldHeight
|
||||||
anchors {
|
anchors {
|
||||||
top: parent.top
|
top: usernameField.bottom
|
||||||
|
topMargin: hifi.dimensions.contentSpacing.y
|
||||||
}
|
}
|
||||||
placeholderText: "Email"
|
placeholderText: "Email"
|
||||||
font.pixelSize: completeProfileBody.textFieldFontSize
|
font.pixelSize: completeProfileBody.textFieldFontSize
|
||||||
|
@ -137,9 +186,9 @@ Item {
|
||||||
case Qt.Key_Tab:
|
case Qt.Key_Tab:
|
||||||
event.accepted = true;
|
event.accepted = true;
|
||||||
if (event.modifiers === Qt.ShiftModifier) {
|
if (event.modifiers === Qt.ShiftModifier) {
|
||||||
passwordField.focus = true;
|
|
||||||
} else {
|
|
||||||
usernameField.focus = true;
|
usernameField.focus = true;
|
||||||
|
} else {
|
||||||
|
passwordField.focus = true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Qt.Key_Backtab:
|
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 {
|
HifiControlsUit.TextField {
|
||||||
id: passwordField
|
id: passwordField
|
||||||
width: root.bannerWidth
|
width: root.bannerWidth
|
||||||
height: completeProfileBody.textFieldHeight
|
height: completeProfileBody.textFieldHeight
|
||||||
placeholderText: "Password (min. 6 characters)"
|
placeholderText: "Password (optional)"
|
||||||
font.pixelSize: completeProfileBody.textFieldFontSize
|
font.pixelSize: completeProfileBody.textFieldFontSize
|
||||||
styleRenderType: Text.QtRendering
|
styleRenderType: Text.QtRendering
|
||||||
activeFocusOnPress: true
|
activeFocusOnPress: true
|
||||||
echoMode: passwordFieldMouseArea.showPassword ? TextInput.Normal : TextInput.Password
|
echoMode: passwordFieldMouseArea.showPassword ? TextInput.Normal : TextInput.Password
|
||||||
anchors {
|
anchors {
|
||||||
top: usernameField.bottom
|
top: emailField.bottom
|
||||||
topMargin: hifi.dimensions.contentSpacing.y
|
topMargin: hifi.dimensions.contentSpacing.y
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -110,6 +110,13 @@ bool LoginDialog::isOculusRunning() const {
|
||||||
return (oculusPlatformPlugin && oculusPlatformPlugin->isRunning());
|
return (oculusPlatformPlugin && oculusPlatformPlugin->isRunning());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString LoginDialog::oculusUserID() const {
|
||||||
|
if (auto oculusPlatformPlugin = PluginManager::getInstance()->getOculusPlatformPlugin()) {
|
||||||
|
return oculusPlatformPlugin->getOculusUserID();
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
void LoginDialog::dismissLoginDialog() {
|
void LoginDialog::dismissLoginDialog() {
|
||||||
QAction* loginAction = Menu::getInstance()->getActionForOption(MenuOption::Login);
|
QAction* loginAction = Menu::getInstance()->getActionForOption(MenuOption::Login);
|
||||||
Q_CHECK_PTR(loginAction);
|
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";
|
qDebug() << "Attempting to create account from Oculus info";
|
||||||
if (auto oculusPlatformPlugin = PluginManager::getInstance()->getOculusPlatformPlugin()) {
|
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()) {
|
if (nonce.isEmpty() || userID.isEmpty()) {
|
||||||
emit handleLoginFailed();
|
emit handleLoginFailed();
|
||||||
return;
|
return;
|
||||||
|
@ -179,9 +186,15 @@ void LoginDialog::createAccountFromOculus(QString username) {
|
||||||
payload.insert("oculus_nonce", QJsonValue::fromVariant(QVariant(nonce)));
|
payload.insert("oculus_nonce", QJsonValue::fromVariant(QVariant(nonce)));
|
||||||
payload.insert("oculus_user_id", QJsonValue::fromVariant(QVariant(userID)));
|
payload.insert("oculus_user_id", QJsonValue::fromVariant(QVariant(userID)));
|
||||||
payload.insert("oculus_id", QJsonValue::fromVariant(QVariant(oculusID)));
|
payload.insert("oculus_id", QJsonValue::fromVariant(QVariant(oculusID)));
|
||||||
|
if (!email.isEmpty()) {
|
||||||
|
payload.insert("email", QJsonValue::fromVariant(QVariant(email)));
|
||||||
|
}
|
||||||
if (!username.isEmpty()) {
|
if (!username.isEmpty()) {
|
||||||
payload.insert("username", QJsonValue::fromVariant(QVariant(username)));
|
payload.insert("username", QJsonValue::fromVariant(QVariant(username)));
|
||||||
}
|
}
|
||||||
|
if (!password.isEmpty()) {
|
||||||
|
payload.insert("password", QJsonValue::fromVariant(QVariant(password)));
|
||||||
|
}
|
||||||
|
|
||||||
auto accountManager = DependencyManager::get<AccountManager>();
|
auto accountManager = DependencyManager::get<AccountManager>();
|
||||||
accountManager->sendRequest(CREATE_ACCOUNT_FROM_OCULUS_PATH, AccountManagerAuth::None,
|
accountManager->sendRequest(CREATE_ACCOUNT_FROM_OCULUS_PATH, AccountManagerAuth::None,
|
||||||
|
@ -279,6 +292,39 @@ void LoginDialog::createCompleted(QNetworkReply* reply) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void LoginDialog::createFailed(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());
|
emit handleCreateFailed(reply->errorString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,6 @@ extern const QUrl OVERLAY_LOGIN_DIALOG;
|
||||||
|
|
||||||
class LoginDialog : public OffscreenQmlDialog {
|
class LoginDialog : public OffscreenQmlDialog {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(bool isLogIn READ getIsLogIn WRITE setIsLogIn)
|
|
||||||
HIFI_QML_DECL
|
HIFI_QML_DECL
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -69,25 +68,21 @@ protected slots:
|
||||||
Q_INVOKABLE bool isSteamRunning() const;
|
Q_INVOKABLE bool isSteamRunning() const;
|
||||||
Q_INVOKABLE bool isOculusRunning() 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 login(const QString& username, const QString& password) const;
|
||||||
Q_INVOKABLE void loginThroughSteam();
|
Q_INVOKABLE void loginThroughSteam();
|
||||||
Q_INVOKABLE void linkSteam();
|
Q_INVOKABLE void linkSteam();
|
||||||
Q_INVOKABLE void createAccountFromSteam(QString username = QString());
|
Q_INVOKABLE void createAccountFromSteam(QString username = QString());
|
||||||
Q_INVOKABLE void loginThroughOculus();
|
Q_INVOKABLE void loginThroughOculus();
|
||||||
Q_INVOKABLE void linkOculus();
|
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 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;
|
||||||
|
|
||||||
Q_INVOKABLE bool getLoginDialogPoppedUp() 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
|
#endif // hifi_LoginDialog_h
|
||||||
|
|
|
@ -18,6 +18,7 @@ public:
|
||||||
virtual ~OculusPlatformPlugin() = default;
|
virtual ~OculusPlatformPlugin() = default;
|
||||||
|
|
||||||
virtual const QString getName() const = 0;
|
virtual const QString getName() const = 0;
|
||||||
|
virtual const QString getOculusUserID() const = 0;
|
||||||
|
|
||||||
virtual const bool isRunning() const = 0;
|
virtual const bool isRunning() const = 0;
|
||||||
|
|
||||||
|
|
|
@ -97,7 +97,6 @@ void OculusAPIPlugin::handleOVREvents() {
|
||||||
|
|
||||||
if (_nonceChanged) {
|
if (_nonceChanged) {
|
||||||
_nonceUserIDCallback(_nonce, _user, QString::number(_userID));
|
_nonceUserIDCallback(_nonce, _user, QString::number(_userID));
|
||||||
_nonce = _user = "";
|
|
||||||
_nonceChanged = false;
|
_nonceChanged = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,7 @@ public:
|
||||||
OculusAPIPlugin();
|
OculusAPIPlugin();
|
||||||
virtual ~OculusAPIPlugin();
|
virtual ~OculusAPIPlugin();
|
||||||
const QString getName() const { return NAME; }
|
const QString getName() const { return NAME; }
|
||||||
|
const QString getOculusUserID() const { return _user; };
|
||||||
|
|
||||||
const bool isRunning() const;
|
const bool isRunning() const;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue