From 8e310f3ae6d6ae8a11513a83ce7113361c5d0614 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Thu, 3 Oct 2019 11:16:51 -0700 Subject: [PATCH] Add signup error messages to qt launcher --- .../qml/HFBase/CreateAccountBase.qml | 23 +++++++++++++ launchers/qt/src/Helper_windows.cpp | 5 ++- launchers/qt/src/LauncherState.cpp | 34 ++++++++++++++++--- launchers/qt/src/LauncherState.h | 6 ++++ launchers/qt/src/SignupRequest.cpp | 1 + 5 files changed, 62 insertions(+), 7 deletions(-) diff --git a/launchers/qt/resources/qml/HFBase/CreateAccountBase.qml b/launchers/qt/resources/qml/HFBase/CreateAccountBase.qml index 0c1e9f4421..8b429bae26 100644 --- a/launchers/qt/resources/qml/HFBase/CreateAccountBase.qml +++ b/launchers/qt/resources/qml/HFBase/CreateAccountBase.qml @@ -28,6 +28,7 @@ Item { lineHeight: 35 lineHeightMode: Text.FixedHeight text: root.titleText + visible: LauncherState.lastSignupErrorMessage.length == 0 ? root.titleText : "Uh oh." anchors { top: root.top topMargin: 29 @@ -42,6 +43,8 @@ Item { height: 22 text: "Use the email address that you registered with." + visible: LauncherState.lastSignupErrorMessage.length == 0 + anchors { left: root.left leftMargin: root.marginLeft @@ -50,6 +53,26 @@ Item { } } + HFTextRegular { + id: error + width: 425 + height: 22 + + horizontalAlignment: Text.AlignHCenter + verticalAlignment: Text.AlignVCenter + + color: "#FF9999" + + visible: LauncherState.lastSignupErrorMessage.length > 0 + text: LauncherState.lastSignupErrorMessage + anchors { + left: root.left + right: root.right + top: title.bottom + topMargin: 18 + } + } + HFTextField { id: email width: 430 diff --git a/launchers/qt/src/Helper_windows.cpp b/launchers/qt/src/Helper_windows.cpp index 849f34d08c..743e0681e7 100644 --- a/launchers/qt/src/Helper_windows.cpp +++ b/launchers/qt/src/Helper_windows.cpp @@ -1,5 +1,7 @@ #include "Helper.h" +#include + #include "windows.h" #include "winnls.h" #include "shobjidl.h" @@ -8,7 +10,6 @@ #include "shlguid.h" #include #include -#include void launchClient(const QString& clientPath, const QString& homePath, const QString& defaultScriptsPath, const QString& displayName, const QString& contentCachePath, QString loginResponseToken) { @@ -50,8 +51,6 @@ void launchClient(const QString& clientPath, const QString& homePath, const QStr // Close process and thread handles. CloseHandle(pi.hProcess); CloseHandle(pi.hThread); - - QCoreApplication::instance()->quit(); } void launchAutoUpdater(const QString& autoUpdaterPath) { diff --git a/launchers/qt/src/LauncherState.cpp b/launchers/qt/src/LauncherState.cpp index 8eb807b26b..1049972437 100644 --- a/launchers/qt/src/LauncherState.cpp +++ b/launchers/qt/src/LauncherState.cpp @@ -97,6 +97,11 @@ bool LauncherState::shouldDownloadContentCache() const { return !_contentCacheURL.isEmpty() && !QFile::exists(getContentCachePath()); } +void LauncherState::setLastSignupErrorMessage(const QString& msg) { + _lastSignupErrorMessage = msg; + emit lastSignupErrorMessageChanged(); +} + void LauncherState::setLastLoginErrorMessage(const QString& msg) { _lastLoginErrorMessage = msg; emit lastLoginErrorMessageChanged(); @@ -108,10 +113,10 @@ static const std::array QML_FILE_ void LauncherState::ASSERT_STATE(LauncherState::ApplicationState state) { if (_applicationState != state) { + qDebug() << "Unexpected state, current: " << _applicationState << ", expected: " << state; #ifdef BREAK_ON_ERROR __debugbreak(); #endif - setApplicationState(ApplicationState::UnexpectedError); } } @@ -122,10 +127,10 @@ void LauncherState::ASSERT_STATE(const std::vectorgetError(); emit lastSignupErrorChanged(); - if (_lastSignupError != SignupRequest::Error::None) { + auto err = signupRequest->getError(); + if (err == SignupRequest::Error::ExistingUsername) { + setLastSignupErrorMessage(_username + " is already taken - please try a different username."); + setApplicationState(ApplicationState::WaitingForSignup); + return; + } else if (err == SignupRequest::Error::BadPassword) { + setLastSignupErrorMessage("That's an invalid password - please try another password."); + setApplicationState(ApplicationState::WaitingForSignup); + return; + } else if (err == SignupRequest::Error::BadUsername) { + setLastSignupErrorMessage("That's an invalid username - please try another username."); + setApplicationState(ApplicationState::WaitingForSignup); + return; + } else if (err == SignupRequest::Error::UserProfileAlreadyCompleted || err == SignupRequest::Error::NoSuchEmail) { + setLastSignupErrorMessage("That email does not have an account setup for it, or it was previously completed."); + setApplicationState(ApplicationState::WaitingForSignup); + return; + } else if (err != SignupRequest::Error::None) { setApplicationStateError("Failed to sign up"); return; } @@ -418,7 +441,7 @@ void LauncherState::requestSettings() { } void LauncherState::downloadClient() { - ASSERT_STATE(ApplicationState::RequestingLogin); + ASSERT_STATE({ ApplicationState::RequestingLogin, ApplicationState::RequestingLoginAfterSignup }); Build build; if (!_latestBuilds.getBuild(_buildTag, &build)) { @@ -675,6 +698,8 @@ void LauncherState::installContentCache() { } +#include +#include void LauncherState::launchClient() { ASSERT_STATE({ ApplicationState::RequestingLogin, @@ -714,6 +739,7 @@ void LauncherState::launchClient() { QString contentCachePath = _launcherDirectory.filePath("cache"); ::launchClient(clientPath, _config.homeLocation, defaultScriptsPath, _displayName, contentCachePath, _loginTokenResponse); + QTimer::singleShot(3000, QCoreApplication::instance(), &QCoreApplication::quit); } void LauncherState::setApplicationStateError(QString errorMessage) { diff --git a/launchers/qt/src/LauncherState.h b/launchers/qt/src/LauncherState.h index 0842eafa52..3c3b7a31c2 100644 --- a/launchers/qt/src/LauncherState.h +++ b/launchers/qt/src/LauncherState.h @@ -26,6 +26,7 @@ class LauncherState : public QObject { Q_PROPERTY(float downloadProgress READ getDownloadProgress NOTIFY downloadProgressChanged) Q_PROPERTY(SignupRequest::Error lastSignupError MEMBER _lastSignupError NOTIFY lastSignupErrorChanged) Q_PROPERTY(QString lastLoginErrorMessage READ getLastLoginErrorMessage NOTIFY lastLoginErrorMessageChanged); + Q_PROPERTY(QString lastSignupErrorMessage READ getLastSignupErrorMessage NOTIFY lastSignupErrorMessageChanged); Q_PROPERTY(QString buildVersion READ getBuildVersion) public: @@ -90,6 +91,9 @@ public: void setLastLoginErrorMessage(const QString& msg); QString getLastLoginErrorMessage() const { return _lastLoginErrorMessage; } + void setLastSignupErrorMessage(const QString& msg); + QString getLastSignupErrorMessage() const { return _lastSignupErrorMessage; } + QString getBuildVersion() { return QString(LAUNCHER_BUILD_VERSION); } void setApplicationStateError(QString errorMessage); @@ -136,6 +140,7 @@ signals: void applicationStateChanged(); void downloadProgressChanged(); void lastSignupErrorChanged(); + void lastSignupErrorMessageChanged(); void lastLoginErrorMessageChanged(); private slots: @@ -169,6 +174,7 @@ private: LoginToken _loginResponse; SignupRequest::Error _lastSignupError{ SignupRequest::Error::None }; QString _lastLoginErrorMessage{ "" }; + QString _lastSignupErrorMessage{ "" }; QString _displayName; QString _applicationErrorMessage; QString _currentClientVersion; diff --git a/launchers/qt/src/SignupRequest.cpp b/launchers/qt/src/SignupRequest.cpp index 0a2c554f8d..91f495e73a 100644 --- a/launchers/qt/src/SignupRequest.cpp +++ b/launchers/qt/src/SignupRequest.cpp @@ -44,6 +44,7 @@ void SignupRequest::receivedResponse() { } auto data = reply->readAll(); + qDebug() << "Signup response: " << data; QJsonParseError parseError; auto doc = QJsonDocument::fromJson(data, &parseError);