Extracted reauthenticateCurrentAccount as a separate function
Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
parent
2863a691ef
commit
ceb88a170e
@ -258,29 +258,8 @@ void LaunchController::login()
|
||||
continue;
|
||||
}
|
||||
case AccountState::Expired: {
|
||||
auto errorString = tr("The account has expired and needs to be logged into manually. Press OK to log in again.");
|
||||
auto button = QMessageBox::warning(m_parentWidget, tr("Account refresh failed"), errorString,
|
||||
QMessageBox::StandardButton::Ok | QMessageBox::StandardButton::Cancel,
|
||||
QMessageBox::StandardButton::Ok);
|
||||
if (button == QMessageBox::StandardButton::Ok) {
|
||||
auto accounts = APPLICATION->accounts();
|
||||
bool isDefault = accounts->defaultAccount() == m_accountToUse;
|
||||
accounts->removeAccount(accounts->index(accounts->findAccountByProfileId(m_accountToUse->profileId())));
|
||||
if (m_accountToUse->isMSA()) {
|
||||
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();
|
||||
if (reauthenticateCurrentAccount())
|
||||
continue;
|
||||
}
|
||||
emitFailed(tr("Account expired and re-login attempt failed"));
|
||||
} else {
|
||||
emitFailed(errorString);
|
||||
}
|
||||
return;
|
||||
}
|
||||
case AccountState::Disabled: {
|
||||
@ -304,6 +283,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->isMSA()) {
|
||||
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");
|
||||
|
@ -74,6 +74,7 @@ class LaunchController : public Task {
|
||||
void login();
|
||||
void launchInstance();
|
||||
void decideAccount();
|
||||
bool reauthenticateCurrentAccount();
|
||||
|
||||
private slots:
|
||||
void readyForLaunch();
|
||||
|
Loading…
Reference in New Issue
Block a user