From 0ee5665c95c4e0461f23986f0f5f43b4bf36c0fd Mon Sep 17 00:00:00 2001 From: Trial97 Date: Thu, 14 Dec 2023 00:02:53 +0200 Subject: [PATCH] Revert "Removed auto reauthenticate" This reverts commit 400b518bc21b8a56131384fd4a56988d31bceb9f. Signed-off-by: Trial97 --- launcher/LaunchController.cpp | 35 +++++++++++++++++++++++++++++++---- launcher/LaunchController.h | 1 + 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/launcher/LaunchController.cpp b/launcher/LaunchController.cpp index 687da1322..d49e9e8ba 100644 --- a/launcher/LaunchController.cpp +++ b/launcher/LaunchController.cpp @@ -43,6 +43,7 @@ #include "ui/InstanceWindow.h" #include "ui/MainWindow.h" #include "ui/dialogs/CustomMessageBox.h" +#include "ui/dialogs/MSALoginDialog.h" #include "ui/dialogs/ProfileSelectDialog.h" #include "ui/dialogs/ProfileSetupDialog.h" #include "ui/dialogs/ProgressDialog.h" @@ -287,10 +288,8 @@ void LaunchController::login() continue; } case AccountState::Expired: { - auto errorString = tr("The account has expired and needs to be logged into manually again."); - QMessageBox::warning(m_parentWidget, tr("Account refresh failed"), errorString, QMessageBox::StandardButton::Ok, - QMessageBox::StandardButton::Ok); - emitFailed(errorString); + if (reauthenticateCurrentAccount()) + continue; return; } case AccountState::Disabled: { @@ -314,6 +313,34 @@ void LaunchController::login() emitFailed(tr("Failed to launch.")); } +bool LaunchController::reauthenticateCurrentAccount() +{ + auto button = + QMessageBox::warning(m_parentWidget, tr("Account refresh failed"), + tr("The account has expired and needs to be reauthenticated. Do you want to reauthenticate this account?"), + QMessageBox::StandardButton::Yes | QMessageBox::StandardButton::No, QMessageBox::StandardButton::Yes); + if (button == QMessageBox::StandardButton::Yes) { + auto accounts = APPLICATION->accounts(); + bool isDefault = accounts->defaultAccount() == m_accountToUse; + accounts->removeAccount(accounts->index(accounts->findAccountByProfileId(m_accountToUse->profileId()))); + if (m_accountToUse->accountType() == AccountType::MSA) { + auto newAccount = + MSALoginDialog::newAccount(m_parentWidget, tr("Please enter your Mojang account email and password to add your account.")); + accounts->addAccount(newAccount); + if (isDefault) { + accounts->setDefaultAccount(newAccount); + } + m_accountToUse = nullptr; + decideAccount(); + return true; + } + emitFailed(tr("Account expired and re-login attempt failed")); + } else { + emitFailed(tr("The account has expired and needs to be reauthenticated")); + } + return false; +} + void LaunchController::launchInstance() { Q_ASSERT_X(m_instance != NULL, "launchInstance", "instance is NULL"); diff --git a/launcher/LaunchController.h b/launcher/LaunchController.h index 6e2a94258..08fd19cae 100644 --- a/launcher/LaunchController.h +++ b/launcher/LaunchController.h @@ -76,6 +76,7 @@ class LaunchController : public Task { void decideAccount(); bool askPlayDemo(); QString askOfflineName(QString playerName, bool demo, bool& ok); + bool reauthenticateCurrentAccount(); private slots: void readyForLaunch();