Add signup error messages to qt launcher

This commit is contained in:
Ryan Huffman 2019-10-03 11:16:51 -07:00
parent a71d8ec9ce
commit 8e310f3ae6
5 changed files with 62 additions and 7 deletions

View file

@ -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

View file

@ -1,5 +1,7 @@
#include "Helper.h"
#include <QCoreApplication>
#include "windows.h"
#include "winnls.h"
#include "shobjidl.h"
@ -8,7 +10,6 @@
#include "shlguid.h"
#include <tlhelp32.h>
#include <strsafe.h>
#include <QCoreApplication>
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) {

View file

@ -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<QString, LauncherState::UIState::UI_STATE_NUM> 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::vector<LauncherState::ApplicationSta
}
}
qDebug() << "Unexpected state, current: " << _applicationState << ", expected: " << states;
#ifdef BREAK_ON_ERROR
__debugbreak();
#endif
setApplicationState(ApplicationState::UnexpectedError);
}
LauncherState::LauncherState() {
@ -159,6 +164,7 @@ LauncherState::UIState LauncherState::getUIState() const {
return UIState::LoginScreen;
case ApplicationState::WaitingForSignup:
case ApplicationState::RequestingSignup:
case ApplicationState::RequestingLoginAfterSignup:
return UIState::SignupScreen;
case ApplicationState::DownloadingClient:
case ApplicationState::InstallingClient:
@ -313,7 +319,24 @@ void LauncherState::signup(QString email, QString username, QString password, QS
_lastSignupError = signupRequest->getError();
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 <QTimer>
#include <QCoreApplication>
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) {

View file

@ -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;

View file

@ -44,6 +44,7 @@ void SignupRequest::receivedResponse() {
}
auto data = reply->readAll();
qDebug() << "Signup response: " << data;
QJsonParseError parseError;
auto doc = QJsonDocument::fromJson(data, &parseError);