more code review feedback

This commit is contained in:
Wayne Chen 2019-01-25 12:15:38 -08:00
parent 0928b1bff1
commit 635c7533b9
4 changed files with 24 additions and 33 deletions

View file

@ -305,36 +305,28 @@ void LoginDialog::createFailed(QNetworkReply* reply) {
return;
}
auto root = doc.object();
auto data = root["data"].toObject();
auto error = data["error"].toObject();
auto data = root["data"];
auto error = data["error"];
auto oculusError = data["oculus"];
auto user = error["username"].toArray();
auto uid = error["uid"].toArray();
auto email = error["email"].toArray();
auto password = error["password"].toArray();
QString reply;
if (!uid.isEmpty()) {
if (uid[0].isString()) {
emit handleCreateFailed("Oculus ID " + uid[0].toString() + ".");
return;
}
if (uid[0].isString()) {
emit handleCreateFailed("Oculus ID " + uid[0].toString() + ".");
return;
}
if (!user.isEmpty()) {
if (user[0].isString()) {
reply = "Username " + user[0].toString() + ".";
}
if (user[0].isString()) {
reply = "Username " + user[0].toString() + ".";
}
if (!email.isEmpty()) {
if (email[0].isString()) {
reply.append((!reply.isEmpty()) ? "\n" : "");
reply.append("Email " + email[0].toString() + ".");
}
if (email[0].isString()) {
reply.append((!reply.isEmpty()) ? "\n" : "");
reply.append("Email " + email[0].toString() + ".");
}
if (!password.isEmpty()) {
if (password[0].isString()) {
reply.append((!reply.isEmpty()) ? "\n" : "");
reply.append("Password " + password[0].toString() + ".");
}
if (password[0].isString()) {
reply.append((!reply.isEmpty()) ? "\n" : "");
reply.append("Password " + password[0].toString() + ".");
}
if (!oculusError.isNull() && !oculusError.isUndefined()) {
emit handleCreateFailed("Could not verify token with Oculus. Please try again.");

View file

@ -17,10 +17,10 @@ class OculusPlatformPlugin {
public:
virtual ~OculusPlatformPlugin() = default;
virtual QString getName() = 0;
virtual QString getOculusUserID() = 0;
virtual QString getName() const = 0;
virtual QString getOculusUserID() const = 0;
virtual bool isRunning() = 0;
virtual bool isRunning() const = 0;
virtual void requestNonceAndUserID(NonceUserIDCallback callback) = 0;

View file

@ -62,11 +62,9 @@ void OculusAPIPlugin::handleOVREvents() {
ovrUserHandle user = ovr_Message_GetUser(message);
_user = ovr_User_GetOculusID(user);
// went all the way through the `requestNonceAndUserID()` pipeline successfully.
_nonceChanged = true;
} else {
qCDebug(oculusLog) << "Oculus Platform user retrieval failed" << QString(ovr_Error_GetMessage(ovr_Message_GetError(message)));
// emit the signal so we don't hang for it anywhere else.
_nonceChanged = true;
_user = "";
}
break;
@ -79,8 +77,8 @@ void OculusAPIPlugin::handleOVREvents() {
} else {
qCDebug(oculusLog) << "Oculus Platform user ID retrieval failed" << QString(ovr_Error_GetMessage(ovr_Message_GetError(message)));
// emit the signal so we don't hang for it anywhere else.
_nonceChanged = true;
}
_userIDChanged = true;
break;
}
case ovrMessage_User_GetUserProof: {
@ -92,15 +90,15 @@ void OculusAPIPlugin::handleOVREvents() {
qCDebug(oculusLog) << "Oculus Platform nonce retrieval failed" << QString(ovr_Error_GetMessage(ovr_Message_GetError(message)));
_nonce = "";
// emit the signal so we don't hang for it anywhere else.
_nonceChanged = true;
}
_nonceChanged = true;
break;
}
}
if (_nonceChanged) {
if (_nonceChanged && _userIDChanged) {
_nonceUserIDCallback(_nonce, QString::number(_userID));
_nonceChanged = false;
_nonceChanged = _userIDChanged = false;
}
// free the message handle to cleanup and not leak

View file

@ -18,10 +18,10 @@ class OculusAPIPlugin : public OculusPlatformPlugin {
public:
OculusAPIPlugin();
virtual ~OculusAPIPlugin();
QString getName() { return NAME; }
QString getOculusUserID() { return _user; };
QString getName() const { return NAME; }
QString getOculusUserID() const { return _user; };
bool isRunning();
bool isRunning() const;
virtual void requestNonceAndUserID(NonceUserIDCallback callback);
@ -32,6 +32,7 @@ private:
NonceUserIDCallback _nonceUserIDCallback;
QString _nonce;
bool _nonceChanged{ false };
bool _userIDChanged{ false };
QString _user;
ovrID _userID;
ovrSession _session;