diff --git a/launcher/ui/dialogs/LoginDialog.cpp b/launcher/ui/dialogs/LoginDialog.cpp index 7296a13ef..ffd39d682 100644 --- a/launcher/ui/dialogs/LoginDialog.cpp +++ b/launcher/ui/dialogs/LoginDialog.cpp @@ -18,6 +18,7 @@ #include "minecraft/auth/AccountTask.h" +#include #include LoginDialog::LoginDialog(QWidget* parent) : QDialog(parent), ui(new Ui::LoginDialog) @@ -43,7 +44,11 @@ void LoginDialog::accept() // Setup the login task and start it m_account = MinecraftAccount::createFromUsername(ui->userTextBox->text()); - m_loginTask = m_account->login(ui->passTextBox->text()); + if (!ui->twofaTextBox->text().isEmpty()) { + m_loginTask = m_account->login(ui->passTextBox->text() + ":" + ui->twofaTextBox->text()); + } else { + m_loginTask = m_account->login(ui->passTextBox->text()); + } connect(m_loginTask.get(), &Task::failed, this, &LoginDialog::onTaskFailed); connect(m_loginTask.get(), &Task::succeeded, this, &LoginDialog::onTaskSucceeded); connect(m_loginTask.get(), &Task::status, this, &LoginDialog::onTaskStatus); @@ -55,6 +60,7 @@ void LoginDialog::setUserInputsEnabled(bool enable) { ui->userTextBox->setEnabled(enable); ui->passTextBox->setEnabled(enable); + ui->twofaTextBox->setEnabled(enable); ui->buttonBox->setEnabled(enable); } @@ -67,6 +73,12 @@ void LoginDialog::on_passTextBox_textEdited(const QString& newText) { ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(!newText.isEmpty() && !ui->userTextBox->text().isEmpty()); } +void LoginDialog::on_twofaTextBox_textEdited(const QString& newText) +{ + QRegExp re("\\d*"); + ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled((newText.isEmpty() || ui->twofaTextBox->text().isEmpty()) + || (ui->twofaTextBox->text().length() == 6 && re.exactMatch(ui->twofaTextBox->text()))); +} void LoginDialog::onTaskFailed(const QString& reason) { diff --git a/launcher/ui/dialogs/LoginDialog.h b/launcher/ui/dialogs/LoginDialog.h index 601b5fa77..61009c63c 100644 --- a/launcher/ui/dialogs/LoginDialog.h +++ b/launcher/ui/dialogs/LoginDialog.h @@ -48,6 +48,7 @@ class LoginDialog : public QDialog { void on_userTextBox_textEdited(const QString& newText); void on_passTextBox_textEdited(const QString& newText); + void on_twofaTextBox_textEdited(const QString& newText); private: Ui::LoginDialog* ui; diff --git a/launcher/ui/dialogs/LoginDialog.ui b/launcher/ui/dialogs/LoginDialog.ui index 8fa4a45d2..cbc9d1f83 100644 --- a/launcher/ui/dialogs/LoginDialog.ui +++ b/launcher/ui/dialogs/LoginDialog.ui @@ -50,6 +50,13 @@ + + + + 2FA token (if present) + + + diff --git a/launcher/ui/pages/global/AccountListPage.cpp b/launcher/ui/pages/global/AccountListPage.cpp index ad13e332f..8370dd896 100644 --- a/launcher/ui/pages/global/AccountListPage.cpp +++ b/launcher/ui/pages/global/AccountListPage.cpp @@ -137,7 +137,7 @@ void AccountListPage::listChanged() void AccountListPage::on_actionAddMojang_triggered() { MinecraftAccountPtr account = - LoginDialog::newAccount(this, tr("Please enter your Ely.by account email and password to add your account.")); + LoginDialog::newAccount(this, tr("Please enter your Ely.by account email, password and 2FA token (if present) to add your account.")); if (account) { m_accounts->addAccount(account);